1{ system ? builtins.currentSystem
3, iosSdkVersion ? "10.2"
5, reflex-platform-func ? import ./dep/reflex-platform
8 cleanSource = builtins.filterSource (name: _: let baseName = builtins.baseNameOf name; in !(
9 builtins.match "^\\.ghc\\.environment.*" baseName != null ||
10 baseName == "cabal.project.local"
13 commandRuntimeDeps = pkgs: with pkgs; [
20 getReflexPlatform = sys: reflex-platform-func {
21 inherit iosSdkVersion config;
23 enableLibraryProfiling = profiling;
27 obeliskExecutableConfig = import ./lib/executable-config { nixpkgs = pkgs; filterGitSource = cleanSource; };
33 # Fix misc upstream packages
35 pkgs = self.callPackage ({ pkgs }: pkgs) {};
36 haskellLib = pkgs.haskell.lib;
38 hnix = haskellLib.dontCheck (haskellLib.doJailbreak (self.callCabal2nix "hnix" (hackGet dep/hnix) {}));
39 hnix-store-core = self.callHackage "hnix-store-core" "0.1.0.0" {};
41 ghcid = self.callCabal2nix "ghcid" (hackGet ./dep/ghcid) {};
44 pkgs.obeliskExecutableConfig.haskellOverlay
46 # Add obelisk packages
48 pkgs = self.callPackage ({ pkgs }: pkgs) {};
49 onLinux = pkg: f: if pkgs.stdenv.isLinux then f pkg else pkg;
51 shelly = self.callHackage "shelly" "1.9.0" {};
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 = haskellLib.overrideCabal (self.callCabal2nix "obelisk-selftest" (cleanSource ./lib/selftest) {}) {
71 librarySystemDepends = [
76 obelisk-snap-extras = self.callCabal2nix "obelisk-snap-extras" (cleanSource ./lib/snap-extras) {};
77 tabulation = self.callCabal2nix "tabulation" (cleanSource ./lib/tabulation) {};
81 pkgs = self.callPackage ({ pkgs }: pkgs) {};
82 haskellLib = pkgs.haskell.lib;
84 # Dynamic linking with split objects dramatically increases startup time (about
85 # 0.5 seconds on a decent machine with SSD), so we do `justStaticExecutables`.
86 obelisk-command = haskellLib.overrideCabal
87 (haskellLib.generateOptparseApplicativeCompletion "ob"
88 (haskellLib.justStaticExecutables super.obelisk-command))
90 buildTools = (drv.buildTools or []) ++ [ pkgs.buildPackages.makeWrapper ];
92 ${drv.postFixup or ""}
93 # Make `ob` reference its runtime dependencies.
94 wrapProgram "$out"/bin/ob --prefix PATH : ${pkgs.lib.makeBinPath (commandRuntimeDeps pkgs)}
97 obelisk-selftest = haskellLib.justStaticExecutables super.obelisk-selftest;
103 reflex-platform = getReflexPlatform system;
104 inherit (reflex-platform) hackGet nixpkgs;
107 # The haskell environment used to build Obelisk itself, e.g. the 'ob' command
108 ghcObelisk = reflex-platform.ghc;
110 # Development environments for obelisk packages.
111 ghcObeliskEnvs = pkgs.lib.mapAttrs (n: v: reflex-platform.workOn ghcObelisk v) ghcObelisk;
113 inherit (import ./lib/asset/assets.nix { inherit nixpkgs; }) mkAssets;
115 haskellLib = pkgs.haskell.lib;
118 inherit reflex-platform;
119 inherit (reflex-platform) nixpkgs pinBuildInputs;
120 inherit (nixpkgs) lib;
121 pathGit = ./.; # Used in CI by the migration graph hash algorithm to correctly ignore files.
122 path = reflex-platform.filterGit ./.;
123 obelisk = ghcObelisk;
124 obeliskEnvs = pkgs.lib.filterAttrs (k: _: pkgs.lib.strings.hasPrefix "obelisk-" k) ghcObeliskEnvs;
125 command = ghcObelisk.obelisk-command;
126 shell = pinBuildInputs "obelisk-shell" ([command] ++ commandRuntimeDeps pkgs);
128 selftest = pkgs.writeScript "selftest" ''
129 #!${pkgs.runtimeShell}
132 PATH="${command}/bin:$PATH"
133 export OBELISK_IMPL="$(mktemp -d)"
134 ${pkgs.git}/bin/git clone file://${pathGit} $OBELISK_IMPL
135 "${ghcObelisk.obelisk-selftest}/bin/obelisk-selftest" +RTS -N -RTS "$@"
137 skeleton = pkgs.runCommand "skeleton" {
138 dir = builtins.filterSource (path: type: builtins.trace path (baseNameOf path != ".obelisk")) ./skeleton;
142 nullIfAbsent = p: if lib.pathExists p then p else null;
143 #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.
144 processAssets = { src, packageName ? "obelisk-generated-static", moduleName ? "Obelisk.Generated.Static" }: pkgs.runCommand "asset-manifest" {
146 outputs = [ "out" "haskellManifest" "symlinked" ];
147 nativeBuildInputs = [ ghcObelisk.obelisk-asset-manifest ];
151 mkdir -p "$symlinked"
152 obelisk-asset-manifest-generate "$src" "$haskellManifest" ${packageName} ${moduleName} "$symlinked"
155 compressedJs = frontend: optimizationLevel: pkgs.runCommand "compressedJs" {} ''
158 # TODO profiling + static shouldn't break and need an ad-hoc workaround like that
159 ln -s "${haskellLib.justStaticExecutables frontend}/bin/frontend.jsexe/all.js" all.unminified.js
160 ${if optimizationLevel == null then ''
161 ln -s all.unminified.js all.js
163 ${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
164 echo "//# sourceMappingURL=all.js.map" >> all.js
169 mkBaseEc2 = { hostName, routeHost, enableHttps, adminEmail, ... }: {...}: {
171 (pkgs.path + /nixos/modules/virtualisation/amazon-image.nix)
175 firewall.allowedTCPPorts = if enableHttps then [ 80 443 ] else [ 80 ];
177 security.acme.certs = if enableHttps then {
178 "${routeHost}".email = adminEmail;
191 , internalPort ? 8000
192 , backendArgs ? "--port=${toString internalPort}"
197 virtualHosts."${routeHost}" = {
198 enableACME = enableHttps;
199 forceSSL = enableHttps;
200 locations.${baseUrl} = {
201 proxyPass = "http://127.0.0.1:" + toString internalPort;
202 proxyWebsockets = true;
206 systemd.services.${name} = {
207 wantedBy = [ "multi-user.target" ];
208 after = [ "network.target" ];
209 restartIfChanged = true;
210 path = [ pkgs.gnutar ];
214 exec ./backend ${backendArgs} </dev/null
218 KillMode = "process";
219 WorkingDirectory = "~";
226 description = "${user} service";
227 home = "/var/lib/${user}";
232 groups.${group} = {};
237 serverExe = backend: frontend: assets: optimizationLevel: version:
238 pkgs.runCommand "serverExe" {} ''
241 ln -s "${if profiling then backend else haskellLib.justStaticExecutables backend}"/bin/* $out/
242 ln -s "${mkAssets assets}" $out/static.assets
243 ln -s ${mkAssets (compressedJs frontend optimizationLevel)} $out/frontend.jsexe.assets
244 echo ${version} > $out/version
247 server = { exe, hostName, adminEmail, routeHost, enableHttps, version }@args:
249 nixos = import (pkgs.path + /nixos);
251 system = "x86_64-linux";
254 (serverModules.mkBaseEc2 args)
255 (serverModules.mkObeliskApp args)
260 # An Obelisk project is a reflex-platform project with a predefined layout and role for each component
261 project = base': projectDefinition:
263 projectOut = sys: let reflexPlatformProject = (getReflexPlatform sys).project; in reflexPlatformProject (args@{ nixpkgs, ... }:
265 inherit (lib.strings) hasPrefix;
267 { android ? null #TODO: Better error when missing
268 , ios ? null #TODO: Better error when missing
270 , overrides ? _: _: {}
273 , shellToolOverrides ? _: _: {}
274 , withHoogle ? false # Setting this to `true` makes shell reloading far slower
275 , __closureCompilerOptimizationLevel ? "ADVANCED" # Set this to `null` to skip the closure-compiler step
278 allConfig = nixpkgs.lib.makeExtensible (self: {
282 inherit android ios packages overrides tools shellToolOverrides withHoogle __closureCompilerOptimizationLevel;
283 staticFiles = if staticFiles == null then self.base + /static else staticFiles;
285 frontendName = "frontend";
286 backendName = "backend";
287 commonName = "common";
288 staticName = "obelisk-generated-static";
289 staticFilesImpure = let fs = self.userSettings.staticFiles; in if lib.isDerivation fs then fs else toString fs;
290 processedStatic = processAssets { src = self.userSettings.staticFiles; };
291 # The packages whose names and roles are defined by this package
292 predefinedPackages = lib.filterAttrs (_: x: x != null) {
293 ${self.frontendName} = nullIfAbsent (self.base + "/frontend");
294 ${self.commonName} = nullIfAbsent (self.base + "/common");
295 ${self.backendName} = nullIfAbsent (self.base + "/backend");
298 combinedPackages = self.predefinedPackages // self.userSettings.packages // self.shellPackages;
299 projectOverrides = self': super': {
300 ${self.staticName} = haskellLib.dontHaddock (self'.callCabal2nix self.staticName self.processedStatic.haskellManifest {});
301 ${self.backendName} = haskellLib.addBuildDepend super'.${self.backendName} self'.obelisk-run;
303 totalOverrides = lib.composeExtensions self.projectOverrides self.userSettings.overrides;
304 privateConfigDirs = ["config/backend"];
305 injectableConfig = builtins.filterSource (path: _:
306 !(lib.lists.any (x: hasPrefix (toString self.base + "/" + toString x) (toString path)) self.privateConfigDirs)
308 __androidWithConfig = configPath: {
309 ${if self.userSettings.android == null then null else self.frontendName} = {
310 executableName = "frontend";
311 ${if builtins.pathExists self.userSettings.staticFiles then "assets" else null} =
312 nixpkgs.obeliskExecutableConfig.platforms.android.inject
313 (self.injectableConfig configPath)
314 self.processedStatic.symlinked;
315 } // self.userSettings.android;
317 __iosWithConfig = configPath: {
318 ${if self.userSettings.ios == null then null else self.frontendName} = {
319 executableName = "frontend";
320 ${if builtins.pathExists self.userSettings.staticFiles then "staticSrc" else null} =
321 nixpkgs.obeliskExecutableConfig.platforms.ios.inject
322 (self.injectableConfig configPath)
323 self.processedStatic.symlinked;
324 } // self.userSettings.ios;
327 shells-ghc = builtins.attrNames self.shellPackages;
334 shells-ghcSavedSplices = [
339 project = reflexPlatformProject ({...}: self.projectConfig);
341 inherit (self.userSettings) shellToolOverrides tools withHoogle;
342 overrides = self.totalOverrides;
343 packages = self.combinedPackages;
345 ${if self.userSettings.android == null && self.userSettings.ios == null then null else "ghcSavedSplices"} =
346 lib.filter (x: lib.hasAttr x self.combinedPackages) self.shells-ghcSavedSplices;
347 ghc = lib.filter (x: lib.hasAttr x self.combinedPackages) self.shells-ghc;
348 ghcjs = lib.filter (x: lib.hasAttr x self.combinedPackages) self.shells-ghcjs;
350 android = self.__androidWithConfig (self.base + "/config");
351 ios = self.__iosWithConfig (self.base + "/config");
354 __unstable__.self = allConfig;
356 staticFilesImpure processedStatic
357 __iosWithConfig __androidWithConfig
359 inherit (self.userSettings)
360 android ios overrides packages shellToolOverrides staticFiles tools withHoogle
361 __closureCompilerOptimizationLevel
367 in (mkProject (projectDefinition args)).projectConfig);
368 mainProjectOut = projectOut system;
369 serverOn = projectInst: version: serverExe
370 projectInst.ghc.backend
371 mainProjectOut.ghcjs.frontend
372 projectInst.passthru.staticFiles
373 projectInst.passthru.__closureCompilerOptimizationLevel
375 linuxExe = serverOn (projectOut "x86_64-linux");
376 dummyVersion = "Version number is only available for deployments";
377 in mainProjectOut // {
378 linuxExeConfigurable = linuxExe;
379 linuxExe = linuxExe dummyVersion;
380 exe = serverOn mainProjectOut dummyVersion;
381 server = args@{ hostName, adminEmail, routeHost, enableHttps, version }:
382 server (args // { exe = linuxExe version; });
383 obelisk = import (base' + "/.obelisk/impl") {};
385 haskellPackageSets = {
386 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