tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
0
fork
atom
lol
0
fork
atom
overview
issues
pulls
pipelines
nixos/activation-script: Add lib.sh with warn()
Robert Hensing
2 years ago
1022da85
3fb14db0
+78
5 changed files
expand all
collapse all
unified
split
nixos
modules
system
activation
activation-script.nix
lib
lib.sh
test.nix
test.sh
tests
all-tests.nix
+2
nixos/modules/system/activation/activation-script.nix
reviewed
···
33
33
''
34
34
#!${pkgs.runtimeShell}
35
35
36
36
+
source ${./lib/lib.sh}
37
37
+
36
38
systemConfig='@out@'
37
39
38
40
export PATH=/empty
+5
nixos/modules/system/activation/lib/lib.sh
reviewed
···
1
1
+
# shellcheck shell=bash
2
2
+
3
3
+
warn() {
4
4
+
printf "\033[1;35mwarning:\033[0m %s\n" "$*" >&2
5
5
+
}
+36
nixos/modules/system/activation/lib/test.nix
reviewed
···
1
1
+
# Run:
2
2
+
# nix-build -A nixosTests.activation-lib
3
3
+
{ lib, stdenv, testers }:
4
4
+
let
5
5
+
inherit (lib) fileset;
6
6
+
7
7
+
runTests = stdenv.mkDerivation {
8
8
+
name = "tests-activation-lib";
9
9
+
src = fileset.toSource {
10
10
+
root = ./.;
11
11
+
fileset = fileset.unions [
12
12
+
./lib.sh
13
13
+
./test.sh
14
14
+
];
15
15
+
};
16
16
+
buildPhase = ":";
17
17
+
doCheck = true;
18
18
+
postUnpack = ''
19
19
+
patchShebangs --build .
20
20
+
'';
21
21
+
checkPhase = ''
22
22
+
./test.sh
23
23
+
'';
24
24
+
installPhase = ''
25
25
+
touch $out
26
26
+
'';
27
27
+
};
28
28
+
29
29
+
runShellcheck = testers.shellcheck {
30
30
+
src = runTests.src;
31
31
+
};
32
32
+
33
33
+
in
34
34
+
lib.recurseIntoAttrs {
35
35
+
inherit runTests runShellcheck;
36
36
+
}
+34
nixos/modules/system/activation/lib/test.sh
reviewed
···
1
1
+
#!/usr/bin/env bash
2
2
+
3
3
+
# Run:
4
4
+
# ./test.sh
5
5
+
# or:
6
6
+
# nix-build -A nixosTests.activation-lib
7
7
+
8
8
+
cd "$(dirname "${BASH_SOURCE[0]}")"
9
9
+
set -euo pipefail
10
10
+
11
11
+
# report failure
12
12
+
onerr() {
13
13
+
set +e
14
14
+
# find failed statement
15
15
+
echo "call trace:"
16
16
+
local i=0
17
17
+
while t="$(caller $i)"; do
18
18
+
line="${t%% *}"
19
19
+
file="${t##* }"
20
20
+
echo " $file:$line" >&2
21
21
+
((i++))
22
22
+
done
23
23
+
# red
24
24
+
printf "\033[1;31mtest failed\033[0m\n" >&2
25
25
+
exit 1
26
26
+
}
27
27
+
trap onerr ERR
28
28
+
29
29
+
source ./lib.sh
30
30
+
31
31
+
(warn hi, this works >/dev/null) 2>&1 | grep -E $'.*warning:.* hi, this works' >/dev/null
32
32
+
33
33
+
# green
34
34
+
printf "\033[1;32mok\033[0m\n"
+1
nixos/tests/all-tests.nix
reviewed
···
296
296
esphome = handleTest ./esphome.nix {};
297
297
etc = pkgs.callPackage ../modules/system/etc/test.nix { inherit evalMinimalConfig; };
298
298
activation = pkgs.callPackage ../modules/system/activation/test.nix { };
299
299
+
activation-lib = pkgs.callPackage ../modules/system/activation/lib/test.nix { };
299
300
activation-var = runTest ./activation/var.nix;
300
301
activation-nix-channel = runTest ./activation/nix-channel.nix;
301
302
activation-etc-overlay-mutable = runTest ./activation/etc-overlay-mutable.nix;