From 413d5c9dbdb6bf9090bcc8b88198a75e7c1181d0 Mon Sep 17 00:00:00 2001 From: Edward Amsden Date: Thu, 16 May 2019 22:55:04 -0400 Subject: [PATCH] Add shellHook option to components (and packages and plans) (#117) --- builder/comp-builder.nix | 9 +++++++-- modules/component-driver.nix | 2 +- modules/plan.nix | 9 +++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/builder/comp-builder.nix b/builder/comp-builder.nix index 82410ee9..eb6228a9 100644 --- a/builder/comp-builder.nix +++ b/builder/comp-builder.nix @@ -18,7 +18,7 @@ , preCheck ? null, postCheck ? null , preInstall ? null, postInstall ? null , preHaddock ? null, postHaddock ? null -, shellHook ? null +, shellHook ? "" , doCheck ? component.doCheck || haskellLib.isTest componentId , doCrossCheck ? component.doCrossCheck || false @@ -187,6 +187,11 @@ let inherit configFiles; }; + # In order to let shell hooks make package-specific things like Hoogle databases + shellHookApplied = if builtins.isString shellHook then shellHook else + if builtins.isFunction shellHook then shellHook { inherit package shellWrappers; } + else abort "shellHook should be a string or a function"; + # the target dir for haddock documentation docdir = docoutput: docoutput + "/share/doc/" + componentId.cname; @@ -332,7 +337,7 @@ stdenv.mkDerivation ({ shellHook = '' export PATH="${shellWrappers}/bin:$PATH" - ${toString shellHook} + ${shellHookApplied} ''; } # patches can (if they like) depend on the version and revision of the package. diff --git a/modules/component-driver.nix b/modules/component-driver.nix index 5eee813d..fd399d53 100644 --- a/modules/component-driver.nix +++ b/modules/component-driver.nix @@ -5,7 +5,7 @@ let inherit haskellLib; ghc = config.ghc.package; buildGHC = buildModules.config.ghc.package; - inherit (config) nonReinstallablePkgs hsPkgs; + inherit (config) nonReinstallablePkgs hsPkgs shellHook; inherit ghcForComponent; }; diff --git a/modules/plan.nix b/modules/plan.nix index 341cd1cd..426e5fd1 100644 --- a/modules/plan.nix +++ b/modules/plan.nix @@ -73,6 +73,11 @@ let type = bool; default = (def.doHaddock or true); }; + shellHook = mkOption { + description = "Hook to run when entering a shell"; + type = unspecified; # Can be either a string or a function + default = (def.shellHook or ""); + }; }; packageOptions = def: componentOptions def // { preUnpack = mkOption { @@ -123,10 +128,6 @@ let type = nullOr string; default = (def.postHaddock or null); }; - shellHook = mkOption { - type = nullOr string; - default = (def.shellHook or null); - }; };