1{ system ? builtins.currentSystem
3, iosSdkVersion ? "10.2"
7 cleanSource = builtins.filterSource (name: _: let baseName = builtins.baseNameOf name; in !(
8 builtins.match "^\\.ghc\\.environment.*" baseName != null ||
9 baseName == "cabal.project.local"
12 commandRuntimeDeps = pkgs: with pkgs; [
19 getReflexPlatform = sys: import ./dep/reflex-platform {
20 inherit iosSdkVersion config;
22 enableLibraryProfiling = profiling;
26 obeliskExecutableConfig = import ./lib/executable-config { nixpkgs = pkgs; filterGitSource = cleanSource; };
32 # Fix misc upstream packages
34 pkgs = self.callPackage ({ pkgs }: pkgs) {};
35 haskellLib = pkgs.haskell.lib;
37 hnix = haskellLib.overrideCabal (self.callHackage "hnix" "0.6.1" { these = self.these_0_8; }) (_: {
41 hnix-store-core = self.callHackage "hnix-store-core" "0.1.0.0" {};
43 ghcid = self.callCabal2nix "ghcid" (hackGet ./dep/ghcid) {};
46 pkgs.obeliskExecutableConfig.haskellOverlay
48 # Add obelisk packages
50 pkgs = self.callPackage ({ pkgs }: pkgs) {};
51 onLinux = pkg: f: if pkgs.stdenv.isLinux then f pkg else pkg;
53 obelisk-executable-config-inject = pkgs.obeliskExecutableConfig.platforms.web.inject self;
55 obelisk-asset-manifest = self.callCabal2nix "obelisk-asset-manifest" (cleanSource ./lib/asset/manifest) {};
56 obelisk-asset-serve-snap = self.callCabal2nix "obelisk-asset-serve-snap" (cleanSource ./lib/asset/serve-snap) {};
57 obelisk-backend = self.callCabal2nix "obelisk-backend" (cleanSource ./lib/backend) {};
58 obelisk-cliapp = self.callCabal2nix "obelisk-cliapp" (cleanSource ./lib/cliapp) {};
59 obelisk-command = haskellLib.overrideCabal (self.callCabal2nix "obelisk-command" (cleanSource ./lib/command) {}) {
60 librarySystemDepends = [
62 (haskellLib.justStaticExecutables self.ghcid)
65 obelisk-frontend = self.callCabal2nix "obelisk-frontend" (cleanSource ./lib/frontend) {};
66 obelisk-run = onLinux (self.callCabal2nix "obelisk-run" (cleanSource ./lib/run) {}) (pkg:
67 haskellLib.overrideCabal pkg (drv: { librarySystemDepends = [ pkgs.iproute ]; })
69 obelisk-route = self.callCabal2nix "obelisk-route" (cleanSource ./lib/route) {};
70 obelisk-selftest = self.callCabal2nix "obelisk-selftest" (cleanSource ./lib/selftest) {};
71 obelisk-snap-extras = self.callCabal2nix "obelisk-snap-extras" (cleanSource ./lib/snap-extras) {};
72 tabulation = self.callCabal2nix "tabulation" (cleanSource ./lib/tabulation) {};
76 pkgs = self.callPackage ({ pkgs }: pkgs) {};
77 haskellLib = pkgs.haskell.lib;
79 # Dynamic linking with split objects dramatically increases startup time (about
80 # 0.5 seconds on a decent machine with SSD), so we do `justStaticExecutables`.
81 obelisk-command = haskellLib.overrideCabal
82 (haskellLib.generateOptparseApplicativeCompletion "ob"
83 (haskellLib.justStaticExecutables super.obelisk-command))
85 buildTools = (drv.buildTools or []) ++ [ pkgs.buildPackages.makeWrapper ];
87 ${drv.postFixup or ""}
88 # Make `ob` reference its runtime dependencies.
89 wrapProgram "$out"/bin/ob --prefix PATH : ${pkgs.lib.makeBinPath (commandRuntimeDeps pkgs)}
92 obelisk-selftest = haskellLib.justStaticExecutables super.obelisk-selftest;
98 reflex-platform = getReflexPlatform system;
99 inherit (reflex-platform) hackGet nixpkgs;
102 # The haskell environment used to build Obelisk itself, e.g. the 'ob' command
103 ghcObelisk = reflex-platform.ghc;
105 # Development environments for obelisk packages.
106 ghcObeliskEnvs = pkgs.lib.mapAttrs (n: v: reflex-platform.workOn ghcObelisk v) ghcObelisk;
108 inherit (import ./lib/asset/assets.nix { inherit nixpkgs; }) mkAssets;
110 haskellLib = pkgs.haskell.lib;
113 inherit reflex-platform;
114 inherit (reflex-platform) nixpkgs pinBuildInputs;
115 inherit (nixpkgs) lib;
116 pathGit = ./.; # Used in CI by the migration graph hash algorithm to correctly ignore files.
117 path = reflex-platform.filterGit ./.;
118 obelisk = ghcObelisk;
119 obeliskEnvs = ghcObeliskEnvs;
120 command = ghcObelisk.obelisk-command;
121 shell = pinBuildInputs "obelisk-shell" ([command] ++ commandRuntimeDeps pkgs);
123 selftest = pkgs.writeScript "selftest" ''
127 PATH="${command}/bin:$PATH"
128 export OBELISK_IMPL="${hackGet ./.}"
129 "${ghcObelisk.obelisk-selftest}/bin/obelisk-selftest" +RTS -N -RTS "$@"
131 #TODO: Why can't I build ./skeleton directly as a derivation? `nix-build -E ./.` doesn't work
132 skeleton = pkgs.runCommand "skeleton" {
133 dir = builtins.filterSource (path: type: builtins.trace path (baseNameOf path != ".obelisk")) ./skeleton;
137 nullIfAbsent = p: if lib.pathExists p then p else null;
138 #TODO: Avoid copying files within the nix store. Right now, obelisk-asset-manifest-generate copies files into a big blob so that the android/ios static assets can be imported from there; instead, we should get everything lined up right before turning it into an APK, so that copies, if necessary, only exist temporarily.
139 processAssets = { src, packageName ? "obelisk-generated-static", moduleName ? "Obelisk.Generated.Static" }: pkgs.runCommand "asset-manifest" {
141 outputs = [ "out" "haskellManifest" "symlinked" ];
142 nativeBuildInputs = [ ghcObelisk.obelisk-asset-manifest ];
146 mkdir -p "$symlinked"
147 obelisk-asset-manifest-generate "$src" "$haskellManifest" ${packageName} ${moduleName} "$symlinked"
150 compressedJs = frontend: optimizationLevel: pkgs.runCommand "compressedJs" {} ''
153 ln -s "${haskellLib.justStaticExecutables frontend}/bin/frontend.jsexe/all.js" all.unminified.js
154 ${if optimizationLevel == null then ''
155 ln -s all.unminified.js all.js
157 ${pkgs.closurecompiler}/bin/closure-compiler --externs "${reflex-platform.ghcjsExternsJs}" -O ${optimizationLevel} --jscomp_warning=checkVars --create_source_map="all.js.map" --source_map_format=V3 --js_output_file="all.js" all.unminified.js
158 echo "//# sourceMappingURL=all.js.map" >> all.js
163 mkBaseHost = { hostName, routeHost, enableHttps, adminEmail, defaultCloud ? "virtualbox", ... }: {...}: {
165 ( "${pkgs.path}/nixos/modules/virtualisation/${defaultCloud}-image.nix" )
169 firewall.allowedTCPPorts = if enableHttps then [ 80 443 ] else [ 80 ];
171 security.acme.certs = if enableHttps then {
172 "${routeHost}".email = adminEmail;
185 , internalPort ? 8000
186 , backendArgs ? "--port=${toString internalPort}"
191 virtualHosts."${routeHost}" = {
192 enableACME = enableHttps;
193 forceSSL = enableHttps;
194 locations.${baseUrl} = {
195 proxyPass = "http://127.0.0.1:" + toString internalPort;
196 proxyWebsockets = true;
200 systemd.services.${name} = {
201 wantedBy = [ "multi-user.target" ];
202 after = [ "network.target" ];
203 restartIfChanged = true;
204 path = [ pkgs.gnutar ];
208 exec ./backend ${backendArgs} </dev/null
212 KillMode = "process";
213 WorkingDirectory = "~";
220 description = "${user} service";
221 home = "/var/lib/${user}";
226 groups.${group} = {};
231 serverExe = backend: frontend: assets: optimizationLevel: version:
232 pkgs.runCommand "serverExe" {} ''
235 ln -s "${haskellLib.justStaticExecutables backend}"/bin/* $out/
236 ln -s "${mkAssets assets}" $out/static.assets
237 ln -s ${mkAssets (compressedJs frontend optimizationLevel)} $out/frontend.jsexe.assets
238 echo ${version} > $out/version
241 server = { exe, hostName, adminEmail, routeHost, enableHttps, version }@args:
243 nixos = import (pkgs.path + /nixos);
245 system = "x86_64-linux";
248 (serverModules.mkBaseHost args)
249 (serverModules.mkObeliskApp args)
253 (pkgs.path + /nixos/modules/security/acme.nix)
257 nixos1909 = import (hackGet ./dep/nixpkgs-19.09) {};
259 inherit (nixos1909) simp_le;
266 # An Obelisk project is a reflex-platform project with a predefined layout and role for each component
267 project = base: projectDefinition:
268 let projectOut = sys: (getReflexPlatform sys).project (args@{ nixpkgs, ... }:
269 let mkProject = { android ? null #TODO: Better error when missing
270 , ios ? null #TODO: Better error when missing
272 , overrides ? _: _: {}
273 , staticFiles ? base + /static
275 , shellToolOverrides ? _: _: {}
276 , withHoogle ? false # Setting this to `true` makes shell reloading far slower
277 , __closureCompilerOptimizationLevel ? "ADVANCED" # Set this to `null` to skip the closure-compiler step
279 let frontendName = "frontend";
280 backendName = "backend";
281 commonName = "common";
282 staticName = "obelisk-generated-static";
283 staticFilesImpure = if lib.isDerivation staticFiles then staticFiles else toString staticFiles;
284 processedStatic = processAssets { src = staticFiles; };
285 # The packages whose names and roles are defined by this package
286 predefinedPackages = lib.filterAttrs (_: x: x != null) {
287 ${frontendName} = nullIfAbsent (base + "/frontend");
288 ${commonName} = nullIfAbsent (base + "/common");
289 ${backendName} = nullIfAbsent (base + "/backend");
291 combinedPackages = predefinedPackages // packages;
292 projectOverrides = self: super: {
293 ${staticName} = haskellLib.dontHaddock (self.callCabal2nix staticName processedStatic.haskellManifest {});
294 ${backendName} = haskellLib.addBuildDepend super.${backendName} self.obelisk-run;
296 totalOverrides = lib.composeExtensions projectOverrides overrides;
297 inherit (lib.strings) hasPrefix;
298 privateConfigDirs = ["config/backend"];
299 injectableConfig = builtins.filterSource (path: _:
300 !(lib.lists.any (x: hasPrefix (toString base + "/" + toString x) (toString path)) privateConfigDirs)
302 __androidWithConfig = configPath: {
303 ${if android == null then null else frontendName} = {
304 executableName = "frontend";
305 ${if builtins.pathExists staticFiles then "assets" else null} =
306 nixpkgs.obeliskExecutableConfig.platforms.android.inject
307 (injectableConfig configPath)
308 processedStatic.symlinked;
311 __iosWithConfig = configPath: {
312 ${if ios == null then null else frontendName} = {
313 executableName = "frontend";
314 ${if builtins.pathExists staticFiles then "staticSrc" else null} =
315 nixpkgs.obeliskExecutableConfig.platforms.ios.inject
316 (injectableConfig configPath)
317 processedStatic.symlinked;
321 inherit shellToolOverrides tools withHoogle;
322 overrides = totalOverrides;
323 packages = combinedPackages;
325 ${if android == null && ios == null then null else "ghcSavedSplices"} = (lib.filter (x: lib.hasAttr x combinedPackages) [
329 ghc = (lib.filter (x: lib.hasAttr x combinedPackages) [
334 ghcjs = lib.filter (x: lib.hasAttr x combinedPackages) [
339 android = __androidWithConfig (base + "/config");
340 ios = __iosWithConfig (base + "/config");
341 passthru = { inherit android ios packages overrides tools shellToolOverrides withHoogle staticFiles staticFilesImpure __closureCompilerOptimizationLevel processedStatic __iosWithConfig __androidWithConfig; };
343 in mkProject (projectDefinition args));
344 serverOn = sys: version: serverExe
345 (projectOut sys).ghc.backend
346 (projectOut system).ghcjs.frontend
347 (projectOut sys).passthru.staticFiles
348 (projectOut sys).passthru.__closureCompilerOptimizationLevel
350 linuxExe = serverOn "x86_64-linux";
351 dummyVersion = "Version number is only available for deployments";
352 in projectOut system // {
353 linuxExeConfigurable = linuxExe;
354 linuxExe = linuxExe dummyVersion;
355 exe = serverOn system dummyVersion;
356 server = args@{ hostName, adminEmail, routeHost, enableHttps, version }:
357 server (args // { exe = linuxExe version; });
358 obelisk = import (base + "/.obelisk/impl") {};
360 haskellPackageSets = {
361 inherit (reflex-platform) ghc ghcjs;
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list