-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathshell.nix
More file actions
74 lines (67 loc) · 2.07 KB
/
shell.nix
File metadata and controls
74 lines (67 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
let
name = "ch-hs-imports";
# the pegged and customized nix package set
pkgs = import ./nix/pkgs {};
ghc = pkgs.haskellPackages.ghcWithHoogle
(
hs: with hs; [
# cabal dependencies
abstract-par
base
containers
deepseq
directory
dlist
filepath
megaparsec
monad-par
monad-par-extras
monoidal-containers
mtl
nonempty-containers
optparse-applicative
process
text
transformers
# extra useful dependencies
pretty-show
#rio
haskell-language-server
hie-bios
]
);
# the dependencies available in the shell
dependencies = with pkgs;[
# tools
ghc
cabal-install
];
# fake package explicitly adding dependencies to all the shell dependencies for adding GC roots
pathToDependencies = pkgs.runCommand "build" {
name = "${name}-pathToDependencies";
# add explicit dependencies to the path of the instantiated nixpkgs and also
# the pegged source of nixpkgs
paths = dependencies ++ [ pkgs.nixpkgs-src pkgs.path ];
} "echo $paths > $out";
# create the non buildable shell only environment
in
pkgs.mkShell {
name = "${name}-shell";
buildInputs = dependencies;
# perform some setup on entering the shell
shellHook = ''
# set NIX_PATH to point to the pegged nix packages
export NIX_PATH="nixpkgs=${pkgs.nixpkgs-src}";
# setup environment to find the correct GHC package set
NIX_GHC=$(type -p ghc)
if [ -n "$NIX_GHC" ]; then
eval $(grep export "$NIX_GHC")
fi
# add GC roots so that nix-collect-garbage does not delete our environment
mkdir -p ./.gcroots
# GC root to the actual shell file
${pkgs.nix}/bin/nix-instantiate ./shell.nix --indirect --add-root "./.gcroots/$(basename $out)-shell.drv" > /dev/null
# GC root to the fake package which keeps all our dependencies alive
${pkgs.nix}/bin/nix-store --add-root ./.gcroots/$(basename ${pathToDependencies}) --indirect --realise ${pathToDependencies} > /dev/null
'';
}