-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.nix
120 lines (101 loc) · 2.99 KB
/
setup.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
{ self
, pkgs
, inputs
, system
}:
with pkgs.lib;
let
buildFromConfig = configuration: sel: sel
(import inputs.nix-darwin {
inherit (inputs) nixpkgs;
inherit configuration system;
}).config;
testName = file:
builtins.replaceStrings [ ".nix" ] [ "" ]
(builtins.baseNameOf file);
makeTest = name: test:
let
configuration =
{ config, pkgs, ... }:
let
defaults = builtins.toJSON
config.system.defaults.CustomUserPreferences;
purgeScript = config.plist.purgeScript;
in
{
imports = [
self.darwinModules.default
test
];
options.test = mkOption {
type = types.lines;
};
config = {
system.stateVersion = config.system.maxStateVersion;
system.build.run-test = pkgs.runCommandLocal name
{
nativeBuildInputs = with pkgs; [
jq
];
}
''
set -e
mkdir -p $out
echo ${escapeShellArg defaults} > $out/defaults.json
echo ${escapeShellArg purgeScript} > $out/purge.sh
# Holds domain context
d=""
function Domain {
if [[ -n "$d" ]]; then
echo "Domain end"
fi
d=$1
echo ""
echo "Domain start: '$d'"
}
function Set {
v=$(cat $out/defaults.json | jq ".\"$d\".\"$1\"")
if [[ "$v" != "$2" ]]; then
echo ""
echo "Expected attribute '$d'.'$1' to equal:"
echo ""
echo " $2"
echo ""
echo "But value is:"
echo ""
echo " $v"
echo ""
echo "Full output:"
echo ""
jq . $out/defaults.json | sed 's/^/ /'
echo ""
exit 1
fi
}
function Del {
if ! grep -q "defaults delete '$d' '$1'" $out/purge.sh; then
echo ""
echo "Expected attribute '$d'.'$1' to be deleted."
echo ""
echo "Actual output:"
echo ""
cat $out/purge.sh | sed 's/^/ /'
echo ""
exit 1
fi
}
echo "Running '${name}'"
${config.test}
'';
};
};
in
buildFromConfig configuration (config: config.system.build.run-test);
in
listToAttrs (map
(file: rec {
name = testName file;
value = makeTest name file;
})
(fileset.toList
(fileset.fileFilter (file: hasPrefix "test-" file.name) ./.)))