aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/nixos-test
blob: 354f8f6d596222f00d8a7e5780f114c6de4832d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/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

[ -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 --option substituters 'https://cache.nixos.org' dry-build