-
Notifications
You must be signed in to change notification settings - Fork 126
/
default.nix
272 lines (241 loc) · 8.24 KB
/
default.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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
{ checkMaterialization ? false }:
let
sources = import nix/sources.nix;
# Fetch the latest haskell.nix and import its default.nix
haskellNix = import sources.haskellNix {};
# Peek at https://github.com/input-output-hk/haskell.nix/blob/master/ci.nix
# for supported nixpkgs and ghc versions
# or https://github.com/input-output-hk/haskell.nix/blob/master/docs/reference/supported-ghc-versions.md
nixpkgsSrc = haskellNix.sources.nixpkgs-unstable;
nixpkgsArgs = haskellNix.nixpkgsArgs;
pkgs = import nixpkgsSrc nixpkgsArgs;
pkgs-osx = import nixpkgsSrc (nixpkgsArgs // { system = "x86_64-darwin"; });
# a nicer filterSource
sourceByRegex =
src: regexes: builtins.filterSource (path: type:
let relPath = pkgs.lib.removePrefix (toString src + "/") (toString path); in
let match = builtins.match (pkgs.lib.strings.concatStringsSep "|" regexes); in
( type == "directory" && match (relPath + "/") != null
|| match relPath != null)) src;
tttool-project = pkgs: sha256:
pkgs.haskell-nix.cabalProject {
src = sourceByRegex ./. [
"cabal.project"
"src/"
"src/.*/"
"src/.*.hs"
".*.cabal"
"LICENSE"
];
# Pinning the input to the constraint solver
compiler-nix-name = "ghc928";
index-state = "2023-07-14T00:00:00Z";
plan-sha256 = sha256;
inherit checkMaterialization;
modules = [{
# smaller files
packages.tttool.dontStrip = false;
}] ++
pkgs.lib.optional pkgs.hostPlatform.isMusl {
packages.tttool.configureFlags = [ "--ghc-option=-static" ];
# terminfo is disabled on musl by haskell.nix, but still the flag
# is set in the package plan, so override this
packages.haskeline.flags.terminfo = false;
};
};
tttool-exe = pkgs: sha256:
(tttool-project pkgs sha256).tttool.components.exes.tttool;
tttool-shell = pkgs: sha256:
(tttool-project pkgs sha256).shellFor {
buildInputs = [ pkgs.ghcid ];
};
osx-bundler = pkgs: tttool:
pkgs.stdenv.mkDerivation {
name = "tttool-bundle";
buildInputs = [ pkgs.macdylibbundler ];
builder = pkgs.writeScript "tttool-osx-bundler.sh" ''
source ${pkgs.stdenv}/setup
mkdir -p $out/bin/osx
cp ${tttool}/bin/tttool $out/bin/osx
chmod u+w $out/bin/osx/tttool
dylibbundler \
-b \
-x $out/bin/osx/tttool \
-d $out/bin/osx \
-p '@executable_path' \
-i /usr/lib/system \
-i ${pkgs.darwin.Libsystem}/lib
'';
};
in rec {
shell = tttool-shell pkgs
"12fm0i61zhah9yrkf0lmpybrcl0q91gb3krib12zz6qg5fx0lbw7";
linux-exe = tttool-exe pkgs
"12fm0i61zhah9yrkf0lmpybrcl0q91gb3krib12zz6qg5fx0lbw7";
windows-exe = tttool-exe pkgs.pkgsCross.mingwW64
"1x16mjjx4wnzksmpi4jg6ykvfvdshrhp58gciy9lfslavy9clf3a";
static-exe = tttool-exe pkgs.pkgsCross.musl64
"12fm0i61zhah9yrkf0lmpybrcl0q91gb3krib12zz6qg5fx0lbw7";
osx-exe = tttool-exe pkgs-osx
"12fm0i61zhah9yrkf0lmpybrcl0q91gb3krib12zz6qg5fx0lbw7";
osx-exe-bundle = osx-bundler pkgs-osx osx-exe;
static-files = sourceByRegex ./. [
"README.md"
"Changelog.md"
"oid-decoder.html"
"example/.*"
"Debug.yaml"
"templates/"
"templates/.*\.md"
"templates/.*\.yaml"
"Audio/"
"Audio/digits/"
"Audio/digits/.*\.ogg"
];
contrib = ./contrib;
book =
let
sphinx-env = pkgs.python3.withPackages(ps: [
ps.sphinx
ps.recommonmark
]);
tex = pkgs.texlive.combine {
inherit (pkgs.texlive)
scheme-basic babel-german latexmk cmap collection-fontsrecommended
fncychap titlesec tabulary varwidth framed fancyvrb float parskip
wrapfig upquote capt-of needspace;
};
in
pkgs.stdenv.mkDerivation {
name = "tttool-book";
buildInputs = [ sphinx-env tex ];
src = builtins.path {
path = ./book;
name = "book";
filter = path: type:
baseNameOf path != "_build" &&
baseNameOf path != ".gitignore";
};
buildPhase = ''
make html
make latexpdf
rm -f _build/html/.buildinfo
rm -rf _build/html/_sources
'';
installPhase = ''
mkdir -p $out/
mv _build/html $out/book.html
mv _build/latex/tttool.pdf $out/book.pdf
'';
};
os-switch = pkgs.writeScript "tttool-os-switch.sh" ''
#!/usr/bin/env bash
case "$OSTYPE" in
linux*) exec "$(dirname "''${BASH_SOURCE[0]}")/linux/tttool" "$@" ;;
darwin*) exec "$(dirname "''${BASH_SOURCE[0]}")/osx/tttool" "$@" ;;
msys*) exec "$(dirname "''${BASH_SOURCE[0]}")/tttool.exe" "$@" ;;
cygwin*) exec "$(dirname "''${BASH_SOURCE[0]}")/tttool.exe" "$@" ;;
*) echo "unsupported operating system $OSTYPE" ;;
esac
'';
release = pkgs.runCommandNoCC "tttool-release" {
buildInputs = [ pkgs.perl ];
} ''
# check version
version=$(${static-exe}/bin/tttool --help|perl -ne 'print $1 if /tttool-(.*) -- The swiss army knife/')
doc_version=$(perl -ne "print \$1 if /VERSION: '(.*)'/" ${book}/book.html/_static/documentation_options.js)
if [ "$version" != "$doc_version" ]
then
echo "Mismatch between tttool version \"$version\" and book version \"$doc_version\""
exit 1
fi
mkdir -p $out/
cp -vsr ${static-files}/* $out
mkdir $out/linux
cp -vs ${static-exe}/bin/tttool $out/linux
cp -vs ${windows-exe}/bin/* $out/
mkdir $out/osx
cp -vsr ${osx-exe-bundle}/bin/osx/* $out/osx
cp -vs ${os-switch} $out/tttool
mkdir $out/contrib
cp -vsr ${contrib}/* $out/contrib/
cp -vsr ${book}/* $out
'';
release-zip = pkgs.runCommandNoCC "tttool-release.zip" {
buildInputs = with pkgs; [ perl zip ];
} ''
version=$(bash ${release}/tttool --help|perl -ne 'print $1 if /tttool-(.*) -- The swiss army knife/')
base="tttool-$version"
echo "Zipping tttool version $version"
mkdir -p $out/$base
cd $out
cp -r ${release}/* $base/
chmod u+w -R $base
zip -r $base.zip $base
rm -rf $base
'';
gme-downloads = pkgs.runCommandNoCC "gme-downloads" {
buildInputs = with pkgs; [ wget ];
outputHashMode = "recursive";
# This hash may change as Ravensburger edits their GME files
outputHash = "sha256:0f4pvh4bmddabr3mycscjx08nv8xkkvh5lrqij0bwsyviajsqycm";
} ''
mkdir -p $out
bash ${./testsuite/download.sh} ${./testsuite/gme-files-test.txt} $out
'';
tests = pkgs.stdenv.mkDerivation {
name = "tttool-tests";
phases = "unpackPhase checkPhase installPhase";
src = builtins.path {
path = ./testsuite;
filter = path: type:
path != builtins.toString ./testsuite/output &&
path != builtins.toString ./testsuite/downloaded &&
path != builtins.toString ./testsuite/all-gmes;
};
doCheck = true;
buildInputs = [ linux-exe pkgs.glibcLocales ];
checkPhase = ''
patchShebangs .
ln -s ${gme-downloads} downloaded
./run.sh
'';
installPhase = "touch $out";
};
# The following two derivations keep the cabal.config.freeze file
# up to date.
cabal-cmd = "nix-shell -A check-cabal-freeze default.nix";
cabal-freeze = pkgs.stdenv.mkDerivation {
name = "cabal-freeze";
src = linux-exe.src;
buildInputs = [ pkgs.cabal-install linux-exe.env ];
buildPhase = ''
mkdir .cabal
touch .cabal/config
HOME=$PWD cabal new-freeze --offline --enable-tests || true
'';
installPhase = ''
mkdir -p $out
echo "-- Run ${cabal-cmd} to update this file" > $out/cabal.project.freeze
cat cabal.project.freeze |
grep -v -F active-repositories: |
grep -v -F index-state: >> $out/cabal.project.freeze
'';
};
check-cabal-freeze = pkgs.runCommandNoCC "check-cabal-freeze" {
nativeBuildInputs = [ pkgs.diffutils ];
expected = cabal-freeze + /cabal.project.freeze;
actual = ./cabal.project.freeze;
shellHook = ''
dest=${toString ./cabal.project.freeze}
rm -f $dest
cp -v $expected $dest
chmod u-w $dest
exit 0
'';
} ''
diff -r -U 3 $actual $expected ||
{ echo "To update, please run ${cabal-cmd}"; exit 1; }
touch $out
'';
}