86 lines
2.0 KiB
Plaintext
Executable File
86 lines
2.0 KiB
Plaintext
Executable File
#!/usr/bin/env nu
|
|
|
|
# Ensure we are located at the bin folder
|
|
const current_folder = path self | path dirname | path dirname
|
|
cd $current_folder
|
|
|
|
def valid_profiles [] {
|
|
nix flake show --json err> /dev/null | from json |
|
|
select nixosConfigurations |
|
|
flatten | transpose |
|
|
select column0 | rename name
|
|
}
|
|
|
|
def is-valid-profile [name: string] {
|
|
(valid_profiles | where name == $name | length) == 1
|
|
}
|
|
|
|
def main [] {
|
|
print $current_folder
|
|
help main
|
|
}
|
|
|
|
def "main profiles" [] {
|
|
valid_profiles | print
|
|
}
|
|
|
|
# Build configuration
|
|
def "main build" [] {
|
|
nh os build | print
|
|
}
|
|
|
|
# Switch configuration
|
|
def "main switch" [] {
|
|
nh os switch --ask | print
|
|
}
|
|
|
|
# test configuration
|
|
def "main test" [] {
|
|
nh os test | print
|
|
}
|
|
|
|
# rollback configuration
|
|
def "main rollback" [] {
|
|
sudo nixos-rebuild switch --rollback
|
|
}
|
|
|
|
# update some flakes
|
|
def "main update" [input_name:string = ""] {
|
|
if $input_name == "" {
|
|
print "Updating all flakes..."
|
|
nix flake update | print
|
|
} else {
|
|
print "Updating flake: $input_name"
|
|
nix flake update $input_name | print
|
|
}
|
|
git diff flake.lock | print
|
|
}
|
|
|
|
# Deploy to remote machine
|
|
def "main remote" [cmd:string, target:string = ""] {
|
|
mut target_host = $"root@($target).lab.internal"
|
|
mut profile = $"hl-($target)"
|
|
# if not (is-valid-profile $profile) {
|
|
# print $"Invalid Profile ($profile), please select one of:"
|
|
# return valid_profiles
|
|
# }
|
|
$"Using [($profile)]" | print
|
|
const valid_cmds = [
|
|
"test" , "dry-activate" , "run" , "switch" , "build"
|
|
]
|
|
if not ($cmd in $valid_cmds) {
|
|
print $"Invalid command ($cmd), please select one of"
|
|
return $valid_cmds
|
|
}
|
|
$"($cmd) on ($target_host) with ($profile)" | print
|
|
mut runcmd = $"nh os ($cmd) --target-host ($target_host) --ask .#($profile)"
|
|
$runcmd | print
|
|
bash -c $runcmd
|
|
}
|
|
|
|
# Build ISO image
|
|
def "main build-iso" [] {
|
|
nix build .#nixosConfigurations.iso.config.system.build.isoImage
|
|
ls -l result/iso
|
|
}
|