1{ system ? builtins.currentSystem
3, iosSdkVersion ? "10.2"
5, reflex-platform-func ? import ./dep/reflex-platform
8 reflex-platform = getReflexPlatform { inherit system; };
9 inherit (reflex-platform) hackGet nixpkgs;
12 inherit (import dep/gitignore.nix { inherit (nixpkgs) lib; }) gitignoreSource;
15 # WARNING: The order of application here seems to matter a great deal to
16 # how quickly `ghcid` is able to reload changes. As a rule of thumb,
17 # always apply `gitignoreSource` first.
18 # See https://github.com/obsidiansystems/obelisk/pull/666 and related.
19 pkgs.lib.cleanSource (gitignoreSource src);
21 commandRuntimeDeps = pkgs: with pkgs; [
28 getReflexPlatform = { system, enableLibraryProfiling ? profiling }: reflex-platform-func {
29 inherit iosSdkVersion config system enableLibraryProfiling;
33 obeliskExecutableConfig = import ./lib/executable-config { nixpkgs = pkgs; filterGitSource = cleanSource; };
39 # Fix misc upstream packages
41 pkgs = self.callPackage ({ pkgs }: pkgs) {};
42 haskellLib = pkgs.haskell.lib;
44 hnix = haskellLib.dontCheck (haskellLib.doJailbreak (self.callCabal2nix "hnix" (hackGet dep/hnix) {}));
45 hnix-store-core = self.callHackage "hnix-store-core" "0.1.0.0" {};
47 ghcid = self.callCabal2nix "ghcid" (hackGet ./dep/ghcid) {};
48 # Exports more internals
49 snap-core = haskellLib.dontCheck (self.callCabal2nix "snap-core" (hackGet ./dep/snap-core) {});
52 pkgs.obeliskExecutableConfig.haskellOverlay
54 # Add obelisk packages
56 pkgs = self.callPackage ({ pkgs }: pkgs) {};
57 onLinux = pkg: f: if pkgs.stdenv.isLinux then f pkg else pkg;
59 shelly = self.callHackage "shelly" "1.9.0" {};
61 obelisk-executable-config-inject = pkgs.obeliskExecutableConfig.platforms.web.inject self;
63 obelisk-asset-manifest = self.callCabal2nix "obelisk-asset-manifest" (cleanSource ./lib/asset/manifest) {};
64 obelisk-asset-serve-snap = self.callCabal2nix "obelisk-asset-serve-snap" (cleanSource ./lib/asset/serve-snap) {};
65 obelisk-backend = self.callCabal2nix "obelisk-backend" (cleanSource ./lib/backend) {};
66 obelisk-cliapp = self.callCabal2nix "obelisk-cliapp" (cleanSource ./lib/cliapp) {};
67 obelisk-command = haskellLib.overrideCabal (self.callCabal2nix "obelisk-command" (cleanSource ./lib/command) {}) {
68 librarySystemDepends = [
71 (haskellLib.justStaticExecutables self.ghcid)
74 obelisk-frontend = self.callCabal2nix "obelisk-frontend" (cleanSource ./lib/frontend) {};
75 obelisk-run = onLinux (self.callCabal2nix "obelisk-run" (cleanSource ./lib/run) {}) (pkg:
76 haskellLib.overrideCabal pkg (drv: { librarySystemDepends = [ pkgs.iproute ]; })
78 obelisk-route = self.callCabal2nix "obelisk-route" (cleanSource ./lib/route) {};
79 obelisk-selftest = haskellLib.overrideCabal (self.callCabal2nix "obelisk-selftest" (cleanSource ./lib/selftest) {}) {
80 librarySystemDepends = [
87 obelisk-snap-extras = self.callCabal2nix "obelisk-snap-extras" (cleanSource ./lib/snap-extras) {};
88 tabulation = self.callCabal2nix "tabulation" (cleanSource ./lib/tabulation) {};
92 pkgs = self.callPackage ({ pkgs }: pkgs) {};
93 haskellLib = pkgs.haskell.lib;
95 # Dynamic linking with split objects dramatically increases startup time (about
96 # 0.5 seconds on a decent machine with SSD), so we do `justStaticExecutables`.
97 obelisk-command = haskellLib.overrideCabal
98 (haskellLib.generateOptparseApplicativeCompletion "ob"
99 (haskellLib.justStaticExecutables super.obelisk-command))
101 buildTools = (drv.buildTools or []) ++ [ pkgs.buildPackages.makeWrapper ];
103 ${drv.postFixup or ""}
104 # Make `ob` reference its runtime dependencies.
105 wrapProgram "$out"/bin/ob --prefix PATH : ${pkgs.lib.makeBinPath (commandRuntimeDeps pkgs)}
108 obelisk-selftest = haskellLib.justStaticExecutables super.obelisk-selftest;
114 # The haskell environment used to build Obelisk itself, e.g. the 'ob' command
115 ghcObelisk = reflex-platform.ghc;
117 # Development environments for obelisk packages.
118 ghcObeliskEnvs = pkgs.lib.mapAttrs (n: v: reflex-platform.workOn ghcObelisk v) ghcObelisk;
120 inherit (import ./lib/asset/assets.nix { inherit nixpkgs; }) mkAssets;
122 haskellLib = pkgs.haskell.lib;
125 inherit reflex-platform;
126 inherit (reflex-platform) nixpkgs pinBuildInputs;
127 inherit (nixpkgs) lib;
128 pathGit = ./.; # Used in CI by the migration graph hash algorithm to correctly ignore files.
129 path = reflex-platform.filterGit ./.;
130 obelisk = ghcObelisk;
131 obeliskEnvs = pkgs.lib.filterAttrs (k: _: pkgs.lib.strings.hasPrefix "obelisk-" k) ghcObeliskEnvs;
132 command = ghcObelisk.obelisk-command;
133 shell = pinBuildInputs "obelisk-shell" ([command] ++ commandRuntimeDeps pkgs);
135 selftest = pkgs.writeScript "selftest" ''
136 #!${pkgs.runtimeShell}
139 PATH="${command}/bin:$PATH"
141 "${ghcObelisk.obelisk-selftest}/bin/obelisk-selftest" +RTS -N -RTS "$@"
143 skeleton = pkgs.runCommand "skeleton" {
144 dir = builtins.filterSource (path: type: builtins.trace path (baseNameOf path != ".obelisk")) ./skeleton;
148 nullIfAbsent = p: if lib.pathExists p then p else null;
149 #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.
150 processAssets = { src, packageName ? "obelisk-generated-static", moduleName ? "Obelisk.Generated.Static" }: pkgs.runCommand "asset-manifest" {
152 outputs = [ "out" "haskellManifest" "symlinked" ];
153 nativeBuildInputs = [ ghcObelisk.obelisk-asset-manifest ];
157 mkdir -p "$symlinked"
158 obelisk-asset-manifest-generate "$src" "$haskellManifest" ${packageName} ${moduleName} "$symlinked"
161 compressedJs = frontend: optimizationLevel: pkgs.runCommand "compressedJs" {} ''
164 # TODO profiling + static shouldn't break and need an ad-hoc workaround like that
165 ln -s "${haskellLib.justStaticExecutables frontend}/bin/frontend.jsexe/all.js" all.unminified.js
166 ${if optimizationLevel == null then ''
167 ln -s all.unminified.js all.js
169 ${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
170 echo "//# sourceMappingURL=all.js.map" >> all.js
175 mkBaseEc2 = { nixosPkgs, ... }: {...}: {
177 (nixosPkgs.path + /nixos/modules/virtualisation/amazon-image.nix)
182 mkDefaultNetworking = { adminEmail, enableHttps, hostName, routeHost, ... }: {...}: {
185 firewall.allowedTCPPorts = if enableHttps then [ 80 443 ] else [ 80 ];
188 # `amazon-image.nix` already sets these but if the user provides their own module then
189 # forgetting these can cause them to lose access to the server!
190 # https://github.com/NixOS/nixpkgs/blob/fab05f17d15e4e125def4fd4e708d205b41d8d74/nixos/modules/virtualisation/amazon-image.nix#L133-L136
191 services.openssh.enable = true;
192 services.openssh.permitRootLogin = "prohibit-password";
194 security.acme.certs = if enableHttps then {
195 "${routeHost}".email = adminEmail;
207 , internalPort ? 8000
208 , backendArgs ? "--port=${toString internalPort}"
213 virtualHosts."${routeHost}" = {
214 enableACME = enableHttps;
215 forceSSL = enableHttps;
216 locations.${baseUrl} = {
217 proxyPass = "http://127.0.0.1:" + toString internalPort;
218 proxyWebsockets = true;
222 systemd.services.${name} = {
223 wantedBy = [ "multi-user.target" ];
224 after = [ "network.target" ];
225 restartIfChanged = true;
226 path = [ pkgs.gnutar ];
230 exec ./backend ${backendArgs} </dev/null
234 KillMode = "process";
235 WorkingDirectory = "~";
242 description = "${user} service";
243 home = "/var/lib/${user}";
248 groups.${group} = {};
255 serverExe = backend: frontend: assets: optimizationLevel: version:
256 pkgs.runCommand "serverExe" {} ''
259 ln -s "${if profiling then backend else haskellLib.justStaticExecutables backend}"/bin/* $out/
260 ln -s "${mkAssets assets}" $out/static.assets
261 ln -s ${mkAssets (compressedJs frontend optimizationLevel)} $out/frontend.jsexe.assets
262 echo ${version} > $out/version
265 server = { exe, hostName, adminEmail, routeHost, enableHttps, version, module ? serverModules.mkBaseEc2 }@args:
267 nixos = import (pkgs.path + /nixos);
269 system = "x86_64-linux";
272 (module { inherit exe hostName adminEmail routeHost enableHttps version; nixosPkgs = pkgs; })
273 (serverModules.mkDefaultNetworking args)
274 (serverModules.mkObeliskApp args)
279 # An Obelisk project is a reflex-platform project with a predefined layout and role for each component
280 project = base': projectDefinition:
282 projectOut = { system, enableLibraryProfiling ? profiling }: let reflexPlatformProject = (getReflexPlatform { inherit system enableLibraryProfiling; }).project; in reflexPlatformProject (args@{ nixpkgs, ... }:
284 inherit (lib.strings) hasPrefix;
286 { android ? null #TODO: Better error when missing
287 , ios ? null #TODO: Better error when missing
289 , overrides ? _: _: {}
292 , shellToolOverrides ? _: _: {}
293 , withHoogle ? false # Setting this to `true` makes shell reloading far slower
294 , __closureCompilerOptimizationLevel ? "ADVANCED" # Set this to `null` to skip the closure-compiler step
297 allConfig = nixpkgs.lib.makeExtensible (self: {
301 inherit android ios packages overrides tools shellToolOverrides withHoogle __closureCompilerOptimizationLevel;
302 staticFiles = if staticFiles == null then self.base + /static else staticFiles;
304 frontendName = "frontend";
305 backendName = "backend";
306 commonName = "common";
307 staticName = "obelisk-generated-static";
308 staticFilesImpure = let fs = self.userSettings.staticFiles; in if lib.isDerivation fs then fs else toString fs;
309 processedStatic = processAssets { src = self.userSettings.staticFiles; };
310 # The packages whose names and roles are defined by this package
311 predefinedPackages = lib.filterAttrs (_: x: x != null) {
312 ${self.frontendName} = nullIfAbsent (self.base + "/frontend");
313 ${self.commonName} = nullIfAbsent (self.base + "/common");
314 ${self.backendName} = nullIfAbsent (self.base + "/backend");
317 combinedPackages = self.predefinedPackages // self.userSettings.packages // self.shellPackages;
318 projectOverrides = self': super': {
319 ${self.staticName} = haskellLib.dontHaddock (self'.callCabal2nix self.staticName self.processedStatic.haskellManifest {});
320 ${self.backendName} = haskellLib.addBuildDepend super'.${self.backendName} self'.obelisk-run;
322 totalOverrides = lib.composeExtensions self.projectOverrides self.userSettings.overrides;
323 privateConfigDirs = ["config/backend"];
324 injectableConfig = builtins.filterSource (path: _:
325 !(lib.lists.any (x: hasPrefix (toString self.base + "/" + toString x) (toString path)) self.privateConfigDirs)
327 __androidWithConfig = configPath: {
328 ${if self.userSettings.android == null then null else self.frontendName} = {
329 executableName = "frontend";
330 ${if builtins.pathExists self.userSettings.staticFiles then "assets" else null} =
331 nixpkgs.obeliskExecutableConfig.platforms.android.inject
332 (self.injectableConfig configPath)
333 self.processedStatic.symlinked;
334 } // self.userSettings.android;
336 __iosWithConfig = configPath: {
337 ${if self.userSettings.ios == null then null else self.frontendName} = {
338 executableName = "frontend";
339 ${if builtins.pathExists self.userSettings.staticFiles then "staticSrc" else null} =
340 nixpkgs.obeliskExecutableConfig.platforms.ios.inject
341 (self.injectableConfig configPath)
342 self.processedStatic.symlinked;
343 } // self.userSettings.ios;
346 shells-ghc = builtins.attrNames (self.predefinedPackages // self.shellPackages);
353 shells-ghcSavedSplices = [
358 project = reflexPlatformProject ({...}: self.projectConfig);
360 inherit (self.userSettings) shellToolOverrides tools withHoogle;
361 overrides = self.totalOverrides;
362 packages = self.combinedPackages;
364 ${if self.userSettings.android == null && self.userSettings.ios == null then null else "ghcSavedSplices"} =
365 lib.filter (x: lib.hasAttr x self.combinedPackages) self.shells-ghcSavedSplices;
366 ghc = lib.filter (x: lib.hasAttr x self.combinedPackages) self.shells-ghc;
367 ghcjs = lib.filter (x: lib.hasAttr x self.combinedPackages) self.shells-ghcjs;
369 android = self.__androidWithConfig (self.base + "/config");
370 ios = self.__iosWithConfig (self.base + "/config");
373 __unstable__.self = allConfig;
375 staticFilesImpure processedStatic
376 __iosWithConfig __androidWithConfig
378 inherit (self.userSettings)
379 android ios overrides packages shellToolOverrides staticFiles tools withHoogle
380 __closureCompilerOptimizationLevel
386 in (mkProject (projectDefinition args)).projectConfig);
387 mainProjectOut = projectOut { inherit system; };
388 serverOn = projectInst: version: serverExe
389 projectInst.ghc.backend
390 mainProjectOut.ghcjs.frontend
391 projectInst.passthru.staticFiles
392 projectInst.passthru.__closureCompilerOptimizationLevel
394 linuxExe = serverOn (projectOut { system = "x86_64-linux"; });
395 dummyVersion = "Version number is only available for deployments";
396 in mainProjectOut // {
397 __unstable__.profiledObRun = let
398 profiled = projectOut { inherit system; enableLibraryProfiling = true; };
399 exeSource = builtins.toFile "ob-run.hs" ''
402 import Control.Exception
403 import Reflex.Profiled
404 import System.Environment
406 import qualified Obelisk.Run
407 import qualified Frontend
408 import qualified Backend
413 let port = read $ args !! 0
415 profileFile = (args !! 2) <> ".rprof"
416 Obelisk.Run.run port (Obelisk.Run.runServeAsset assets) Backend.backend Frontend.frontend `finally` writeProfilingData profileFile
418 in nixpkgs.runCommand "ob-run" {
419 buildInputs = [ (profiled.ghc.ghcWithPackages (p: [ p.backend p.frontend])) ];
422 ghc -x hs -prof -fno-prof-auto -threaded ${exeSource} -o $out/bin/ob-run
425 linuxExeConfigurable = linuxExe;
426 linuxExe = linuxExe dummyVersion;
427 exe = serverOn mainProjectOut dummyVersion;
428 server = args@{ hostName, adminEmail, routeHost, enableHttps, version, module ? serverModules.mkBaseEc2 }:
429 server (args // { exe = linuxExe version; });
430 obelisk = import (base' + "/.obelisk/impl") {};
432 haskellPackageSets = {
433 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