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 = [
78 obelisk-snap-extras = self.callCabal2nix "obelisk-snap-extras" (cleanSource ./lib/snap-extras) {};
79 tabulation = self.callCabal2nix "tabulation" (cleanSource ./lib/tabulation) {};
83 pkgs = self.callPackage ({ pkgs }: pkgs) {};
84 haskellLib = pkgs.haskell.lib;
86 # Dynamic linking with split objects dramatically increases startup time (about
87 # 0.5 seconds on a decent machine with SSD), so we do `justStaticExecutables`.
88 obelisk-command = haskellLib.overrideCabal
89 (haskellLib.generateOptparseApplicativeCompletion "ob"
90 (haskellLib.justStaticExecutables super.obelisk-command))
92 buildTools = (drv.buildTools or []) ++ [ pkgs.buildPackages.makeWrapper ];
94 ${drv.postFixup or ""}
95 # Make `ob` reference its runtime dependencies.
96 wrapProgram "$out"/bin/ob --prefix PATH : ${pkgs.lib.makeBinPath (commandRuntimeDeps pkgs)}
99 obelisk-selftest = haskellLib.justStaticExecutables super.obelisk-selftest;
105 reflex-platform = getReflexPlatform system;
106 inherit (reflex-platform) hackGet nixpkgs;
109 # The haskell environment used to build Obelisk itself, e.g. the 'ob' command
110 ghcObelisk = reflex-platform.ghc;
112 # Development environments for obelisk packages.
113 ghcObeliskEnvs = pkgs.lib.mapAttrs (n: v: reflex-platform.workOn ghcObelisk v) ghcObelisk;
115 inherit (import ./lib/asset/assets.nix { inherit nixpkgs; }) mkAssets;
117 haskellLib = pkgs.haskell.lib;
120 inherit reflex-platform;
121 inherit (reflex-platform) nixpkgs pinBuildInputs;
122 inherit (nixpkgs) lib;
123 pathGit = ./.; # Used in CI by the migration graph hash algorithm to correctly ignore files.
124 path = reflex-platform.filterGit ./.;
125 obelisk = ghcObelisk;
126 obeliskEnvs = pkgs.lib.filterAttrs (k: _: pkgs.lib.strings.hasPrefix "obelisk-" k) ghcObeliskEnvs;
127 command = ghcObelisk.obelisk-command;
128 shell = pinBuildInputs "obelisk-shell" ([command] ++ commandRuntimeDeps pkgs);
130 selftest = pkgs.writeScript "selftest" ''
131 #!${pkgs.runtimeShell}
134 PATH="${command}/bin:$PATH"
136 "${ghcObelisk.obelisk-selftest}/bin/obelisk-selftest" +RTS -N -RTS "$@"
138 skeleton = pkgs.runCommand "skeleton" {
139 dir = builtins.filterSource (path: type: builtins.trace path (baseNameOf path != ".obelisk")) ./skeleton;
143 nullIfAbsent = p: if lib.pathExists p then p else null;
144 #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.
145 processAssets = { src, packageName ? "obelisk-generated-static", moduleName ? "Obelisk.Generated.Static" }: pkgs.runCommand "asset-manifest" {
147 outputs = [ "out" "haskellManifest" "symlinked" ];
148 nativeBuildInputs = [ ghcObelisk.obelisk-asset-manifest ];
152 mkdir -p "$symlinked"
153 obelisk-asset-manifest-generate "$src" "$haskellManifest" ${packageName} ${moduleName} "$symlinked"
156 compressedJs = frontend: optimizationLevel: pkgs.runCommand "compressedJs" {} ''
159 # TODO profiling + static shouldn't break and need an ad-hoc workaround like that
160 ln -s "${haskellLib.justStaticExecutables frontend}/bin/frontend.jsexe/all.js" all.unminified.js
161 ${if optimizationLevel == null then ''
162 ln -s all.unminified.js all.js
164 ${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
165 echo "//# sourceMappingURL=all.js.map" >> all.js
170 mkBaseEc2 = { hostName, routeHost, enableHttps, adminEmail, ... }: {...}: {
172 (pkgs.path + /nixos/modules/virtualisation/amazon-image.nix)
176 firewall.allowedTCPPorts = if enableHttps then [ 80 443 ] else [ 80 ];
178 security.acme.certs = if enableHttps then {
179 "${routeHost}".email = adminEmail;
192 , internalPort ? 8000
193 , backendArgs ? "--port=${toString internalPort}"
198 virtualHosts."${routeHost}" = {
199 enableACME = enableHttps;
200 forceSSL = enableHttps;
201 locations.${baseUrl} = {
202 proxyPass = "http://127.0.0.1:" + toString internalPort;
203 proxyWebsockets = true;
207 systemd.services.${name} = {
208 wantedBy = [ "multi-user.target" ];
209 after = [ "network.target" ];
210 restartIfChanged = true;
211 path = [ pkgs.gnutar ];
215 exec ./backend ${backendArgs} </dev/null
219 KillMode = "process";
220 WorkingDirectory = "~";
227 description = "${user} service";
228 home = "/var/lib/${user}";
233 groups.${group} = {};
238 serverExe = backend: frontend: assets: optimizationLevel: version:
239 pkgs.runCommand "serverExe" {} ''
242 ln -s "${if profiling then backend else haskellLib.justStaticExecutables backend}"/bin/* $out/
243 ln -s "${mkAssets assets}" $out/static.assets
244 ln -s ${mkAssets (compressedJs frontend optimizationLevel)} $out/frontend.jsexe.assets
245 echo ${version} > $out/version
248 server = { exe, hostName, adminEmail, routeHost, enableHttps, version }@args:
250 nixos = import (pkgs.path + /nixos);
252 system = "x86_64-linux";
255 (serverModules.mkBaseEc2 args)
256 (serverModules.mkObeliskApp args)
261 # An Obelisk project is a reflex-platform project with a predefined layout and role for each component
262 project = base': projectDefinition:
264 projectOut = sys: let reflexPlatformProject = (getReflexPlatform sys).project; in reflexPlatformProject (args@{ nixpkgs, ... }:
266 inherit (lib.strings) hasPrefix;
268 { android ? null #TODO: Better error when missing
269 , ios ? null #TODO: Better error when missing
271 , overrides ? _: _: {}
274 , shellToolOverrides ? _: _: {}
275 , withHoogle ? false # Setting this to `true` makes shell reloading far slower
276 , __closureCompilerOptimizationLevel ? "ADVANCED" # Set this to `null` to skip the closure-compiler step
279 allConfig = nixpkgs.lib.makeExtensible (self: {
283 inherit android ios packages overrides tools shellToolOverrides withHoogle __closureCompilerOptimizationLevel;
284 staticFiles = if staticFiles == null then self.base + /static else staticFiles;
286 frontendName = "frontend";
287 backendName = "backend";
288 commonName = "common";
289 staticName = "obelisk-generated-static";
290 staticFilesImpure = let fs = self.userSettings.staticFiles; in if lib.isDerivation fs then fs else toString fs;
291 processedStatic = processAssets { src = self.userSettings.staticFiles; };
292 # The packages whose names and roles are defined by this package
293 predefinedPackages = lib.filterAttrs (_: x: x != null) {
294 ${self.frontendName} = nullIfAbsent (self.base + "/frontend");
295 ${self.commonName} = nullIfAbsent (self.base + "/common");
296 ${self.backendName} = nullIfAbsent (self.base + "/backend");
299 combinedPackages = self.predefinedPackages // self.userSettings.packages // self.shellPackages;
300 projectOverrides = self': super': {
301 ${self.staticName} = haskellLib.dontHaddock (self'.callCabal2nix self.staticName self.processedStatic.haskellManifest {});
302 ${self.backendName} = haskellLib.addBuildDepend super'.${self.backendName} self'.obelisk-run;
304 totalOverrides = lib.composeExtensions self.projectOverrides self.userSettings.overrides;
305 privateConfigDirs = ["config/backend"];
306 injectableConfig = builtins.filterSource (path: _:
307 !(lib.lists.any (x: hasPrefix (toString self.base + "/" + toString x) (toString path)) self.privateConfigDirs)
309 __androidWithConfig = configPath: {
310 ${if self.userSettings.android == null then null else self.frontendName} = {
311 executableName = "frontend";
312 ${if builtins.pathExists self.userSettings.staticFiles then "assets" else null} =
313 nixpkgs.obeliskExecutableConfig.platforms.android.inject
314 (self.injectableConfig configPath)
315 self.processedStatic.symlinked;
316 } // self.userSettings.android;
318 __iosWithConfig = configPath: {
319 ${if self.userSettings.ios == null then null else self.frontendName} = {
320 executableName = "frontend";
321 ${if builtins.pathExists self.userSettings.staticFiles then "staticSrc" else null} =
322 nixpkgs.obeliskExecutableConfig.platforms.ios.inject
323 (self.injectableConfig configPath)
324 self.processedStatic.symlinked;
325 } // self.userSettings.ios;
328 shells-ghc = builtins.attrNames (self.predefinedPackages // self.shellPackages);
335 shells-ghcSavedSplices = [
340 project = reflexPlatformProject ({...}: self.projectConfig);
342 inherit (self.userSettings) shellToolOverrides tools withHoogle;
343 overrides = self.totalOverrides;
344 packages = self.combinedPackages;
346 ${if self.userSettings.android == null && self.userSettings.ios == null then null else "ghcSavedSplices"} =
347 lib.filter (x: lib.hasAttr x self.combinedPackages) self.shells-ghcSavedSplices;
348 ghc = lib.filter (x: lib.hasAttr x self.combinedPackages) self.shells-ghc;
349 ghcjs = lib.filter (x: lib.hasAttr x self.combinedPackages) self.shells-ghcjs;
351 android = self.__androidWithConfig (self.base + "/config");
352 ios = self.__iosWithConfig (self.base + "/config");
355 __unstable__.self = allConfig;
357 staticFilesImpure processedStatic
358 __iosWithConfig __androidWithConfig
360 inherit (self.userSettings)
361 android ios overrides packages shellToolOverrides staticFiles tools withHoogle
362 __closureCompilerOptimizationLevel
368 in (mkProject (projectDefinition args)).projectConfig);
369 mainProjectOut = projectOut system;
370 serverOn = projectInst: version: serverExe
371 projectInst.ghc.backend
372 mainProjectOut.ghcjs.frontend
373 projectInst.passthru.staticFiles
374 projectInst.passthru.__closureCompilerOptimizationLevel
376 linuxExe = serverOn (projectOut "x86_64-linux");
377 dummyVersion = "Version number is only available for deployments";
378 in mainProjectOut // {
379 linuxExeConfigurable = linuxExe;
380 linuxExe = linuxExe dummyVersion;
381 exe = serverOn mainProjectOut dummyVersion;
382 server = args@{ hostName, adminEmail, routeHost, enableHttps, version }:
383 server (args // { exe = linuxExe version; });
384 obelisk = import (base' + "/.obelisk/impl") {};
386 haskellPackageSets = {
387 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