aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/nixos-test
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin/nixos-test')
-rwxr-xr-x.local/bin/nixos-test35
1 files changed, 35 insertions, 0 deletions
diff --git a/.local/bin/nixos-test b/.local/bin/nixos-test
new file mode 100755
index 0000000..1fedf89
--- /dev/null
+++ b/.local/bin/nixos-test
@@ -0,0 +1,35 @@
+#!/bin/sh -eu
+
+# nix-shell -i dash -p dash gawk moreutils nixos-rebuild nixfmt
+
+{ [ "${1:-}" = "-h" ] ||
+ [ "${1:-}" = "--help" ] ||
+ [ "$#" = 0 ]; } &&
+ printf "nixos-test [FILE]...\n" &&
+ exit
+
+for configuration in "$@"; do
+
+ [ -f "$configuration" ] || { printf "Error: File '%s' not found\n" "$configuration" && exit; }
+
+ cp "$configuration" "$configuration.bak"
+
+ trap 'for configuration in "$@"; do mv "$configuration.bak" "$configuration"; done; trap - EXIT; exit' EXIT INT HUP
+
+ nixfmt "$configuration"
+
+ awk '!s {s=sub("^{$","{ boot.isContainer = true;")}{ print $0 }' "$configuration" | sponge "$configuration"
+ awk '!s {s=sub("}: {","}: { boot.isContainer = true;")}{ print $0 }' "$configuration" | sponge "$configuration"
+ awk '!s {s=sub("^in {$","in { boot.isContainer = true;")}{ print $0 }' "$configuration" | sponge "$configuration"
+
+ printf '%s ' "$configuration";
+
+ NIXOS_CONFIG=$(realpath "$configuration")
+
+ export NIXOS_CONFIG \
+ NIXPKGS_ALLOW_UNFREE=1 \
+ NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1
+
+ nixos-rebuild --fast --option substituters 'https://cache.nixos.org' --option builders '' dry-build
+
+done;