2025-09-21 18:53:42 -05:00
|
|
|
# vim: set filetype=nushell :
|
2026-06-22 14:00:23 -04:00
|
|
|
let servers = [isaiah jeremiah zeke genesis hosea]
|
2025-09-11 21:39:34 -05:00
|
|
|
|
2025-09-11 12:15:39 -05:00
|
|
|
def par-map [ items: list, c: closure ] {
|
|
|
|
|
let results = $items | par-each -k $c
|
|
|
|
|
$items | enumerate | reduce -f {} {|e, a| $a | upsert $e.item { $results | get $e.index }}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def --env unlock [] {
|
|
|
|
|
if "BW_SESSION" not-in $env {
|
|
|
|
|
$env.BW_SESSION = ^bw unlock --raw
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-21 17:17:04 -05:00
|
|
|
def nebulaIps [] {
|
2026-07-25 13:49:21 -05:00
|
|
|
open /etc/nixos/network.json | get hosts | items { |h, e| $e.nebulaIp? } | where $it != null | sort
|
2026-07-21 17:17:04 -05:00
|
|
|
}
|
|
|
|
|
|
2026-07-28 22:41:01 -05:00
|
|
|
def localIps [] {
|
|
|
|
|
open /etc/nixos/network.json | get hosts | items { |h, e| $e.ip? } | where $it != null | sort
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-25 15:18:15 -05:00
|
|
|
def genNebulaCert [ --ips: string, --name: string ] {
|
|
|
|
|
let public = $'~/SynologyDrive/nebula/($name).key.pub' | path expand
|
|
|
|
|
let private = $'~/SynologyDrive/nebula/($name).key' | path expand
|
|
|
|
|
let cert = $'/etc/nixos/secrets/nebula/($name).crt'
|
|
|
|
|
let ca_cert = '~/SynologyDrive/nebula/ca.crt' | path expand
|
|
|
|
|
let ca_key = '~/SynologyDrive/nebula/ca.key' | path expand
|
|
|
|
|
|
|
|
|
|
# Generate public key if there isn't one already
|
|
|
|
|
if ( not ($public | path exists) ) {
|
|
|
|
|
nebula-cert keygen -out-key $private -out-pub $public
|
|
|
|
|
}
|
|
|
|
|
# Clear old cert if there is one
|
|
|
|
|
if ( $cert | path exists) {
|
|
|
|
|
rm $cert
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Create and sign certs
|
|
|
|
|
(nebula-cert sign
|
|
|
|
|
-ca-crt $ca_cert
|
|
|
|
|
-ca-key $ca_key
|
|
|
|
|
-name $name
|
|
|
|
|
-networks $ips
|
|
|
|
|
-out-crt $cert
|
|
|
|
|
-in-pub $public
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Agenix update
|
|
|
|
|
cd /etc/nixos/secrets
|
|
|
|
|
cat $private | agenix -e $'nebula/($name).key.age'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2026-06-24 12:49:32 -05:00
|
|
|
def rebuild [ $target: string = "switch" ] {
|
2025-09-11 12:15:39 -05:00
|
|
|
if (uname | get operating-system) == "Darwin" {
|
2026-06-24 12:49:32 -05:00
|
|
|
sudo darwin-rebuild $target
|
2025-09-11 12:15:39 -05:00
|
|
|
} else {
|
|
|
|
|
let hostname = uname | get nodename
|
2025-09-30 21:57:11 -05:00
|
|
|
let build = ^nom build --keep-going $"/etc/nixos#nixosConfigurations.($hostname).config.system.build.toplevel"
|
2025-09-21 18:53:42 -05:00
|
|
|
if $env.LAST_EXIT_CODE == 0 {
|
|
|
|
|
nvd diff /run/current-system result
|
2026-06-24 12:49:32 -05:00
|
|
|
run0 result/bin/switch-to-configuration $target
|
2025-09-21 18:53:42 -05:00
|
|
|
} else {
|
|
|
|
|
print "Error during build"
|
|
|
|
|
}
|
2025-09-11 12:15:39 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def deploy [ $host: string, $build: string = "" ] {
|
|
|
|
|
mut buildhost = $build
|
|
|
|
|
if $build == "" {
|
|
|
|
|
$buildhost = $host
|
|
|
|
|
}
|
2025-09-27 09:19:17 -05:00
|
|
|
if $buildhost == "linode" or $buildhost == "genesis" {
|
2025-09-11 12:15:39 -05:00
|
|
|
$buildhost = "isaiah"
|
|
|
|
|
}
|
2026-07-25 15:18:15 -05:00
|
|
|
colmena apply --on $host
|
|
|
|
|
#nixos-rebuild switch --sudo --use-substitutes --target-host $host --build-host $buildhost
|
2025-09-11 12:15:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def ff [ $file: string ] {
|
|
|
|
|
ls **/* | where name =~ $file
|
|
|
|
|
}
|
2025-09-11 21:39:34 -05:00
|
|
|
|
|
|
|
|
def update_all [] {
|
2025-09-11 23:01:00 -05:00
|
|
|
par-map $servers {|e| deploy $e | complete} | explore
|
2025-09-11 21:39:34 -05:00
|
|
|
}
|
2025-09-12 13:25:00 -05:00
|
|
|
|
|
|
|
|
def bake [template: string] {
|
|
|
|
|
let copier = "~/.copier-templates" | path expand
|
|
|
|
|
if not ($copier | path exists) {
|
|
|
|
|
git clone srcpub:greg/copier-templates.git $copier
|
|
|
|
|
}
|
|
|
|
|
let srcdir = [$copier $template] | path join
|
|
|
|
|
print $srcdir
|
|
|
|
|
copier copy $srcdir .
|
|
|
|
|
}
|
2025-10-09 16:22:57 -05:00
|
|
|
|
|
|
|
|
def podman_image_clean [] {
|
|
|
|
|
podman rmi ...(^podman images --format=json | from json | where {|e| not ("Names" in $e)} | get Id)
|
|
|
|
|
}
|
2025-10-14 09:53:27 -05:00
|
|
|
|
|
|
|
|
def dc [ $cmd: string = "sh" ] {
|
|
|
|
|
match $cmd {
|
|
|
|
|
"up" => (devcontainer up --workspace-folder . --docker-path podman),
|
|
|
|
|
"sh" => (devcontainer exec --workspace-folder . --docker-path podman bash),
|
|
|
|
|
"down" => (podman compose -f .devcontainer/(open .devcontainer/devcontainer.json | get dockerComposeFile | first) down),
|
|
|
|
|
_ => (devcontainer --help),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ("/usr/local/bin" | path exists) {
|
|
|
|
|
$env.PATH = $env.PATH | append "/usr/local/bin"
|
|
|
|
|
}
|
2026-04-06 16:50:06 -05:00
|
|
|
$env.PATH = $env.PATH | prepend "~/.local/bin"
|