feat(deployment): add configurable NixOS deployment modes

This commit is contained in:
Ryan Yin
2026-07-24 15:44:40 +08:00
parent bae7e05a9a
commit 83d919815b
5 changed files with 98 additions and 70 deletions
+21 -15
View File
@@ -7,17 +7,23 @@ def repeat-str [s: string, n: int] {
export def nixos-switch [
name: string
mode: string
verbosity: string
] {
print $"nixos-switch '($name)' in '($mode)' mode..."
if $mode not-in ["switch" "boot"] {
error make { msg: $"unsupported deployment mode '($mode)'; expected switch or boot" }
}
if $verbosity not-in ["normal" "debug"] {
error make { msg: $"unsupported verbosity '($verbosity)'; expected normal or debug" }
}
print $"nixos-switch '($name)' in '($mode)' mode with '($verbosity)' verbosity..."
print (repeat-str "=" 50)
if "debug" == $mode {
if $verbosity == "debug" {
# show details via nix-output-monitor
nom build $".#nixosConfigurations.($name).config.system.build.toplevel" --accept-flake-config --show-trace --verbose
nixos-rebuild switch --sudo --flake $".#($name)" --accept-flake-config --show-trace --verbose
} else if "boot" == $mode {
nixos-rebuild boot --sudo --flake $".#($name)" --accept-flake-config
nixos-rebuild $mode --sudo --flake $".#($name)" --accept-flake-config --show-trace --verbose
} else {
nixos-rebuild switch --sudo --flake $".#($name)" --accept-flake-config
nixos-rebuild $mode --sudo --flake $".#($name)" --accept-flake-config
}
}
@@ -38,12 +44,12 @@ export def make-editable [
export def darwin-build [
name: string
mode: string
verbosity: string
] {
print $"darwin-build '($name)' in '($mode)' mode..."
print $"darwin-build '($name)' with '($verbosity)' verbosity..."
print (repeat-str "=" 50)
let target = $".#darwinConfigurations.($name).system"
if "debug" == $mode {
if "debug" == $verbosity {
nom build $target --extra-experimental-features "nix-command flakes" --show-trace --verbose
} else {
nix build $target --extra-experimental-features "nix-command flakes"
@@ -52,11 +58,11 @@ export def darwin-build [
export def darwin-switch [
name: string
mode: string
verbosity: string
] {
print $"darwin-switch '($name)' in '($mode)' mode..."
print $"darwin-switch '($name)' with '($verbosity)' verbosity..."
print (repeat-str "=" 50)
if "debug" == $mode {
if "debug" == $verbosity {
sudo -E ./result/sw/bin/darwin-rebuild switch --flake $".#($name)" --show-trace --verbose
} else {
sudo -E ./result/sw/bin/darwin-rebuild switch --flake $".#($name)"
@@ -72,12 +78,12 @@ export def darwin-rollback [] {
# Build and upload a VM image
export def upload-vm [
name: string
mode: string
verbosity: string
] {
print $"upload-vm '($name)' in '($mode)' mode..."
print $"upload-vm '($name)' with '($verbosity)' verbosity..."
print (repeat-str "=" 50)
let target = $".#($name)"
if "debug" == $mode {
if "debug" == $verbosity {
nom build $target --show-trace --verbose
} else {
nix build $target