forked from srid/neuron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.nix
129 lines (116 loc) · 4.32 KB
/
project.nix
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
let
nixpkgsSrc = builtins.fetchTarball {
url = "https://github.com/nixos/nixpkgs/archive/729e7295cf7b.tar.gz";
sha256 = "0mxhi0lc11aa3r7i7din1q2rjg5c4amq3alcr8ga2fcb64vn2zd3";
};
gitignoreSrc = builtins.fetchTarball {
url = "https://github.com/hercules-ci/gitignore/archive/c4662e6.tar.gz";
sha256 = "1npnx0h6bd0d7ql93ka7azhj40zgjp815fw2r6smg8ch9p7mzdlx";
};
in {
system ? builtins.currentSystem,
pkgs ? import nixpkgsSrc { inherit system; },
# Cabal project name
name ? "neuron",
compiler ? pkgs.haskellPackages,
withHoogle ? false,
...
}:
let
inherit (pkgs.haskell.lib)
overrideCabal markUnbroken doJailbreak appendPatch justStaticExecutables;
inherit (import (gitignoreSrc) { inherit (pkgs) lib; }) gitignoreSource;
thunkOrPath = dep:
let p = ./dep + "/${dep}/thunk.nix";
in if builtins.pathExists p then import p else (./dep + "/${dep}");
sources = {
neuron = gitignoreSource ./neuron;
rib = thunkOrPath "rib";
reflex-dom-pandoc = thunkOrPath "reflex-dom-pandoc";
};
searchBuilder = ''
mkdir -p $out/bin
cp $src/src-bash/neuron-search $out/bin/neuron-search
chmod +x $out/bin/neuron-search
wrapProgram $out/bin/neuron-search --prefix 'PATH' ':' ${
with pkgs;
lib.makeBinPath [ fzf ripgrep gawk bat findutils envsubst ]
}
PATH=$PATH:$out/bin
'';
wrapSearchScript = drv: {
buildTools = [ pkgs.makeWrapper ];
preConfigure = searchBuilder;
};
haskellOverrides = self: super: {
rib-core = self.callCabal2nix "rib-core" (sources.rib + "/rib-core") { };
reflex-dom-pandoc =
pkgs.haskell.lib.dontHaddock (self.callCabal2nix "reflex-dom-pandoc" sources.reflex-dom-pandoc { });
# Override pandoc-types and dependencies because stack-lts versions are to old
pandoc-types = self.pandoc-types_1_21;
skylighting = self.callHackageDirect {
pkg = "skylighting";
ver = "0.9";
sha256 = "1zk8flzfafnmpb7wy7sf3q0biaqfh7svxz2da7wlc3am3n9fpxbr";
} {};
skylighting-core = self.callHackageDirect {
pkg = "skylighting-core";
ver = "0.9";
sha256 = "1fb3j5kmfdycxwr7vjdg1hrdz6s61ckp489qj3899klk18pcmpnh";
} {};
# Jailbreak to allow newer skylighting. Next version of pandoc shouldn't
# require this.
pandoc = doJailbreak super.pandoc_2_10_1;
neuron = (justStaticExecutables
(overrideCabal (self.callCabal2nix "neuron" sources.neuron { })
wrapSearchScript)).overrideDerivation (drv: {
# Avoid transitive runtime dependency on the whole GHC distribution due to
# Cabal's `Path_*` module thingy. For details, see:
# https://github.com/NixOS/nixpkgs/blob/46405e7952c4b41ca0ba9c670fe9a84e8a5b3554/pkgs/development/tools/pandoc/default.nix#L13-L28
#
# In order to keep this list up to date, use nix-store and why-depends as
# explained here: https://www.srid.ca/04b88e01.html
disallowedReferences = [
self.pandoc
self.pandoc-types
self.shake
self.warp
self.HTTP
self.js-jquery
self.js-dgtable
self.js-flot
];
postInstall = ''
remove-references-to -t ${self.pandoc} $out/bin/neuron
remove-references-to -t ${self.pandoc-types} $out/bin/neuron
remove-references-to -t ${self.shake} $out/bin/neuron
remove-references-to -t ${self.warp} $out/bin/neuron
remove-references-to -t ${self.HTTP} $out/bin/neuron
remove-references-to -t ${self.js-jquery} $out/bin/neuron
remove-references-to -t ${self.js-dgtable} $out/bin/neuron
remove-references-to -t ${self.js-flot} $out/bin/neuron
'';
});
};
haskellPackages = compiler.override { overrides = haskellOverrides; };
nixShellSearchScript = pkgs.stdenv.mkDerivation {
name = "neuron-search";
src = sources.neuron;
buildInputs = [ pkgs.makeWrapper ];
buildCommand = searchBuilder;
};
in {
neuron = haskellPackages.neuron;
shell = haskellPackages.shellFor {
inherit withHoogle;
packages = p: [ p.neuron ];
buildInputs = [
haskellPackages.ghcid
haskellPackages.cabal-install
haskellPackages.haskell-language-server
haskellPackages.hlint
haskellPackages.ormolu
nixShellSearchScript
];
};
}