blob: b41e9f54b3ff9cb770765f0915ceacc1851e92d1 (
about) (
plain) (
blame)
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
|
{ pkgs, src, baseName }:
let
nixfmt = import (builtins.fetchTarball
"https://github.com/serokell/nixfmt/archive/master.tar.gz") { };
in rec {
baseTask = pkgs.stdenv.mkDerivation {
name = "${baseName}-task";
src = src;
buildInputs = [ ];
phases = "unpackPhase buildPhase";
buildPhase = ''
echo "ERROR: base task buildPhase not overriden."
exit 1
'';
};
shellcheck = ignoredFindPattern:
baseTask.overrideAttrs (baseAttrs: rec {
name = "${baseAttrs.name}-shellcheck";
buildInputs = baseAttrs.buildInputs ++ [ pkgs.shellcheck ];
ignoredPattern = if ignoredFindPattern == null then "" else ignoredFindPattern;
buildPhase = ''
find . -type f \( -name '*.sh' -and -regextype egrep ! -regex '${ignoredPattern}' \) -print0 | xargs -0 shellcheck
touch $out
'';
});
formatNix = baseTask.overrideAttrs (baseAttrs: {
name = "${baseAttrs.name}-nixfmt";
buildInputs = baseAttrs.buildInputs ++ [ nixfmt ];
buildPhase = ''
format() {
nix_file="$1"
diff <(nixfmt < "$nix_file") "$nix_file" || {
echo "The $nix_file is unformatted. To fix it, run:"
echo " nixfmt $nix_file"
exit 1
}
}
export -f format
find . -type f -name '*.nix' -print0 | xargs -0 -I{} bash -c "format {}" \;
touch $out
'';
});
fixme = ignoredFiles:
baseTask.overrideAttrs (baseAttrs: rec {
name = "${baseAttrs.name}-fixme";
buildInputs = baseAttrs.buildInputs ++ [ pkgs.ag ];
ignoredPattern = pkgs.lib.fold (a: b: " --ignore ${a} ${b}") ""
(if ignoredFiles == null then [
"default.nix"
"TODOs.org"
] else
ignoredFiles);
buildPhase = ''
ag FIXME ${ignoredPattern} || {
touch $out
exit 0
}
echo " Found dangling FIXME markers on the project."
echo " You should write them down properly on TODOs.org."
exit 1
'';
});
orgMkDocs = title:
baseTask.overrideAttrs (baseAttrs: {
name = "${baseAttrs.name}-docs";
buildInputs = [ pkgs.pandoc pkgs.mkdocs ];
buildPhase = ''
# Convert from org-mode to markdown with pandoc
find docs/ -type f -name '*.org' -print0 | xargs -0 -I{} pandoc -o {}.md {}.org
# Give the generated markdown files to MkDocs
mkdocs build
# Build remaining one-off files
pandoc README.org -o site/index.html --css docs/README.css --to=html5 --self-contained --metadata title="${title}"
mv site/ $out/
'';
});
test = testDerivations:
baseTask.overrideAttrs (baseAttrs: {
name = "${baseAttrs.name}-test";
buildPhase = ''
echo "Ran tests for:"
for d in ${builtins.toString testDerivations}; do
echo " $d"
done
echo "All tests passed!"
touch $out
'';
});
publishScript = docsDerivation:
pkgs.writeShellScriptBin "publish.sh" ''
set -euo pipefail
OUT_DOCS="${docsDerivation}"
${pkgs.rsync}/bin/rsync -avzP \
--rsh="ssh -o StrictHostKeyChecking=no" \
"$OUT_DOCS/" \
"$SERVER_URL:$DOCS_SERVER_PATH"
'';
}
|