39 lines
1.4 KiB
Plaintext
39 lines
1.4 KiB
Plaintext
#!/usr/bin/env nu
|
|
|
|
# Main function
|
|
def main [ action: string = "build" host?: string --user: string = "root" --source: string --inside ] {
|
|
mut source = $source
|
|
if ($source == null) {
|
|
# Copy this flake to the store
|
|
$source = ^nix flake prefetch --json | jq .storePath --raw-output
|
|
}
|
|
mut ssh = "ssh"
|
|
if ($host != null) {
|
|
print $"Nix path of flake is ($source). Copying.."
|
|
# Copy the store entry to the target
|
|
nix copy --to $"ssh://($user)@($host)" --substitute-on-destination $source
|
|
# Just call this script on the remote machine 😈
|
|
if ($env.TERM == "xterm-kitty") {
|
|
ssh $"($user)@($host)" -- nix run $"($source)#push" -- $action --source $source
|
|
} else {
|
|
kitty +kitten ssh $"($user)@($host)" -- nix run $"($source)#push" -- $action --source $source
|
|
}
|
|
} else {
|
|
let source = if $source != null { $source } else { "." }
|
|
let host = hostname
|
|
# Switch to temp dir
|
|
cd (mktemp -d)
|
|
# Build using nix-output-monitor
|
|
print $"($source)#nixosConfigurations.($host).config.system.build.toplevel"
|
|
nom build $"($source)#nixosConfigurations.($host).config.system.build.toplevel"
|
|
print ""
|
|
print ""
|
|
nvd diff /run/current-system result
|
|
print ""
|
|
print ""
|
|
if ($action != "build") {
|
|
sudo nixos-rebuild --flake $"($source)#($host)" $action --log-format internal-json -v o+e>| nom --json
|
|
}
|
|
}
|
|
}
|