lol

nixos/activation-script: Add lib.sh with warn()

+78
+2
nixos/modules/system/activation/activation-script.nix
··· 33 33 '' 34 34 #!${pkgs.runtimeShell} 35 35 36 + source ${./lib/lib.sh} 37 + 36 38 systemConfig='@out@' 37 39 38 40 export PATH=/empty
+5
nixos/modules/system/activation/lib/lib.sh
··· 1 + # shellcheck shell=bash 2 + 3 + warn() { 4 + printf "\033[1;35mwarning:\033[0m %s\n" "$*" >&2 5 + }
+36
nixos/modules/system/activation/lib/test.nix
··· 1 + # Run: 2 + # nix-build -A nixosTests.activation-lib 3 + { lib, stdenv, testers }: 4 + let 5 + inherit (lib) fileset; 6 + 7 + runTests = stdenv.mkDerivation { 8 + name = "tests-activation-lib"; 9 + src = fileset.toSource { 10 + root = ./.; 11 + fileset = fileset.unions [ 12 + ./lib.sh 13 + ./test.sh 14 + ]; 15 + }; 16 + buildPhase = ":"; 17 + doCheck = true; 18 + postUnpack = '' 19 + patchShebangs --build . 20 + ''; 21 + checkPhase = '' 22 + ./test.sh 23 + ''; 24 + installPhase = '' 25 + touch $out 26 + ''; 27 + }; 28 + 29 + runShellcheck = testers.shellcheck { 30 + src = runTests.src; 31 + }; 32 + 33 + in 34 + lib.recurseIntoAttrs { 35 + inherit runTests runShellcheck; 36 + }
+34
nixos/modules/system/activation/lib/test.sh
··· 1 + #!/usr/bin/env bash 2 + 3 + # Run: 4 + # ./test.sh 5 + # or: 6 + # nix-build -A nixosTests.activation-lib 7 + 8 + cd "$(dirname "${BASH_SOURCE[0]}")" 9 + set -euo pipefail 10 + 11 + # report failure 12 + onerr() { 13 + set +e 14 + # find failed statement 15 + echo "call trace:" 16 + local i=0 17 + while t="$(caller $i)"; do 18 + line="${t%% *}" 19 + file="${t##* }" 20 + echo " $file:$line" >&2 21 + ((i++)) 22 + done 23 + # red 24 + printf "\033[1;31mtest failed\033[0m\n" >&2 25 + exit 1 26 + } 27 + trap onerr ERR 28 + 29 + source ./lib.sh 30 + 31 + (warn hi, this works >/dev/null) 2>&1 | grep -E $'.*warning:.* hi, this works' >/dev/null 32 + 33 + # green 34 + printf "\033[1;32mok\033[0m\n"
+1
nixos/tests/all-tests.nix
··· 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 + 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;