generated from srid/rib-sample
-
-
Notifications
You must be signed in to change notification settings - Fork 150
/
project.nix
139 lines (129 loc) · 4.44 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
130
131
132
133
134
135
136
137
138
139
let
nixpkgs = import ./nixpkgs.nix { };
in
{ pkgs ? nixpkgs
, pkgsForBins ? null
, static ? false
, neuronFlags ? [ ]
, withHoogle ? false
, ...
}:
let
inherit (pkgs.haskell.lib)
overrideCabal doJailbreak dontCheck justStaticExecutables appendConfigureFlags;
nix-filter = import ./dep/nix-filter;
inherit (nix-filter) inDirectory;
inherit (import ./dep/nix-thunk { })
thunkSource;
# Deal with non-Nix Haskellers allowing broken symlinks in an otherwise
# standalone Cabal package directory.
fuckSymlinkAbuse = p: pkgs.haskell.lib.overrideCabal p (drv: {
postUnpack = ''
echo fuck > $sourceRoot/README.md
echo fuck > $sourceRoot/LICENSE
'';
});
unfuckCoLog = p: pkgs.haskell.lib.overrideCabal p (drv: {
postUnpack = drv.postUnpack + ''
# Ditch executable stanzas that fail to build
# First 104 lines are enough to get the library.
head -n 104 $sourceRoot/co-log.cabal > fuck
mv fuck $sourceRoot/co-log.cabal
'';
});
sources = {
neuron = nix-filter {
root = ./.;
name = "neuron";
include = [
"neuron-search"
"neuron.cabal"
(inDirectory "exe")
(inDirectory "src")
(inDirectory "test")
];
};
reflex-dom-pandoc = thunkSource ./dep/reflex-dom-pandoc;
pandoc-link-context = thunkSource ./dep/pandoc-link-context;
directory-contents = thunkSource ./dep/directory-contents;
reflex-fsnotify = thunkSource ./dep/reflex-fsnotify;
};
searchBuilder = ''
mkdir -p $out/bin
cp $src/neuron-search $out/bin/neuron-search
chmod +x $out/bin/neuron-search
wrapProgram $out/bin/neuron-search --prefix 'PATH' ':' ${
with (if pkgsForBins != null then pkgsForBins else pkgs);
lib.makeBinPath [ fzf ripgrep gawk bat findutils envsubst ]
}
PATH=$PATH:$out/bin
'';
wrapSearchScript = drv: {
buildTools = [ pkgs.makeWrapper ];
preConfigure = searchBuilder;
};
haskellOverrides = self: super: with pkgs.haskell.lib; {
pandoc-link-context = self.callCabal2nix "pandoc-link-context" sources.pandoc-link-context { };
reflex-dom-pandoc =
dontHaddock (self.callCabal2nix "reflex-dom-pandoc" sources.reflex-dom-pandoc { });
reflex-fsnotify =
# Jailbreak to allow newer base
doJailbreak (self.callCabal2nix "reflex-fsnotify" sources.reflex-fsnotify { });
directory-contents = self.callCabal2nix "directory-contents" sources.directory-contents { };
# Test fails on pkgsMusl
time-compat = if static then (dontCheck super.time-compat) else super.time-compat;
neuron = appendConfigureFlags
((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-types
self.warp
self.HTTP
self.js-jquery
self.js-dgtable
self.js-flot
];
postInstall = ''
remove-references-to -t ${self.pandoc-types} $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
'';
}))
neuronFlags;
};
haskellPackages = pkgs.haskellPackages.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 = [
pkgs.nixpkgs-fmt
haskellPackages.ghcid
haskellPackages.cabal-install
haskellPackages.haskell-language-server
haskellPackages.hlint
haskellPackages.ormolu
nixShellSearchScript
];
};
}