Merge pull request #111 from srid/shell-extra-libraries

Add `devShell.extraLibraries` option
This commit is contained in:
Sridhar Ratnakumar 2023-03-09 18:33:33 -05:00 committed by GitHub
commit da1d8bbda4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 1 deletions

View File

@ -8,6 +8,7 @@
- #49 & #91: The `packages` option now autodiscovers the top-level `.cabal` file (in addition to looking inside sub-directories) as its default value.
- #69: The default flake template creates `flake.nix` only, while the `#example` one creates the full Haskell project template.
- #92: Add `devShell.mkShellArgs` to pass custom arguments to `mkShell`
- #111: Add `devShell.extraLibraries` to add custom Haskell libraries to the devshell.
- #100: `source-overrides` option now supports specifying Hackage versions.
- API changes
- #37: Group `buildTools` (renamed to `tools`), `hlsCheck` and `hlintCheck` under the `devShell` submodule option; and allow disabling them all using `devShell.enable = false;` (useful if you want haskell-flake to produce just the package outputs).

View File

@ -63,6 +63,20 @@ in
Build tools useful for Haskell development are included by default.
'';
};
extraLibraries = mkOption {
type = functionTo (types.attrsOf (types.nullOr types.package));
description = ''
Extra Haskell libraries available in the shell's environment.
These can be used in the shell's `runghc` and `ghci` for instance.
The argument is the Haskell package set.
The return type is an attribute set for overridability and syntax, as only the values are used.
'';
default = hp: { };
defaultText = lib.literalExpression "hp: { }";
example = lib.literalExpression "hp: { inherit (hp) releaser; }";
};
hlsCheck = mkOption {
default = { };
type = hlsCheckSubmodule;

View File

@ -83,6 +83,12 @@ in
(name: p."${name}")
(lib.attrNames config.packages);
withHoogle = true;
extraDependencies = p:
let o = mkShellArgs.extraDependencies or (_: { }) p;
in o // {
libraryHaskellDepends = o.libraryHaskellDepends or []
++ builtins.attrValues (config.devShell.extraLibraries p);
};
});
in
{

View File

@ -51,6 +51,9 @@
# Adding a tool should make it available in devshell.
fzf = pkgs.fzf;
};
extraLibraries = hp: {
inherit (hp) tomland;
};
mkShellArgs.shellHook = ''
echo "Hello from devshell!"
export FOO=bar

5
test/script Normal file
View File

@ -0,0 +1,5 @@
import Toml.Type.Value (Value(Bool))
main :: IO ()
main = do
putStrLn ("I depend on the `tomland` package. Here's a TOML-flavored boolean: " <> show (Bool True))

View File

@ -23,4 +23,7 @@ if [[ "$FOO" == "bar" ]]; then
else
echo "FOO is not bar"
exit 2
fi
fi
# extraLibraries works
runghc ./script | grep -F 'TOML-flavored boolean: Bool True'