KYPDLOMFTH6IETNNZ7FS7HYAXPAGST2ROBO4ENGR4UYSG3PQNBXQC SCB7IK7YNYAR3WTV2XYGPYCGCUW2GPJSWAA5S2ZGCYSZ5AZKXIDAC 4MM66MG2G2RUFJOTWRBCMWEK4YYCMKPQCO45CZLQ6VDVIO3ITMJQC C7RQ6W5HRUARWHCHFYQ4NSKLL4XXNFJZUKF4AWAC7HVBFQAAEZIQC 5G7WRBMWKG6DMCOHE6WQHTYZACUHO2UPBZRWN72CFH7P45NN5E7QC J4KXXGIIQSRBYE6ZOSKCCKJNRR3J2KG6N3ZKQ3UOBXBYAICNQ4OAC 4DJCBLW3CFDQPY3CBDTZAE7URHA4QP2F6XGVOKHNM3SI5O55WU2AC SQ2SHQL4JSA7RRRNZBBAFGCBMW2GVVRDSHNERLY6JXSNJBKWBJLAC QRPPLHLL6YZU3Z35JNJFXHMBY3BX4THHN4AMWDFCUSFHYAHWTRHAC QOY7D3GZ3WF7HAMEHAW2CIUB5TDQCFE3YDZEO23R5MFQEBN635WAC def main [--remote] {let os = (sys host | get name)let hostname = (hostname | str trim)
def --wrapped main [host: string = "" # The host to build (maybe useless will see)--remote # Deploy to remote host using --target-host--rollback # Rollback...arguments # Extra arguments to pass to rebuild commands]: nothing -> nothing {let host = if ($host | is-not-empty) {if $host != (hostname) and not $remote {print $"(ansi yellow_bold)warn:(ansi reset) building local configuration for hostname that does not match the local machine"}$host} else if $remote {print $"(ansi red_bold)error:(ansi reset) hostname not specified for remote deployment"exit 1} else {(hostname)}
let flake = if $remote {$"github:jamesukiyo/nixos#($hostname)"} else {$"($config_path)#($hostname)"}
let base_args = ["switch""--flake" $flake_ref"--accept-flake-config" # avoid asking for y/n approval for all settings] | append $arguments
if $os == "Darwin" {print $"Building Darwin configuration for ($hostname) from ($flake)..."sudo darwin-rebuild switch --flake $flake
# Add target-host for remote deploymentslet final_args = if $remote {$base_args | append ["--target-host" $"root@($host)"]
home.file."nixos-config/rollback.nu" = {text = ''#!/usr/bin/env nudef main [--remote] {let os = (sys host | get name)let hostname = (hostname | str trim)let config_path = if $os == "Darwin" { "/Users/james/nixos-config" } else { "/home/james/nixos-config" }let flake = if $remote {$"github:jamesukiyo/nixos#($hostname)"
# Add rollback flag if specifiedlet final_args = if $rollback {$final_args | prepend "--rollback"
print $"Rolling back Darwin configuration for ($hostname) from ($flake)..."sudo darwin-rebuild switch --rollback --flake $flake
let action = if $remote { $"deploying to ($host)" } else { "building locally" }print $"(ansi green_bold)($action) Darwin configuration for ($host)...(ansi reset)"if $remote {darwin-rebuild ...$final_args} else {sudo darwin-rebuild ...$final_args}
print $"Rolling back NixOS configuration for ($hostname) from ($flake)..."sudo nixos-rebuild switch --rollback --flake $flake
let action = if $remote { $"deploying to ($host)" } else { "building locally" }print $"(ansi green_bold)($action) NixOS configuration for ($host)...(ansi reset)"if $remote {nixos-rebuild ...$final_args} else {sudo nixos-rebuild ...$final_args}