aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/nixos-test
blob: 980fddba482b025154773466a4934475d4f51c0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env nix-shell
#!nix-shell -i dash -p dash gawk moreutils nixos-rebuild nixfmt

set -eu

{ [ "${1:-}" = "-h" ] ||
	[ "${1:-}" = "--help" ] ||
	[ "$#" = 0 ]; } &&
	printf "nixos-test [FILE]...\n" &&
	exit

[ -f "$1" ] || { printf "Error: File '%s' not found\n" "$1" && exit; }

trap 'mv "$1.bak" "$1"; trap - EXIT; exit' EXIT INT HUP

cp "$1" "$1.bak"

nixfmt "$1"

awk '!s {s=sub("^{$","{ boot.isContainer = true;")}{ print $0 }' "$1" | sponge "$1"
awk '!s {s=sub("^in {$","in { boot.isContainer = true;")}{ print $0 }' "$1" | sponge "$1"

NIXOS_CONFIG=$(realpath "$1") nixos-rebuild --fast dry-build