1{ system ? builtins.currentSystem
3, iosSdkVersion ? "10.2"
5, terms ? { # Accepted terms, conditions, and licenses
6 security.acme.acceptTerms = false;
8, reflex-platform-func ? import ./dep/reflex-platform
11 reflex-platform = getReflexPlatform { inherit system; };
12 inherit (reflex-platform) hackGet nixpkgs;
15 inherit (import dep/gitignore.nix { inherit (nixpkgs) lib; }) gitignoreSource;
17 getReflexPlatform = { system, enableLibraryProfiling ? profiling }: reflex-platform-func {
18 inherit iosSdkVersion config system enableLibraryProfiling;
21 (import ./nixpkgs-overlays)
25 (import ./haskell-overlays/misc-deps.nix { inherit hackGet; })
26 pkgs.obeliskExecutableConfig.haskellOverlay
27 (import ./haskell-overlays/obelisk.nix)
28 (import ./haskell-overlays/tighten-ob-exes.nix)
32 # The haskell environment used to build Obelisk itself, e.g. the 'ob' command
33 ghcObelisk = reflex-platform.ghc;
35 # Development environments for obelisk packages.
36 ghcObeliskEnvs = pkgs.lib.mapAttrs (n: v: reflex-platform.workOn ghcObelisk v) ghcObelisk;
38 inherit (import ./lib/asset/assets.nix { inherit nixpkgs; }) mkAssets;
40 haskellLib = pkgs.haskell.lib;
43 inherit reflex-platform;
44 inherit (reflex-platform) nixpkgs pinBuildInputs;
45 inherit (nixpkgs) lib;
46 pathGit = ./.; # Used in CI by the migration graph hash algorithm to correctly ignore files.
47 path = reflex-platform.filterGit ./.;
49 obeliskEnvs = pkgs.lib.filterAttrs (k: _: k == "tabulation" || pkgs.lib.strings.hasPrefix "obelisk-" k) ghcObeliskEnvs; #TODO: use thunkSet https://github.com/reflex-frp/reflex-platform/pull/671
50 command = ghcObelisk.obelisk-command;
51 shell = pinBuildInputs "obelisk-shell" ([command] ++ command.commandRuntimeDeps);
53 selftest = pkgs.writeScript "selftest" ''
54 #!${pkgs.runtimeShell}
57 PATH="${command}/bin:$PATH"
59 "${ghcObelisk.obelisk-selftest}/bin/obelisk-selftest" +RTS -N -RTS "$@"
61 skeleton = pkgs.runCommand "skeleton" {
62 dir = builtins.filterSource (path: type: builtins.trace path (baseNameOf path != ".obelisk")) ./skeleton;
66 nullIfAbsent = p: if lib.pathExists p then p else null;
67 #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.
68 processAssets = { src, packageName ? "obelisk-generated-static", moduleName ? "Obelisk.Generated.Static" }: pkgs.runCommand "asset-manifest" {
70 outputs = [ "out" "haskellManifest" "symlinked" ];
71 nativeBuildInputs = [ ghcObelisk.obelisk-asset-manifest ];
76 obelisk-asset-manifest-generate "$src" "$haskellManifest" ${packageName} ${moduleName} "$symlinked"
79 compressedJs = frontend: optimizationLevel: pkgs.runCommand "compressedJs" {} ''
81 cd '${haskellLib.justStaticExecutables frontend}'
83 for f in **/all.js; do
84 dir="$out/$(basename "$(dirname "$f")")"
86 ln -s "$(realpath "$f")" "$dir/all.unminified.js"
87 ${if optimizationLevel == null then ''
88 ln -s "$dir/all.unminified.js" "$dir/all.js"
90 '${pkgs.closurecompiler}/bin/closure-compiler' --externs '${reflex-platform.ghcjsExternsJs}' -O '${optimizationLevel}' --jscomp_warning=checkVars --create_source_map="$dir/all.js.map" --source_map_format=V3 --js_output_file="$dir/all.js" "$dir/all.unminified.js"
91 echo '//# sourceMappingURL=all.js.map' >> "$dir/all.js"
97 mkBaseEc2 = { nixosPkgs, ... }: {...}: {
99 (nixosPkgs.path + /nixos/modules/virtualisation/amazon-image.nix)
104 mkDefaultNetworking = { adminEmail, enableHttps, hostName, routeHost, ... }: {...}: {
107 firewall.allowedTCPPorts = if enableHttps then [ 80 443 ] else [ 80 ];
110 # `amazon-image.nix` already sets these but if the user provides their own module then
111 # forgetting these can cause them to lose access to the server!
112 # https://github.com/NixOS/nixpkgs/blob/fab05f17d15e4e125def4fd4e708d205b41d8d74/nixos/modules/virtualisation/amazon-image.nix#L133-L136
113 services.openssh.enable = true;
114 services.openssh.permitRootLogin = "prohibit-password";
116 security.acme.certs = if enableHttps then {
117 "${routeHost}".email = adminEmail;
120 security.acme.${if enableHttps && (terms.security.acme.acceptTerms or false) then "acceptTerms" else null} = true;
131 , internalPort ? 8000
132 , backendArgs ? "--port=${toString internalPort}"
137 recommendedProxySettings = true;
138 virtualHosts."${routeHost}" = {
139 enableACME = enableHttps;
140 forceSSL = enableHttps;
141 locations.${baseUrl} = {
142 proxyPass = "http://127.0.0.1:" + toString internalPort;
143 proxyWebsockets = true;
150 systemd.services.${name} = {
151 wantedBy = [ "multi-user.target" ];
152 after = [ "network.target" ];
153 restartIfChanged = true;
154 path = [ pkgs.gnutar ];
158 exec ./backend ${backendArgs} </dev/null
162 KillMode = "process";
163 WorkingDirectory = "~";
170 description = "${user} service";
171 home = "/var/lib/${user}";
176 groups.${group} = {};
183 serverExe = backend: frontend: assets: optimizationLevel: version:
184 pkgs.runCommand "serverExe" {} ''
187 ln -s '${if profiling then backend else haskellLib.justStaticExecutables backend}'/bin/* $out/
188 ln -s '${mkAssets assets}' $out/static.assets
189 ln -s '${mkAssets (compressedJs frontend optimizationLevel)}'/* $out
190 echo ${version} > $out/version
193 server = { exe, hostName, adminEmail, routeHost, enableHttps, version, module ? serverModules.mkBaseEc2 }@args:
195 nixos = import (pkgs.path + /nixos);
197 system = "x86_64-linux";
200 (module { inherit exe hostName adminEmail routeHost enableHttps version; nixosPkgs = pkgs; })
201 (serverModules.mkDefaultNetworking args)
202 (serverModules.mkObeliskApp args)
203 ./acme.nix # Backport of ACME upgrades from 20.03
206 # Backport of ACME upgrades from 20.03
208 (pkgs.path + /nixos/modules/security/acme.nix)
212 lego = (import (builtins.fetchTarball {
213 url = https://github.com/NixOS/nixpkgs-channels/archive/70717a337f7ae4e486ba71a500367cad697e5f09.tar.gz;
214 sha256 = "1sbmqn7yc5iilqnvy9nvhsa9bx6spfq1kndvvis9031723iyymd1";
221 # An Obelisk project is a reflex-platform project with a predefined layout and role for each component
222 project = base': projectDefinition:
224 projectOut = { system, enableLibraryProfiling ? profiling }: let reflexPlatformProject = (getReflexPlatform { inherit system enableLibraryProfiling; }).project; in reflexPlatformProject (args@{ nixpkgs, ... }:
226 inherit (lib.strings) hasPrefix;
228 { android ? null #TODO: Better error when missing
229 , ios ? null #TODO: Better error when missing
231 , overrides ? _: _: {}
234 , shellToolOverrides ? _: _: {}
235 , withHoogle ? false # Setting this to `true` makes shell reloading far slower
236 , __closureCompilerOptimizationLevel ? "ADVANCED" # Set this to `null` to skip the closure-compiler step
237 , __withGhcide ? false
240 allConfig = nixpkgs.lib.makeExtensible (self: {
244 inherit android ios packages overrides tools shellToolOverrides withHoogle __closureCompilerOptimizationLevel __withGhcide;
245 staticFiles = if staticFiles == null then self.base + /static else staticFiles;
247 frontendName = "frontend";
248 backendName = "backend";
249 commonName = "common";
250 staticName = "obelisk-generated-static";
251 staticFilesImpure = let fs = self.userSettings.staticFiles; in if lib.isDerivation fs then fs else toString fs;
252 processedStatic = processAssets { src = self.userSettings.staticFiles; };
253 # The packages whose names and roles are defined by this package
254 predefinedPackages = lib.filterAttrs (_: x: x != null) {
255 ${self.frontendName} = nullIfAbsent (self.base + "/frontend");
256 ${self.commonName} = nullIfAbsent (self.base + "/common");
257 ${self.backendName} = nullIfAbsent (self.base + "/backend");
260 combinedPackages = self.predefinedPackages // self.userSettings.packages // self.shellPackages;
261 projectOverrides = self': super': {
262 ${self.staticName} = haskellLib.dontHaddock (self'.callCabal2nix self.staticName self.processedStatic.haskellManifest {});
263 ${self.backendName} = haskellLib.addBuildDepend super'.${self.backendName} self'.obelisk-run;
265 totalOverrides = lib.composeExtensions self.projectOverrides self.userSettings.overrides;
266 privateConfigDirs = ["config/backend"];
267 injectableConfig = builtins.filterSource (path: _:
268 !(lib.lists.any (x: hasPrefix (toString self.base + "/" + toString x) (toString path)) self.privateConfigDirs)
270 __androidWithConfig = configPath: {
271 ${if self.userSettings.android == null then null else self.frontendName} = {
272 executableName = "frontend";
273 ${if builtins.pathExists self.userSettings.staticFiles then "assets" else null} =
274 nixpkgs.obeliskExecutableConfig.platforms.android.inject
275 (self.injectableConfig configPath)
276 self.processedStatic.symlinked;
277 } // self.userSettings.android;
279 __iosWithConfig = configPath: {
280 ${if self.userSettings.ios == null then null else self.frontendName} = {
281 executableName = "frontend";
282 ${if builtins.pathExists self.userSettings.staticFiles then "staticSrc" else null} =
283 nixpkgs.obeliskExecutableConfig.platforms.ios.inject
284 (self.injectableConfig configPath)
285 self.processedStatic.symlinked;
286 } // self.userSettings.ios;
289 shells-ghc = builtins.attrNames (self.predefinedPackages // self.shellPackages);
296 shells-ghcSavedSplices = [
301 shellToolOverrides = lib.composeExtensions
302 self.userSettings.shellToolOverrides
303 (if self.userSettings.__withGhcide
304 then (import ./haskell-overlays/ghcide.nix)
308 project = reflexPlatformProject ({...}: self.projectConfig);
310 inherit (self) shellToolOverrides;
311 inherit (self.userSettings) tools withHoogle;
312 overrides = self.totalOverrides;
313 packages = self.combinedPackages;
315 ${if self.userSettings.android == null && self.userSettings.ios == null then null else "ghcSavedSplices"} =
316 lib.filter (x: lib.hasAttr x self.combinedPackages) self.shells-ghcSavedSplices;
317 ghc = lib.filter (x: lib.hasAttr x self.combinedPackages) self.shells-ghc;
318 ghcjs = lib.filter (x: lib.hasAttr x self.combinedPackages) self.shells-ghcjs;
320 android = self.__androidWithConfig (self.base + "/config");
321 ios = self.__iosWithConfig (self.base + "/config");
324 __unstable__.self = allConfig;
326 staticFilesImpure processedStatic
327 __iosWithConfig __androidWithConfig
329 inherit (self.userSettings)
330 android ios overrides packages shellToolOverrides staticFiles tools withHoogle
331 __closureCompilerOptimizationLevel
337 in (mkProject (projectDefinition args)).projectConfig);
338 mainProjectOut = projectOut { inherit system; };
339 serverOn = projectInst: version: serverExe
340 projectInst.ghc.backend
341 mainProjectOut.ghcjs.frontend
342 projectInst.passthru.staticFiles
343 projectInst.passthru.__closureCompilerOptimizationLevel
345 linuxExe = serverOn (projectOut { system = "x86_64-linux"; });
346 dummyVersion = "Version number is only available for deployments";
347 in mainProjectOut // {
348 __unstable__.profiledObRun = let
349 profiled = projectOut { inherit system; enableLibraryProfiling = true; };
350 exeSource = builtins.toFile "ob-run.hs" ''
351 {-# LANGUAGE NoImplicitPrelude #-}
352 {-# LANGUAGE PackageImports #-}
355 -- Explicitly import Prelude from base lest there be multiple modules called Prelude
356 import "base" Prelude (IO, (++), read)
358 import "base" Control.Exception (finally)
359 import "reflex" Reflex.Profiled (writeProfilingData)
360 import "base" System.Environment (getArgs)
362 import qualified "obelisk-run" Obelisk.Run
363 import qualified Frontend
364 import qualified Backend
368 [portStr, assets, profFileName] <- getArgs
369 Obelisk.Run.run (read portStr) (Obelisk.Run.runServeAsset assets) Backend.backend Frontend.frontend
370 `finally` writeProfilingData (profFileName ++ ".rprof")
372 in nixpkgs.runCommand "ob-run" {
373 buildInputs = [ (profiled.ghc.ghcWithPackages (p: [p.backend p.frontend])) ];
375 cp ${exeSource} ob-run.hs
377 ghc -x hs -prof -fno-prof-auto -threaded ob-run.hs -o $out/bin/ob-run
380 linuxExeConfigurable = linuxExe;
381 linuxExe = linuxExe dummyVersion;
382 exe = serverOn mainProjectOut dummyVersion;
383 server = args@{ hostName, adminEmail, routeHost, enableHttps, version, module ? serverModules.mkBaseEc2 }:
384 server (args // { exe = linuxExe version; });
385 obelisk = import (base' + "/.obelisk/impl") {};
387 haskellPackageSets = {
388 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