-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathflake.nix
More file actions
178 lines (158 loc) · 6.12 KB
/
Copy pathflake.nix
File metadata and controls
178 lines (158 loc) · 6.12 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
{
description = "Easy dependency management for Nix projects.";
inputs.nixpkgs.url = "github:NixOS/nixpkgs?ref=nixpkgs-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages."${system}";
haskellPackages = pkgs.haskellPackages.override {
overrides = self: super: {
# 0.19+ is required for niv to build and at the time of writing nixpkgs defaults to 0.18
optparse-applicative = self.optparse-applicative_0_19_0_0;
};
};
sourceByRegex = name: src: regexes:
builtins.path {
filter = path: type:
let
relPath = pkgs.lib.removePrefix (toString src + "/") (toString path);
accept = pkgs.lib.any (re: builtins.match re relPath != null) regexes;
in
accept;
inherit name;
path = src;
};
niv-source = sourceByRegex "niv" ./. [
"^niv.cabal$"
"^README.md$" # the README is not required for the build but is required for the sdist
"^LICENSE$"
"^app$"
"^app.*.hs$"
"^src$"
"^src/Data$"
"^src/Data/Aeson$"
"^src/Data/HashMap$"
"^src/Data/HashMap/Strict$"
"^src/Data/Text$"
"^src/Niv$"
"^src/Niv/Git$"
"^src/Niv/GitHub$"
"^src/Niv/Local$"
"^src/Niv/Sources$"
"^src/Niv/Update$"
"^src.*.hs$"
"^nix$"
"^nix.sources.nix$"
];
niv = haskellPackages.callPackage
(
{ aeson
, aeson-pretty
, ansi-terminal
, base
, bytestring
, directory
, file-embed
, filepath
, hashable
, http-conduit
, mtl
, optparse-applicative
, process
, profunctors
, pureMD5
, string-qq
, tasty
, tasty-hunit
, text
, unliftio
, unordered-containers
, mkDerivation
}:
mkDerivation {
pname = "niv";
version = "0.2.22";
src = niv-source;
isLibrary = true;
isExecutable = true;
libraryHaskellDepends = [
aeson
aeson-pretty
ansi-terminal
base
bytestring
directory
file-embed
filepath
hashable
http-conduit
mtl
optparse-applicative
process
profunctors
pureMD5
string-qq
tasty
tasty-hunit
text
unliftio
unordered-containers
];
executableHaskellDepends = [ ];
testHaskellDepends = [ ];
description = "Easy dependency management for Nix projects";
homepage = "https://github.com/nmattia/niv#readme";
license = pkgs.lib.licenses.mit;
}
)
{ };
# cabal-friendly sdist
niv-sdist = pkgs.haskell.lib.sdistTarball niv;
# golden tests for TUI. The idle-time-limit is taken to be slightly shorter than the pauses
# in the debug output, so each pause creates a new frame.
golden = pkgs.runCommand "golden" { nativeBuildInputs = [ niv pkgs.asciinema pkgs.asciinema-agg ]; }
''
mkdir -p $out
niv --help # some systems (macOS) are a bit slow to run a new binary
# pairs of job name & window dimensions
goldens=("job-hello-world,16x5" "job-multi,24x6" "job-note-multiline,32x8" "job-every-admonition,24x10")
font_dir=${pkgs.nerd-fonts.jetbrains-mono}/share/fonts/truetype/NerdFonts/JetBrainsMono
font_family="JetBrainsMono Nerd Font"
for cfg in "''${goldens[@]}"; do
IFS=',' read -r golden dims <<<"$cfg"
asciinema record --window-size "$dims" --command "niv debug $golden" "$golden.cast"
agg --font-dir "$font_dir" --text-font-family "$font_family" --idle-time-limit 0.5 "$golden.cast" "$out/$golden.gif"
done
'';
readme = pkgs.runCommand "README.md" { nativeBuildInputs = [ niv pkgs.moreutils ]; }
''
mkdir -p $out
readme="$out/README.md"
cat ${./README.tpl.md} > "$readme"
sed "/replace_niv_help/r"<(niv --help) $readme | sponge $readme
sed "/replace_niv_help/d" $readme | sponge $readme
sed "/replace_niv_add_help/r"<(niv add --help) $readme | sponge $readme
sed "/replace_niv_add_help/d" $readme | sponge $readme
sed "/replace_niv_update_help/r"<(niv update --help) $readme| sponge $readme
sed "/replace_niv_update_help/d" $readme | sponge $readme
sed "/replace_niv_rename_help/r"<(niv rename --help) $readme| sponge $readme
sed "/replace_niv_rename_help/d" $readme | sponge $readme
sed "/replace_niv_modify_help/r"<(niv modify --help) $readme | sponge $readme
sed "/replace_niv_modify_help/d" $readme | sponge $readme
sed "/replace_niv_drop_help/r"<(niv drop --help) $readme | sponge $readme
sed "/replace_niv_drop_help/d" $readme | sponge $readme
sed "/replace_niv_init_help/r"<(niv init --help) $readme | sponge $readme
sed "/replace_niv_init_help/d" $readme | sponge $readme
sed "/replace_niv_show_help/r"<(niv show --help) $readme | sponge $readme
sed "/replace_niv_show_help/d" $readme | sponge $readme
'';
in
{
packages = {
inherit niv niv-sdist readme golden;
};
checks = import ./tests { inherit system pkgs niv; };
}
);
}