aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/nixos-test
blob: e87bd9ef3d3d51be037ba4fde5d92949546428ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/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("^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' dry-build

done;