1{ system ? builtins.currentSystem
3, iosSdkVersion ? "10.2"
4, __useLegacyCompilers ? false
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; [
20 getReflexPlatform = getReflexPlatform' __useLegacyCompilers;
21 getReflexPlatform' = __useLegacyCompilers: sys: import ./dep/reflex-platform {
22 inherit iosSdkVersion __useLegacyCompilers;
24 enableLibraryProfiling = profiling;
28 obeliskExecutableConfig = import ./lib/executable-config { nixpkgs = pkgs; filterGitSource = cleanSource; };
34 # Fix misc upstream packages
36 pkgs = self.callPackage ({ pkgs }: pkgs) {};
38 # Need 8.0.2 build support
39 # PR: https://github.com/dmwit/universe/pull/33
40 universe-template = self.callCabal2nix "universe-template" (pkgs.fetchFromGitHub {
41 owner = "obsidiansystems";
43 rev = "6a71119bfa5db2b9990a2491c941469ff8ef5d13";
44 sha256 = "0z8smyainnlzcglv3dlx6x1n9j6d2jv48aa8f2421iayfkxg3js5";
48 # Add obelisk packages
50 pkgs = self.callPackage ({ pkgs }: pkgs) {};
52 obelisk-executable-config = pkgs.obeliskExecutableConfig.haskellPackage self;
53 obelisk-executable-config-inject = pkgs.obeliskExecutableConfig.platforms.web.inject self;
55 obelisk-asset-manifest = self.callCabal2nix "obelisk-asset-manifest" (hackGet ./lib/asset + "/manifest") {};
56 obelisk-asset-serve-snap = self.callCabal2nix "obelisk-asset-serve-snap" (hackGet ./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 = self.callCabal2nix "obelisk-command" (cleanSource ./lib/command) {};
60 obelisk-frontend = self.callCabal2nix "obelisk-frontend" (cleanSource ./lib/frontend) {};
61 obelisk-run = self.callCabal2nix "obelisk-run" (cleanSource ./lib/run) {};
62 obelisk-route = self.callCabal2nix "obelisk-route" (cleanSource ./lib/route) {};
63 obelisk-selftest = self.callCabal2nix "obelisk-selftest" (cleanSource ./lib/selftest) {};
64 obelisk-snap-extras = self.callCabal2nix "obelisk-snap-extras" (cleanSource ./lib/snap-extras) {};
68 pkgs = self.callPackage ({ pkgs }: pkgs) {};
69 haskellLib = pkgs.haskell.lib;
71 # Modify a Haskell package to add completion scripts for the given
72 # executable produced by it. These completion scripts will be picked up
73 # automatically if the resulting derivation is installed, e.g. by
75 addOptparseApplicativeCompletionScripts = exeName: pkg: haskellLib.overrideCabal pkg (drv: {
76 postInstall = (drv.postInstall or "") + ''
77 BASH_COMP_DIR="$out/share/bash-completion/completions"
78 mkdir -p "$BASH_COMP_DIR"
79 "$out/bin/${exeName}" --bash-completion-script "$out/bin/${exeName}" >"$BASH_COMP_DIR/ob"
81 ZSH_COMP_DIR="$out/share/zsh/vendor-completions"
82 mkdir -p "$ZSH_COMP_DIR"
83 "$out/bin/${exeName}" --zsh-completion-script "$out/bin/${exeName}" >"$ZSH_COMP_DIR/_ob"
85 FISH_COMP_DIR="$out/share/fish/vendor_completions.d"
86 mkdir -p "$FISH_COMP_DIR"
87 "$out/bin/${exeName}" --fish-completion-script "$out/bin/${exeName}" >"$FISH_COMP_DIR/ob.fish"
91 # Dynamic linking with split objects dramatically increases startup time (about
92 # 0.5 seconds on a decent machine with SSD), so we do `justStaticExecutables`.
93 obelisk-command = haskellLib.overrideCabal
94 (addOptparseApplicativeCompletionScripts "ob"
95 (haskellLib.justStaticExecutables super.obelisk-command))
97 buildTools = (drv.buildTools or []) ++ [ pkgs.buildPackages.makeWrapper ];
99 ${drv.postFixup or ""}
100 # Make `ob` reference its runtime dependencies.
101 wrapProgram "$out"/bin/ob --prefix PATH : ${pkgs.lib.makeBinPath (commandRuntimeDeps pkgs)}
104 obelisk-selftest = haskellLib.justStaticExecutables super.obelisk-selftest;
110 reflex-platform = getReflexPlatform' false system;
111 inherit (reflex-platform) hackGet nixpkgs;
114 # The haskell environment used to build Obelisk itself, e.g. the 'ob' command
115 ghcObelisk = reflex-platform.ghc;
117 inherit (import ./lib/asset/assets.nix { inherit nixpkgs; }) mkAssets;
119 haskellLib = pkgs.haskell.lib;
122 inherit reflex-platform;
123 inherit (reflex-platform) nixpkgs pinBuildInputs;
124 inherit (nixpkgs) lib;
125 pathGit = ./.; # Used in CI by the migration graph hash algorithm to correctly ignore files.
126 path = reflex-platform.filterGit ./.;
127 obelisk = ghcObelisk;
128 command = ghcObelisk.obelisk-command;
129 shell = pinBuildInputs "obelisk-shell" ([command] ++ commandRuntimeDeps pkgs) [];
131 selftest = pkgs.writeScript "selftest" ''
135 PATH="${command}/bin:$PATH"
136 export OBELISK_IMPL="${hackGet ./.}"
137 "${ghcObelisk.obelisk-selftest}/bin/obelisk-selftest" +RTS -N -RTS "$@"
139 #TODO: Why can't I build ./skeleton directly as a derivation? `nix-build -E ./.` doesn't work
140 skeleton = pkgs.runCommand "skeleton" {
141 dir = builtins.filterSource (path: type: builtins.trace path (baseNameOf path != ".obelisk")) ./skeleton;
145 nullIfAbsent = p: if lib.pathExists p then p else null;
146 #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.
147 processAssets = { src, packageName ? "obelisk-generated-static", moduleName ? "Obelisk.Generated.Static" }: pkgs.runCommand "asset-manifest" {
149 outputs = [ "out" "haskellManifest" "symlinked" ];
150 nativeBuildInputs = [ ghcObelisk.obelisk-asset-manifest ];
154 mkdir -p "$symlinked"
155 obelisk-asset-manifest-generate "$src" "$haskellManifest" ${packageName} ${moduleName} "$symlinked"
158 compressedJs = frontend: optimizationLevel: pkgs.runCommand "compressedJs" { buildInputs = [ pkgs.closurecompiler ]; } ''
161 ln -s "${haskellLib.justStaticExecutables frontend}/bin/frontend.jsexe/all.js" all.unminified.js
162 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
163 echo "//# sourceMappingURL=all.js.map" >> all.js
167 mkBaseEc2 = { hostName, routeHost, enableHttps, adminEmail, ... }: {...}: {
169 (pkgs.path + /nixos/modules/virtualisation/amazon-image.nix)
173 firewall.allowedTCPPorts = if enableHttps then [ 80 443 ] else [ 80 ];
175 security.acme.certs = if enableHttps then {
176 "${routeHost}".email = adminEmail;
189 , internalPort ? 8000
190 , backendArgs ? "--port=${toString internalPort}"
195 virtualHosts."${routeHost}" = {
196 enableACME = enableHttps;
197 forceSSL = enableHttps;
198 locations.${baseUrl} = {
199 proxyPass = "http://localhost:" + toString internalPort;
203 systemd.services.${name} = {
204 wantedBy = [ "multi-user.target" ];
205 after = [ "network.target" ];
206 restartIfChanged = true;
210 exec ./backend ${backendArgs} >>backend.out 2>>backend.err </dev/null
214 KillMode = "process";
215 WorkingDirectory = "~";
222 description = "${user} service";
223 home = "/var/lib/${user}";
228 groups.${group} = {};
233 serverExe = backend: frontend: assets: config: optimizationLevel: version:
234 pkgs.runCommand "serverExe" {} ''
237 ln -s "${haskellLib.justStaticExecutables backend}"/bin/* $out/
238 ln -s "${mkAssets assets}" $out/static.assets
239 cp -r ${config} $out/config
240 ln -s ${mkAssets (compressedJs frontend optimizationLevel)} $out/frontend.jsexe.assets
241 echo ${version} > $out/version
244 server = { exe, hostName, adminEmail, routeHost, enableHttps, config, version }@args:
246 nixos = import (pkgs.path + /nixos);
248 system = "x86_64-linux";
251 (serverModules.mkBaseEc2 args)
252 (serverModules.mkObeliskApp args)
258 # An Obelisk project is a reflex-platform project with a predefined layout and role for each component
259 project = base: projectDefinition:
260 let configPath = base + "/config";
261 projectOut = sys: (getReflexPlatform sys).project (args@{ nixpkgs, ... }:
262 let mkProject = { android ? null #TODO: Better error when missing
263 , ios ? null #TODO: Better error when missing
265 , overrides ? _: _: {}
266 , staticFiles ? base + /static
267 , staticFilesImpure ?
268 if lib.isDerivation staticFiles
270 ("Define `staticFilesImpure` if you build our assets so you can manually rebuild without restarting `ob run`. Better solution forthcomming!")
272 else toString staticFiles
274 , shellToolOverrides ? _: _: {}
275 , withHoogle ? false # Setting this to `true` makes shell reloading far slower
276 , __closureCompilerOptimizationLevel ? "ADVANCED"
278 let frontendName = "frontend";
279 backendName = "backend";
280 commonName = "common";
281 staticName = "obelisk-generated-static";
282 processedStatic = processAssets { src = staticFiles; };
283 # The packages whose names and roles are defined by this package
284 predefinedPackages = lib.filterAttrs (_: x: x != null) {
285 ${frontendName} = nullIfAbsent (base + "/frontend");
286 ${commonName} = nullIfAbsent (base + "/common");
287 ${backendName} = nullIfAbsent (base + "/backend");
289 combinedPackages = predefinedPackages // packages;
290 projectOverrides = self: super: {
291 ${staticName} = haskellLib.dontHaddock (self.callCabal2nix staticName processedStatic.haskellManifest {});
292 ${backendName} = haskellLib.addBuildDepend super.${backendName} self.obelisk-run;
294 totalOverrides = lib.composeExtensions projectOverrides overrides;
295 inherit (lib.strings) hasPrefix;
296 privateConfigDirs = ["config/backend"];
297 injectableConfig = builtins.filterSource (path: _:
298 !(lib.lists.any (x: hasPrefix (toString base + "/" + toString x) (toString path)) privateConfigDirs)
301 inherit shellToolOverrides tools withHoogle;
302 overrides = totalOverrides;
303 packages = combinedPackages;
305 ${if android == null && ios == null then null else "ghcSavedSplices"} = (lib.filter (x: lib.hasAttr x combinedPackages) [
309 ghc = (lib.filter (x: lib.hasAttr x combinedPackages) [
314 ghcjs = lib.filter (x: lib.hasAttr x combinedPackages) [
320 ${if android == null then null else frontendName} = {
321 executableName = "frontend";
322 ${if builtins.pathExists staticFiles then "assets" else null} =
323 nixpkgs.obeliskExecutableConfig.platforms.android.inject injectableConfig processedStatic.symlinked;
327 ${if ios == null then null else frontendName} = {
328 executableName = "frontend";
329 ${if builtins.pathExists staticFiles then "staticSrc" else null} =
330 nixpkgs.obeliskExecutableConfig.platforms.ios.inject injectableConfig processedStatic.symlinked;
333 passthru = { inherit android ios packages overrides tools shellToolOverrides withHoogle staticFiles staticFilesImpure __closureCompilerOptimizationLevel; };
335 in mkProject (projectDefinition args));
336 serverOn = sys: config: version: serverExe
337 (projectOut sys).ghc.backend
338 (projectOut system).ghcjs.frontend
339 (projectOut sys).passthru.staticFiles
341 (projectOut sys).passthru.__closureCompilerOptimizationLevel
343 linuxExe = serverOn "x86_64-linux";
344 dummyVersion = "Version number is only available for deployments";
345 in projectOut system // {
346 linuxExeConfigurable = linuxExe;
347 linuxExe = linuxExe (base + "/config") dummyVersion;
348 exe = serverOn system (base + "/config") dummyVersion;
349 server = args@{ hostName, adminEmail, routeHost, enableHttps, config, version }: let
350 injectableConfig = builtins.filterSource (path: _: !(lib.hasPrefix (toString config + "/backend") (toString path))) config;
351 in server (args // { exe = linuxExe injectableConfig version; });
352 obelisk = import (base + "/.obelisk/impl") {};
354 haskellPackageSets = {
355 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