nix machine / user configurations

refactor(deploy): use std/log to log

ptr.pet f555033b 792d7e01

verified
Changed files
+5 -8
+5 -8
deploy.nu
···
#!/usr/bin/env nu
use std "path add"
+
use std/log
path add /nix/var/nix/profiles/default/bin
# load webhook secrets
rage -d -i ./ssh_key ./secrets/deployWebhook.age | from toml | load-env
-
-
def log [msg: string, --type (-t): string = "info"] {
-
print $"[($type)][(date now | format date "%H:%M:%S")] ($msg)"
-
}
def webhook [title: string, content: string, exit_code?: number, ping?: bool = false] {
let type = if $exit_code == null { "⌛" } else if $exit_code == 0 { "✔️" } else { "❌" }
···
}]
}
-
log -t debug "posting webhook...."
+
log debug "posting webhook...."
http post --content-type application/json $"https://discord.com/api/webhooks/($env.WEBHOOK_ID)/($env.WEBHOOK_TOKEN)" $msg
}
def deploy [hostname: string] {
-
log $"trying to deploy host ($hostname)"
+
log info $"trying to deploy host ($hostname)"
let hooktitle = $"/($hostname)/deploy"
let start = date now
···
}
def update-input [input: string] {
-
log $"trying to update input ($input)"
+
log info $"trying to update input ($input)"
let result = nix flake update $input | complete
let is_ok = ($result.stderr | str contains "Updated input")
let is_err = ($result.exit_code != 0)
···
update-input "blog"
try {
-
log "trying to update dns records"
+
log info "trying to update dns records"
nix run ".#dns" -- push
} catch { |err|
webhook "dns" $"=== error pushing dns ===\n\n($err.msg | to text)" 1