nixos/activation-script: Add lib.sh with warn()
This commit is contained in:
@@ -33,6 +33,8 @@ let
|
|||||||
''
|
''
|
||||||
#!${pkgs.runtimeShell}
|
#!${pkgs.runtimeShell}
|
||||||
|
|
||||||
|
source ${./lib/lib.sh}
|
||||||
|
|
||||||
systemConfig='@out@'
|
systemConfig='@out@'
|
||||||
|
|
||||||
export PATH=/empty
|
export PATH=/empty
|
||||||
|
|||||||
5
nixos/modules/system/activation/lib/lib.sh
Normal file
5
nixos/modules/system/activation/lib/lib.sh
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# shellcheck shell=bash
|
||||||
|
|
||||||
|
warn() {
|
||||||
|
printf "\033[1;35mwarning:\033[0m %s\n" "$*" >&2
|
||||||
|
}
|
||||||
36
nixos/modules/system/activation/lib/test.nix
Normal file
36
nixos/modules/system/activation/lib/test.nix
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
# Run:
|
||||||
|
# nix-build -A nixosTests.activation-lib
|
||||||
|
{ lib, stdenv, testers }:
|
||||||
|
let
|
||||||
|
inherit (lib) fileset;
|
||||||
|
|
||||||
|
runTests = stdenv.mkDerivation {
|
||||||
|
name = "tests-activation-lib";
|
||||||
|
src = fileset.toSource {
|
||||||
|
root = ./.;
|
||||||
|
fileset = fileset.unions [
|
||||||
|
./lib.sh
|
||||||
|
./test.sh
|
||||||
|
];
|
||||||
|
};
|
||||||
|
buildPhase = ":";
|
||||||
|
doCheck = true;
|
||||||
|
postUnpack = ''
|
||||||
|
patchShebangs --build .
|
||||||
|
'';
|
||||||
|
checkPhase = ''
|
||||||
|
./test.sh
|
||||||
|
'';
|
||||||
|
installPhase = ''
|
||||||
|
touch $out
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
runShellcheck = testers.shellcheck {
|
||||||
|
src = runTests.src;
|
||||||
|
};
|
||||||
|
|
||||||
|
in
|
||||||
|
lib.recurseIntoAttrs {
|
||||||
|
inherit runTests runShellcheck;
|
||||||
|
}
|
||||||
34
nixos/modules/system/activation/lib/test.sh
Executable file
34
nixos/modules/system/activation/lib/test.sh
Executable file
@@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Run:
|
||||||
|
# ./test.sh
|
||||||
|
# or:
|
||||||
|
# nix-build -A nixosTests.activation-lib
|
||||||
|
|
||||||
|
cd "$(dirname "${BASH_SOURCE[0]}")"
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# report failure
|
||||||
|
onerr() {
|
||||||
|
set +e
|
||||||
|
# find failed statement
|
||||||
|
echo "call trace:"
|
||||||
|
local i=0
|
||||||
|
while t="$(caller $i)"; do
|
||||||
|
line="${t%% *}"
|
||||||
|
file="${t##* }"
|
||||||
|
echo " $file:$line" >&2
|
||||||
|
((i++))
|
||||||
|
done
|
||||||
|
# red
|
||||||
|
printf "\033[1;31mtest failed\033[0m\n" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
trap onerr ERR
|
||||||
|
|
||||||
|
source ./lib.sh
|
||||||
|
|
||||||
|
(warn hi, this works >/dev/null) 2>&1 | grep -E $'.*warning:.* hi, this works' >/dev/null
|
||||||
|
|
||||||
|
# green
|
||||||
|
printf "\033[1;32mok\033[0m\n"
|
||||||
@@ -296,6 +296,7 @@ in {
|
|||||||
esphome = handleTest ./esphome.nix {};
|
esphome = handleTest ./esphome.nix {};
|
||||||
etc = pkgs.callPackage ../modules/system/etc/test.nix { inherit evalMinimalConfig; };
|
etc = pkgs.callPackage ../modules/system/etc/test.nix { inherit evalMinimalConfig; };
|
||||||
activation = pkgs.callPackage ../modules/system/activation/test.nix { };
|
activation = pkgs.callPackage ../modules/system/activation/test.nix { };
|
||||||
|
activation-lib = pkgs.callPackage ../modules/system/activation/lib/test.nix { };
|
||||||
activation-var = runTest ./activation/var.nix;
|
activation-var = runTest ./activation/var.nix;
|
||||||
activation-nix-channel = runTest ./activation/nix-channel.nix;
|
activation-nix-channel = runTest ./activation/nix-channel.nix;
|
||||||
activation-etc-overlay-mutable = runTest ./activation/etc-overlay-mutable.nix;
|
activation-etc-overlay-mutable = runTest ./activation/etc-overlay-mutable.nix;
|
||||||
|
|||||||
Reference in New Issue
Block a user