on master help sign in
Expose Obelisk's overlays
commit0f502dc20c2b9493882ece9e8b831deebb05fb70 authorJohn Ericson <John.Ericson@Obsidian.Systems> dateWed 16 Jan 2019, 22:03 (8 years ago) parentba94237
6 files changed+134−112
default.nix+5−95 haskell-overlays/misc-deps.nix+23 haskell-overlays/obelisk.nix+23 haskell-overlays/tighten-ob-exes.nix+51 lib/executable-config/default.nix+22−17 nixpkgs-overlays/default.nix+10
default.nix+5−95
@@ -4,17 +4,6 @@
44, __useLegacyCompilers ? false
55}:
66let
7− cleanSource = builtins.filterSource (name: _: let baseName = builtins.baseNameOf name; in !(
8− builtins.match "^\\.ghc\\.environment.*" baseName != null ||
9− baseName == "cabal.project.local"
10− ));
11−
12− commandRuntimeDeps = pkgs: with pkgs; [
13− coreutils
14− git
15− nix-prefetch-git
16− openssh
17− ];
187
198 getReflexPlatform = getReflexPlatform' __useLegacyCompilers;
209 getReflexPlatform' = __useLegacyCompilers: sys: import ./dep/reflex-platform {
@@ -23,92 +12,13 @@ let
2312 enableLibraryProfiling = profiling;
2413
2514 nixpkgsOverlays = [
26− (self: super: {
27− obeliskExecutableConfig = import ./lib/executable-config { nixpkgs = pkgs; filterGitSource = cleanSource; };
28− })
15+ (import ./nixpkgs-overlays)
2916 ];
3017
3118 haskellOverlays = [
32−
33− # Fix misc upstream packages
34− (self: super: let
35− pkgs = self.callPackage ({ pkgs }: pkgs) {};
36− in {
37− hnix = pkgs.haskell.lib.dontCheck (self.callCabal2nix "hnix" (pkgs.fetchFromGitHub {
38− owner = "haskell-nix";
39− repo = "hnix";
40− rev = "42afdc21da5d9e076eab57eaa42bfdde938192b8";
41− sha256 = "0psw384dx9bw2dp93xrzw8rd9amvcwgzn64jzzwby7sfspj6k349";
42− }) {});
43− # Need 8.0.2 build support
44− # PR: https://github.com/dmwit/universe/pull/33
45− universe-template = self.callCabal2nix "universe-template" (pkgs.fetchFromGitHub {
46− owner = "obsidiansystems";
47− repo = "universe";
48− rev = "6a71119bfa5db2b9990a2491c941469ff8ef5d13";
49− sha256 = "0z8smyainnlzcglv3dlx6x1n9j6d2jv48aa8f2421iayfkxg3js5";
50− } + /template) {};
51− })
52−
53− # Add obelisk packages
54− (self: super: let
55− pkgs = self.callPackage ({ pkgs }: pkgs) {};
56− in {
57− obelisk-executable-config = pkgs.obeliskExecutableConfig.haskellPackage self;
58− obelisk-executable-config-inject = pkgs.obeliskExecutableConfig.platforms.web.inject self;
59−
60− obelisk-asset-manifest = self.callCabal2nix "obelisk-asset-manifest" ./lib/asset/manifest {};
61− obelisk-asset-serve-snap = self.callCabal2nix "obelisk-asset-serve-snap" ./lib/asset/serve-snap {};
62− obelisk-backend = self.callCabal2nix "obelisk-backend" (cleanSource ./lib/backend) {};
63− obelisk-cliapp = self.callCabal2nix "obelisk-cliapp" (cleanSource ./lib/cliapp) {};
64− obelisk-command = self.callCabal2nix "obelisk-command" (cleanSource ./lib/command) {};
65− obelisk-frontend = self.callCabal2nix "obelisk-frontend" (cleanSource ./lib/frontend) {};
66− obelisk-run = self.callCabal2nix "obelisk-run" (cleanSource ./lib/run) {};
67− obelisk-route = self.callCabal2nix "obelisk-route" (cleanSource ./lib/route) {};
68− obelisk-selftest = self.callCabal2nix "obelisk-selftest" (cleanSource ./lib/selftest) {};
69− obelisk-snap-extras = self.callCabal2nix "obelisk-snap-extras" (cleanSource ./lib/snap-extras) {};
70− })
71−
72− (self: super: let
73− pkgs = self.callPackage ({ pkgs }: pkgs) {};
74− haskellLib = pkgs.haskell.lib;
75− #TODO: Upstream
76− # Modify a Haskell package to add completion scripts for the given
77− # executable produced by it. These completion scripts will be picked up
78− # automatically if the resulting derivation is installed, e.g. by
79− # `nix-env -i`.
80− addOptparseApplicativeCompletionScripts = exeName: pkg: haskellLib.overrideCabal pkg (drv: {
81− postInstall = (drv.postInstall or "") + ''
82− BASH_COMP_DIR="$out/share/bash-completion/completions"
83− mkdir -p "$BASH_COMP_DIR"
84− "$out/bin/${exeName}" --bash-completion-script "$out/bin/${exeName}" >"$BASH_COMP_DIR/ob"
85−
86− ZSH_COMP_DIR="$out/share/zsh/vendor-completions"
87− mkdir -p "$ZSH_COMP_DIR"
88− "$out/bin/${exeName}" --zsh-completion-script "$out/bin/${exeName}" >"$ZSH_COMP_DIR/_ob"
89−
90− FISH_COMP_DIR="$out/share/fish/vendor_completions.d"
91− mkdir -p "$FISH_COMP_DIR"
92− "$out/bin/${exeName}" --fish-completion-script "$out/bin/${exeName}" >"$FISH_COMP_DIR/ob.fish"
93− '';
94− });
95− in {
96− # Dynamic linking with split objects dramatically increases startup time (about
97− # 0.5 seconds on a decent machine with SSD), so we do `justStaticExecutables`.
98− obelisk-command = haskellLib.overrideCabal
99− (addOptparseApplicativeCompletionScripts "ob"
100− (haskellLib.justStaticExecutables super.obelisk-command))
101− (drv: {
102− buildTools = (drv.buildTools or []) ++ [ pkgs.buildPackages.makeWrapper ];
103− postFixup = ''
104− ${drv.postFixup or ""}
105− # Make `ob` reference its runtime dependencies.
106− wrapProgram "$out"/bin/ob --prefix PATH : ${pkgs.lib.makeBinPath (commandRuntimeDeps pkgs)}
107− '';
108− });
109− obelisk-selftest = haskellLib.justStaticExecutables super.obelisk-selftest;
110− })
111−
19+ (import ./haskell-overlays/misc-deps.nix)
20+ (import ./haskell-overlays/obelisk.nix)
21+ (import ./haskell-overlays/tighten-ob-exes.nix)
11222 ];
11323 };
11424
@@ -135,7 +45,7 @@ in rec {
13545 obelisk = ghcObelisk;
13646 obeliskEnvs = ghcObeliskEnvs;
13747 command = ghcObelisk.obelisk-command;
138− shell = pinBuildInputs "obelisk-shell" ([command] ++ commandRuntimeDeps pkgs) [];
48+ shell = pinBuildInputs "obelisk-shell" ([command] ++ command.commandRuntimeDeps) [];
13949
14050 selftest = pkgs.writeScript "selftest" ''
14151 #!/usr/bin/env bash
haskell-overlays/misc-deps.nixnew file+23
@@ -0,0 +1,23 @@
1+# Fix misc upstream packages
2+self: super:
3+
4+let
5+ pkgs = self.callPackage ({ pkgs }: pkgs) {};
6+in
7+
8+{
9+ hnix = pkgs.haskell.lib.dontCheck (self.callCabal2nix "hnix" (pkgs.fetchFromGitHub {
10+ owner = "haskell-nix";
11+ repo = "hnix";
12+ rev = "42afdc21da5d9e076eab57eaa42bfdde938192b8";
13+ sha256 = "0psw384dx9bw2dp93xrzw8rd9amvcwgzn64jzzwby7sfspj6k349";
14+ }) {});
15+ # Need 8.0.2 build support
16+ # PR: https://github.com/dmwit/universe/pull/33
17+ universe-template = self.callCabal2nix "universe-template" (pkgs.fetchFromGitHub {
18+ owner = "obsidiansystems";
19+ repo = "universe";
20+ rev = "6a71119bfa5db2b9990a2491c941469ff8ef5d13";
21+ sha256 = "0z8smyainnlzcglv3dlx6x1n9j6d2jv48aa8f2421iayfkxg3js5";
22+ } + /template) {};
23+}
haskell-overlays/obelisk.nixnew file+23
@@ -0,0 +1,23 @@
1+# Add obelisk packages
2+self: super:
3+
4+let
5+ pkgs = self.callPackage ({ pkgs }: pkgs) {};
6+ inherit (pkgs) cleanHaskellSource;
7+in
8+
9+{
10+ obelisk-executable-config = pkgs.obeliskExecutableConfig.haskellPackage self;
11+ obelisk-executable-config-inject = pkgs.obeliskExecutableConfig.platforms.web.inject self;
12+
13+ obelisk-asset-manifest = self.callCabal2nix "obelisk-asset-manifest" ../lib/asset/manifest {};
14+ obelisk-asset-serve-snap = self.callCabal2nix "obelisk-asset-serve-snap" ../lib/asset/serve-snap {};
15+ obelisk-backend = self.callCabal2nix "obelisk-backend" (cleanHaskellSource ../lib/backend) {};
16+ obelisk-cliapp = self.callCabal2nix "obelisk-cliapp" (cleanHaskellSource ../lib/cliapp) {};
17+ obelisk-command = self.callCabal2nix "obelisk-command" (cleanHaskellSource ../lib/command) {};
18+ obelisk-frontend = self.callCabal2nix "obelisk-frontend" (cleanHaskellSource ../lib/frontend) {};
19+ obelisk-run = self.callCabal2nix "obelisk-run" (cleanHaskellSource ../lib/run) {};
20+ obelisk-route = self.callCabal2nix "obelisk-route" (cleanHaskellSource ../lib/route) {};
21+ obelisk-selftest = self.callCabal2nix "obelisk-selftest" (cleanHaskellSource ../lib/selftest) {};
22+ obelisk-snap-extras = self.callCabal2nix "obelisk-snap-extras" (cleanHaskellSource ../lib/snap-extras) {};
23+}
haskell-overlays/tighten-ob-exes.nixnew file+51
@@ -0,0 +1,51 @@
1+self: super:
2+
3+let
4+ pkgs = self.callPackage ({ pkgs }: pkgs) {};
5+ haskellLib = pkgs.haskell.lib;
6+ #TODO: Upstream
7+ # Modify a Haskell package to add completion scripts for the given
8+ # executable produced by it. These completion scripts will be picked up
9+ # automatically if the resulting derivation is installed, e.g. by
10+ # `nix-env -i`.
11+ addOptparseApplicativeCompletionScripts = exeName: pkg: haskellLib.overrideCabal pkg (drv: {
12+ postInstall = (drv.postInstall or "") + ''
13+ BASH_COMP_DIR="$out/share/bash-completion/completions"
14+ mkdir -p "$BASH_COMP_DIR"
15+ "$out/bin/${exeName}" --bash-completion-script "$out/bin/${exeName}" >"$BASH_COMP_DIR/ob"
16+
17+ ZSH_COMP_DIR="$out/share/zsh/vendor-completions"
18+ mkdir -p "$ZSH_COMP_DIR"
19+ "$out/bin/${exeName}" --zsh-completion-script "$out/bin/${exeName}" >"$ZSH_COMP_DIR/_ob"
20+
21+ FISH_COMP_DIR="$out/share/fish/vendor_completions.d"
22+ mkdir -p "$FISH_COMP_DIR"
23+ "$out/bin/${exeName}" --fish-completion-script "$out/bin/${exeName}" >"$FISH_COMP_DIR/ob.fish"
24+ '';
25+ });
26+ commandRuntimeDeps = with pkgs; [
27+ coreutils
28+ git
29+ nix-prefetch-git
30+ openssh
31+ ];
32+in
33+
34+{
35+ # Dynamic linking with split objects dramatically increases startup time (about
36+ # 0.5 seconds on a decent machine with SSD), so we do `justStaticExecutables`.
37+ obelisk-command = haskellLib.overrideCabal
38+ (addOptparseApplicativeCompletionScripts "ob"
39+ (haskellLib.justStaticExecutables super.obelisk-command))
40+ (drv: {
41+ buildTools = (drv.buildTools or []) ++ [ pkgs.buildPackages.makeWrapper ];
42+ postFixup = ''
43+ ${drv.postFixup or ""}
44+ # Make `ob` reference its runtime dependencies.
45+ wrapProgram "$out"/bin/ob --prefix PATH : ${pkgs.lib.makeBinPath commandRuntimeDeps}
46+ '';
47+ passthru = { inherit commandRuntimeDeps; };
48+ });
49+
50+ obelisk-selftest = haskellLib.justStaticExecutables super.obelisk-selftest;
51+}
lib/executable-config/default.nix+22−17
@@ -2,23 +2,28 @@
22# configuration information into a canonical location. It also provides a haskell
33# package that can be used to retrieve the injected configuration on each supported
44# platform.
5−{ nixpkgs
6−, filterGitSource # TODO define this in obelisk
5+{ lib
6+, runCommand
7+, cleanHaskellSource
78}:
8−let injectConfig = config: assets: nixpkgs.runCommand "inject-config" {} (''
9− set -x
10− mkdir -p $out
11− cp --no-preserve=mode -Lr "${assets}" $out/static
12− chmod +w "$out"
13− '' + nixpkgs.lib.optionalString (!(builtins.isNull config)) ''
14− if ! mkdir $out/config; then
15− 2>&1 echo config directory already exists or could not be created
16− exit 1
17− fi
18− cp -a "${config}"/* "$out/config"
19− '');
20−in with nixpkgs.haskell.lib; {
21− haskellPackage = self: self.callPackage (filterGitSource ./lookup) {};
9+
10+let
11+ injectConfig = config: assets: runCommand "inject-config" {} (''
12+ set -x
13+ mkdir -p $out
14+ cp --no-preserve=mode -Lr "${assets}" $out/static
15+ chmod +w "$out"
16+ '' + lib.optionalString (!(builtins.isNull config)) ''
17+ if ! mkdir $out/config; then
18+ 2>&1 echo config directory already exists or could not be created
19+ exit 1
20+ fi
21+ cp -a "${config}"/* "$out/config"
22+ '');
23+in
24+
25+{
26+ haskellPackage = self: self.callPackage (cleanHaskellSource ./lookup) {};
2227 platforms = {
2328 android = {
2429 # Inject the given config directory into an android assets folder
@@ -29,7 +34,7 @@ in with nixpkgs.haskell.lib; {
2934 inject = injectConfig;
3035 };
3136 web = {
32− inject = self: self.callCabal2nix "obelisk-executable-config-inject" (filterGitSource ./inject) {};
37+ inject = self: self.callCabal2nix "obelisk-executable-config-inject" (cleanHaskellSource ./inject) {};
3338 };
3439 };
3540}
nixpkgs-overlays/default.nixnew file+10
@@ -0,0 +1,10 @@
1+self: super:
2+
3+{
4+ cleanHaskellSource = builtins.filterSource (name: _: let baseName = builtins.baseNameOf name; in !(
5+ builtins.match "^\\.ghc\\.environment.*" baseName != null ||
6+ baseName == "cabal.project.local"
7+ ));
8+
9+ obeliskExecutableConfig = self.callPackage ../lib/executable-config { };
10+}