Skip to content

Commit 413d5c9

Browse files
eamsdenangerman
authored andcommitted
Add shellHook option to components (and packages and plans) (#117)
1 parent ae457c1 commit 413d5c9

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

builder/comp-builder.nix

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
, preCheck ? null, postCheck ? null
1919
, preInstall ? null, postInstall ? null
2020
, preHaddock ? null, postHaddock ? null
21-
, shellHook ? null
21+
, shellHook ? ""
2222

2323
, doCheck ? component.doCheck || haskellLib.isTest componentId
2424
, doCrossCheck ? component.doCrossCheck || false
@@ -187,6 +187,11 @@ let
187187
inherit configFiles;
188188
};
189189

190+
# In order to let shell hooks make package-specific things like Hoogle databases
191+
shellHookApplied = if builtins.isString shellHook then shellHook else
192+
if builtins.isFunction shellHook then shellHook { inherit package shellWrappers; }
193+
else abort "shellHook should be a string or a function";
194+
190195
# the target dir for haddock documentation
191196
docdir = docoutput: docoutput + "/share/doc/" + componentId.cname;
192197

@@ -332,7 +337,7 @@ stdenv.mkDerivation ({
332337

333338
shellHook = ''
334339
export PATH="${shellWrappers}/bin:$PATH"
335-
${toString shellHook}
340+
${shellHookApplied}
336341
'';
337342
}
338343
# patches can (if they like) depend on the version and revision of the package.

modules/component-driver.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ let
55
inherit haskellLib;
66
ghc = config.ghc.package;
77
buildGHC = buildModules.config.ghc.package;
8-
inherit (config) nonReinstallablePkgs hsPkgs;
8+
inherit (config) nonReinstallablePkgs hsPkgs shellHook;
99
inherit ghcForComponent;
1010
};
1111

modules/plan.nix

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ let
7373
type = bool;
7474
default = (def.doHaddock or true);
7575
};
76+
shellHook = mkOption {
77+
description = "Hook to run when entering a shell";
78+
type = unspecified; # Can be either a string or a function
79+
default = (def.shellHook or "");
80+
};
7681
};
7782
packageOptions = def: componentOptions def // {
7883
preUnpack = mkOption {
@@ -123,10 +128,6 @@ let
123128
type = nullOr string;
124129
default = (def.postHaddock or null);
125130
};
126-
shellHook = mkOption {
127-
type = nullOr string;
128-
default = (def.shellHook or null);
129-
};
130131
};
131132

132133

0 commit comments

Comments
 (0)