forked from srid/neuron
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject.nix
More file actions
120 lines (107 loc) · 4.09 KB
/
project.nix
File metadata and controls
120 lines (107 loc) · 4.09 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
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
let
gitignoreSrc = builtins.fetchTarball {
url = "https://github.com/hercules-ci/gitignore/archive/c4662e6.tar.gz";
sha256 = "1npnx0h6bd0d7ql93ka7azhj40zgjp815fw2r6smg8ch9p7mzdlx";
};
sources = import nix/sources.nix {};
nixpkgs = import sources.nixpkgs {};
in {
pkgs ? nixpkgs,
pkgsForBins ? null,
neuronFlags ? [],
disableHsLuaTests ? false,
withHoogle ? false,
...
}:
let
inherit (pkgs.haskell.lib)
overrideCabal doJailbreak dontCheck justStaticExecutables appendConfigureFlags;
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;
# TODO: Switch to using `niv` exclusively.
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 (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: {
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 { });
# This version is not the default in nixpkgs, yet.
skylighting = super.skylighting_0_10_0_2;
skylighting-core = super.skylighting-core_0_10_0_2;
# Jailbreak pandoc to work with newer skylighting
pandoc = doJailbreak (dontCheck super.pandoc);
# Test fails on pkgsMusl
# https://github.com/hslua/hslua/issues/67
hslua = if disableHsLuaTests then (dontCheck super.hslua) else super.hslua;
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
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
'';
})) 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 = [
haskellPackages.ghcid
haskellPackages.cabal-install
haskellPackages.haskell-language-server
haskellPackages.hlint
haskellPackages.ormolu
nixShellSearchScript
];
};
}