cleaner cli + pkg update

This commit is contained in:
ari committed 2026-10-15 17:04:05 -04:00
1 parent 58e0705aca
commit 6fbdcf44cf
19 files changed
+590 -424

No files matched your search

+9
View File
@@ -1,5 +1,7 @@
*.AppImage
.pytest_cache
# Devenv
.devenv*
devenv.local.nix
@@ -33,3 +35,10 @@ docs
# worktrees
.branches
# agents
.commandcode
.delta
.claude
.mnt
.pi
+64 -41
View File
@@ -6,20 +6,21 @@ My comprehensive Nix configurations for managing multiple hosts, including local
```
nixos-setup/
├── bin/
│ └── skyg # Main CLI tool for managing NixOS configurations
├── configs/ # Application-specific configurations
├── pkgs/ # Custom packages (niri-touchscreen-gestures, grok-cli)
├── hosts/ # Host-specific NixOS configurations
│ ├── *.nix # Host configuration files (fwbook, hl-bigbox1, hl-minipc*, etc.)
│ ├── *.hardware-configuration.nix # Hardware-specific configurations
│ └── scripts/ # Host-specific scripts
├── bin/ # `skyg` CLI
│ ├── skyg # Bash shim → NuShell command modules in bin/lib/
│ ├── check-flake-versions # Shim for `skyg flake check-versions`
│ ├── temp-monitor # NuShell CPU/GPU temperature logger (see TEMP_MONITOR_README.md)
│ └── lib/ # NuShell command modules (os, remote, secrets, ca, pkgs, flake, build, render, hm)
├── configs/ # Application-specific configurations (incl. configs/pki TLS certs)
├── pkgs/ # Custom packages (buzz-desktop, colibri, delta-editor, niri-touchscreen-gestures, superset-desktop)
├── hosts/ # One folder per host (fwbook, hl-*, iso) + generated hardware configs
├── modules/ # Reusable NixOS and Home Manager modules
│ ├── core/ # Core system modules
│ ├── home/ # Home Manager modules
│ ├── nixos/ # NixOS-specific modules
│ └── *.nix # Utility modules (lib, skyg-utils, network-drives, etc.)
├── apps/ # Standalone applications
│ └── *.nix # Utility modules (lib, skyg-utils, internal-networking, etc.)
├── openwrt-routers/ # OpenWrt router configs (glmain)
├── docs/ # Documentation
├── flake.nix # Nix flake definition
├── flake.lock # Locked dependency versions
└── README.md # This file
@@ -45,55 +46,77 @@ To use the custom packages in your own NixOS/Home Manager configuration:
}
```
You can also import `nixos-setup.lib` to reuse `makeNixOs`, `makeHomeManagerUsers`, and other utilities.
You can also import `nixos-setup.lib` to reuse `makeNixOs`, `makeHomeManagerUsers`, `makeIso`, `makeSdImage`, and other utilities.
See [`pkgs/ABOUTME.md`](pkgs/ABOUTME.md) for details on each package.
## Quick Start
The `skyg` script is your main interface for managing these configurations. It's located in `bin/skyg` and uses NuShell.
The `skyg` script is your main interface for managing these configurations. It's located in `bin/skyg` and uses NuShell. Run `skyg` with no arguments to list subcommands, or `skyg <subcommand> --help` for details.
### Available Commands
#### System Management
#### Local System (`skyg os`)
- **`skyg build`** - Build the current system configuration
- **`skyg switch`** - Switch to a new configuration (with confirmation)
- **`skyg test`** - Test a configuration without switching
- **`skyg rollback`** - Rollback to the previous generation
- **`skyg os <action>`** - Run a local NixOS rebuild. Actions: `test`, `dry-activate`, `run`, `switch`, `build`, `boot`
- **`skyg os rollback`** - Roll back to the previous generation
- **`--build-host <host>`** - Build on a remote builder (e.g. `skyg os switch --build-host fwdesk`)
#### Profile Management
- **`skyg profiles`** - List all available local profiles
- **`skyg profiles --only_remote`** - List only remote profiles (prefixed with `hl-`)
#### Flake Updates
- **`skyg update`** - Update all flakes to their latest versions
- **`skyg update <flake_name>`** - Update a specific flake (e.g., `skyg update nixpkgs`)
Displays the diff of `flake.lock` after updating.
#### Remote Deployments
#### Remote Deployments (`skyg remote`)
- **`skyg remote <command> <target>`** - Deploy to a remote machine
Supported remote commands: `test`, `dry-activate`, `run`, `switch`, `build`
Supported remote commands: `test`, `dry-activate`, `run`, `switch`, `build`, `boot`
Example: `skyg remote switch bigbox1` deploys using the `hl-bigbox1` profile to `root@bigbox1.lab.internal`
- **`skyg remote install <target>`** - Fresh-install a remote host via nixos-anywhere, using `hosts/hl-<target>.disko.nix`. Always wipes the disks in that file. Aborts if the disko file is missing, if the host already boots NixOS from disk (unless `--force-wipe`), or if you don't type the short hostname to confirm.
- **`skyg remote status <target>`** - Check status of a single remote host
- **`skyg remote status --all`** - Check status of all remote hosts (generation, pending reboot, needs rebuild)
- **`skyg remote boot-all`** - Boot all remote hosts (skips the current machine, checks online status first)
- **`skyg remote reboot-pending`** - Find every remote with a pending reboot (its booted system differs from its current system) and reboot them. Lists the affected hosts and asks for confirmation, then reboots them one at a time, waiting for each to come back online and sending a desktop notification when it does.
#### Home Manager
#### Flake Management (`skyg flake`)
- **`skyg flake update [input]`** - Update all flakes, or a specific input (e.g. `skyg flake update nixpkgs`). Displays the diff of `flake.lock` after updating.
- **`skyg flake check`** - Run `nix flake check --no-build`
- **`skyg flake check-versions`** - Verify NixOS release version consistency across flake inputs
#### Building Images and Routers (`skyg build`)
- **`skyg build image <iso|pi1|pi2>`** - Build a bootable image: ISO (`iso`) or Pi SD card image (`pi1`, `pi2`)
- **`skyg build openwrt [router]`** - Deploy an OpenWrt router config (default: `glmain`). Add `--dry-run` to render configs to `.tmp/` without touching the router.
#### Home Manager (`skyg hm`)
- **`skyg hm switch [profile]`** - Apply home-manager configuration (default: `ari`)
- **`skyg hm build [profile]`** - Build home-manager configuration
Example: `skyg hm switch ari` or `skyg hm switch`
#### ISO Images
#### Secrets (`skyg secrets`)
- **`skyg build-iso`** - Build a bootable ISO image
- **`skyg secrets list`** - List known secret names
- **`skyg secrets show <secret>`** - Decrypt a secret to `.tmp/unencrypted-<secret>`
- **`skyg secrets edit <secret> [--yaml]`** - Encrypt a working copy back into the secret
- **`skyg secrets compare <secret>`** - Diff the working copy against the stored secret
#### Lab CA (`skyg ca`)
- **`skyg ca init`** - Generate the lab root CA: key → `secrets/lab-ca-key.age`, cert → `configs/pki/lab-ca.crt`
- **`skyg ca issue <domain> --for <host>`** - Mint a TLS leaf cert signed by the lab CA: cert → `configs/pki/<domain>.crt`, key → `secrets/<name>-tls-key.age`
#### Custom Packages (`skyg pkgs`)
- **`skyg pkgs update --all`** - Auto-detect the latest version for all packages that have `update.sh`
- **`skyg pkgs update <pkg>`** - Auto-detect the latest version for a single package
- **`skyg pkgs update <pkg> <version>`** - Bump a package to an explicit version
#### Other
- **`skyg profiles`** - List all available local profiles
- **`skyg profiles --only_remote`** - List only remote profiles (prefixed with `hl-`)
- **`skyg render html-tpl <file>`** - Render a Gitea `.tmpl` and serve it on `127.0.0.1` for preview. Foreground — Ctrl+C to stop.
## Usage Examples
@@ -102,20 +125,20 @@ Example: `skyg hm switch ari` or `skyg hm switch`
skyg profiles
# Build and switch to new configuration
skyg build
skyg switch
skyg os build
skyg os switch
# Test configuration before switching
skyg test
skyg os test
# Update dependencies
skyg update nixpkgs
skyg flake update nixpkgs
# Deploy to a remote server
skyg remote switch bigbox1
# Rollback if something goes wrong
skyg rollback
skyg os rollback
# Apply home-manager changes
skyg hm switch
@@ -141,7 +164,7 @@ Secrets are encrypted using [agenix](https://github.com/ryantm/agenix) and store
1. **Get the host's SSH public key**: `cat /etc/ssh/ssh_host_ed25519_key.pub`
2. **Add to `secrets.nix`**: Create a variable with the key and add it to each secret's `publicKeys` list
3. **Re-encrypt**: for each affected secret run `skyg decrypt <name>` then `skyg encrypt <name>` to re-encrypt it against the updated key set
3. **Re-encrypt**: for each affected secret run `skyg secrets show <name>` then `skyg secrets edit <name>` to re-encrypt it against the updated key set
For more details, see `secrets/ABOUTME.md`.
@@ -150,7 +173,7 @@ For more details, see `secrets/ABOUTME.md`.
Available profiles include:
- **Local**: `fwbook` (Framework laptop)
- **Remote**: `hl-bigbox1`, `hl-bigbox2`, `hl-fwdesk`, `hl-fws1`, `hl-minipc1`, `hl-minipc2`, `hl-minipc3`, `hl-terra1`
- **Remote**: `hl-bigbox1`, `hl-bigbox2`, `hl-fwdesk`, `hl-fws1`, `hl-minipc1`, `hl-minipc2`, `hl-minipc3`, `hl-pi1`, `hl-pi2`, `hl-terra1`
- **ISO**: `iso` (bootable image)
All profiles automatically have access to the custom packages from the `pkgs/` directory.
+40 -29
View File
@@ -7,42 +7,53 @@ The `skyg` CLI — the single entry point for all system management tasks in thi
```
bin/
├── skyg # Bash shim: exec nu --commands "use lib/cmds.nu *; skyg $*"
├── check-flake-versions # Bash shim for `skyg check-flake-versions`
├── check-flake-versions # Bash shim for `skyg flake check-versions`
├── temp-monitor # NuShell script: collect CPU/GPU temps to CSV + optional graph
├── TEMP_MONITOR_README.md # Usage docs for temp-monitor
└── lib/
├── cmds.nu # Core subcommand implementations (NuShell — source of truth); commands only
├── remote.nu # `skyg remote*` commands (deploy, install, boot-all, status, reboot-pending)
├── helpers.nu # Shared helpers: REPO_ROOT const + internal functions used by commands
├── profile.nu # Profile helpers and tab-completion data
└── types.nu # Type definitions + tab-completion data
├── cmds.nu # Dispatcher + bare `skyg` + `skyg profiles` + deprecated aliases
├── os.nu # `skyg os` (local NixOS rebuild/switch/rollback)
├── remote.nu # `skyg remote *` (deploy, install, boot-all, status, reboot-pending)
├── secrets.nu # `skyg secrets list/show/edit/compare`
├── ca.nu # `skyg ca init/issue`
├── pkgs.nu # `skyg pkgs update`
├── flake.nu # `skyg flake update/check/check-versions`
├── build.nu # `skyg build image/openwrt`
├── render.nu # `skyg render html-tpl`
├── hm.nu # `skyg hm <action>`
├── helpers.nu # Shared helpers: REPO_ROOT const + internal functions
├── profile.nu # Profile helpers and tab-completion data
├── types.nu # Tab-completion completer functions
└── remote.utils.nu # Remote-specific helpers (boot info, wait-for-host, notify)
```
## Key Commands
| Command | Description |
| ------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `skyg os switch` | Rebuild and switch local system |
| `skyg remote switch <host>` | Deploy to a remote host |
| `skyg remote install <host>` | Fresh-install a remote host via nixos-anywhere, using `hosts/<profile>.disko.nix`. Always wipes the disks in that file. Aborts if the file is missing, if the host already boots NixOS from disk (unless `--force-wipe`), or if you do not type the short hostname. |
| `skyg hm switch` | Apply Home Manager config |
| `skyg update [input]` | Update flake inputs |
| `skyg build-image iso | pi1 | pi2` | Build bootable image — ISO (`iso`) or Pi SD card image (`pi1`, `pi2`) |
| `skyg openwrt` | Deploy OpenWrt config |
| `skyg rollback` | Roll back to previous generation |
| `skyg profiles` | List valid local/remote profiles |
| `skyg check` | Run `nix flake check --no-build` |
| `skyg check-flake-versions` | Verify NixOS release version consistency in flake.nix |
| `skyg remote boot-all` | Boot all remote hosts (builds on `fwdesk`) |
| `skyg remote status` | Check status of all remote hosts |
| `skyg remote reboot-pending` | Reboot every remote host with a pending reboot (`booted-system` != `current-system`). Lists them, asks for confirmation, then reboots one at a time, waiting for each to come back online and sending a desktop notification when it does. |
| `skyg secrets` | List known secret names |
| `skyg decrypt <secret>` | Decrypt a secret to `.tmp/unencrypted-<secret>` |
| `skyg encrypt <secret> [--yaml]` | Encrypt a working copy back into the secret |
| `skyg compare-secret <secret>` | Diff the working copy against the stored secret |
| `skyg ca init` | Generate the lab root CA: key → `secrets/lab-ca-key.age`, cert → `configs/pki/lab-ca.crt` (see `configs/pki/ABOUTME.md`) |
| `skyg ca issue <domain> --for <host>` | Mint a TLS leaf cert signed by the lab CA: cert → `configs/pki/<domain>.crt`, key → `secrets/<name>-tls-key.age`. Auto-registers missing `secrets.nix` entries. |
| `skyg render html-tpl <file>` | Render a Gitea `.tmpl` (swaps `base/head`/`base/footer` for a minimal shell, strips `{{ … }}`) and serve it on `127.0.0.1` for preview. Foreground — Ctrl+C to stop. `<file>` tab-completes from `**/*.tmpl`. |
| Command | Description |
| ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `skyg os switch` | Rebuild and switch local system |
| `skyg os rollback` | Roll back to previous generation |
| `skyg remote switch <host>` | Deploy to a remote host |
| `skyg remote install <host>` | Fresh-install a remote host via nixos-anywhere, using `hosts/<profile>.disko.nix`. Always wipes the disks in that file. Aborts if the file is missing, if the host already boots NixOS from disk (unless `--force-wipe`), or if you do not type the short hostname. |
| `skyg remote status <host>` | Check status of a single remote host |
| `skyg remote status --all` | Check status of all remote hosts |
| `skyg remote boot-all` | Boot all remote hosts |
| `skyg remote reboot-pending` | Reboot every remote host with a pending reboot (`booted-system` != `current-system`). Lists them, asks for confirmation, then reboots one at a time, waiting for each to come back online and sending a desktop notification when it does. |
| `skyg hm switch` | Apply Home Manager config |
| `skyg flake update [input]` | Update flake inputs |
| `skyg flake check` | Run `nix flake check --no-build` |
| `skyg flake check-versions` | Verify NixOS release version consistency in flake.nix |
| `skyg build image iso\|pi1\|pi2` | Build bootable image — ISO (`iso`) or Pi SD card image (`pi1`, `pi2`) |
| `skyg build openwrt [router]` | Deploy OpenWrt config |
| `skyg profiles` | List valid local/remote profiles |
| `skyg secrets list` | List known secret names |
| `skyg secrets show <secret>` | Decrypt a secret to `.tmp/unencrypted-<secret>` |
| `skyg secrets edit <secret> [--yaml]` | Encrypt a working copy back into the secret |
| `skyg secrets compare <secret>` | Diff the working copy against the stored secret |
| `skyg ca init` | Generate the lab root CA: key → `secrets/lab-ca-key.age`, cert → `configs/pki/lab-ca.crt` (see `configs/pki/ABOUTME.md`) |
| `skyg ca issue <domain> --for <host>` | Mint a TLS leaf cert signed by the lab CA: cert → `configs/pki/<domain>.crt`, key → `secrets/<name>-tls-key.age`. Auto-registers missing `secrets.nix` entries. |
| `skyg pkgs update [--all\|<pkg>]` | Update one or all custom packages |
| `skyg render html-tpl <file>` | Render a Gitea `.tmpl` and serve it on `127.0.0.1` for preview. Foreground — Ctrl+C to stop. `<file>` tab-completes from `**/*.tmpl`. |
## Agent Note
+1 -1
View File
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
LIB="$SCRIPT_DIR/lib/cmds.nu"
exec nu --commands "use \"$LIB\" *; skyg check-flake-versions"
exec nu --commands "use \"$LIB\" *; skyg flake check-versions"
+35
View File
@@ -0,0 +1,35 @@
use types.nu *
use helpers.nu *
# Build a bootable image: ISO, or Pi SD card image (fully-baked, no on-device rebuild)
export def "skyg build image" [target: string@image-targets] {
cd $REPO_ROOT
let spec = (match $target {
"iso" => { config: "iso", out: "iso", attr: "isoImage" }
"pi1" => { config: "hl-pi1", out: "sd-image", attr: "sdImage" }
"pi2" => { config: "hl-pi2", out: "sd-image", attr: "sdImage" }
_ => { error make { msg: $"Unknown image target '($target)'. Expected: iso, pi1, pi2" } }
})
let imageBuildTime = date now | format date "%Y.%m.%d_%H_%M_%S"
let rootOutputFolder = $REPO_ROOT | path join "build" $spec.config
let outPutFolder = $rootOutputFolder | path join $imageBuildTime
rm -rf $rootOutputFolder
mkdir $rootOutputFolder
nix build $"#nixosConfigurations.($spec.config).config.system.build.($spec.attr)" -o $outPutFolder
printf $outPutFolder
}
# Deploy OpenWrt router configuration
export def "skyg build openwrt" [
router?: string@router-names,
--dry-run # Render configs to .tmp/openwrt-<router>/ without touching the router
] {
cd $REPO_ROOT
let router = $router | default "glmain"
let decrypted_file = skyg secrets show $"($router).json"
if $dry_run {
^cat $decrypted_file | nix run .#openwrt-($router)-dry-run -- ($router)
} else {
^cat $decrypted_file | nix run .#openwrt-($router)
}
}
+73
View File
@@ -0,0 +1,73 @@
use types.nu *
use helpers.nu *
# Generate the lab root CA: key encrypted to secrets/lab-ca-key.age,
# public cert written to configs/pki/lab-ca.crt. Run once, before `ca issue`.
export def "skyg ca init" [
--days: int = 3650 # CA lifetime in days
] {
cd $REPO_ROOT
let cert = "configs/pki/lab-ca.crt"
let key_secret = "secrets/lab-ca-key.age"
if ($cert | path exists) {
error make {msg: $"($cert) already exists — refusing to overwrite the CA. Delete it manually to rotate."}
}
ensure-secret-entry $key_secret ["ari"]
mkdir .tmp configs/pki
let tmp_key = ".tmp/lab-ca-key.pem"
(openssl req -x509 -newkey rsa:4096 -sha256 -days $days -nodes
-keyout $tmp_key -out $cert
-subj "/CN=Skyg Lab CA"
-addext "basicConstraints=critical,CA:TRUE"
-addext "keyUsage=critical,keyCertSign,cRLSign")
^cat $tmp_key | agenix -e $key_secret
rm -f $tmp_key
print $"✅ CA cert: ($cert) — commit this"
print $"✅ CA key encrypted: ($key_secret)"
print "Next: skyg ca issue <domain> --for <host>"
}
# Issue a TLS cert for a domain, signed by the lab CA.
# Writes configs/pki/<domain>.crt; encrypts the key to secrets/<name>-tls-key.age.
export def "skyg ca issue" [
domain: string # e.g. buzz.app.internal
--for: string@ca-recipients # secrets.nix key name allowed to decrypt the leaf key (e.g. minipc1)
--days: int = 825 # leaf lifetime (825 = browser max)
--name: string # secret slug override (default: first DNS label)
] {
cd $REPO_ROOT
let ca_cert = "configs/pki/lab-ca.crt"
let ca_key_secret = "secrets/lab-ca-key.age"
if not ($ca_cert | path exists) {
error make {msg: "No CA found — run `skyg ca init` first"}
}
let key_names = (^cat secrets.nix | parse --regex '(\w+) = "ssh-' | get capture0)
if ($for not-in $key_names) {
error make {msg: $"Unknown recipient '($for)'. Known: ($key_names | str join ', ')"}
}
let slug = $name | default ($domain | split row "." | first)
let secret = $"secrets/($slug)-tls-key.age"
let cert = $"configs/pki/($domain).crt"
if ($cert | path exists) {
error make {msg: $"($cert) already exists — delete it manually to re-issue."}
}
ensure-secret-entry $secret ["ari" $for]
mkdir .tmp configs/pki
let ca_key = ".tmp/lab-ca-key.pem"
agenix -d $ca_key_secret | save -f $ca_key
let leaf_key = $".tmp/($slug)-tls-key.pem"
let csr = $".tmp/($slug).csr"
let ext = $".tmp/($slug)-ext.cnf"
$"basicConstraints=critical,CA:FALSE\nkeyUsage=critical,digitalSignature,keyEncipherment\nextendedKeyUsage=serverAuth\nsubjectAltName=DNS:($domain)\n" | save -f $ext
(openssl req -newkey rsa:2048 -nodes
-keyout $leaf_key -out $csr
-subj $"/CN=($domain)")
(openssl x509 -req -in $csr
-CA $ca_cert -CAkey $ca_key -CAcreateserial
-out $cert -days $days -sha256 -extfile $ext)
^cat $leaf_key | agenix -e $secret
rm -f $ca_key $leaf_key $csr $ext
print $"✅ Cert: ($cert) — commit this"
print $"✅ Key encrypted: ($secret)"
print $"Wire it up: age.secrets.($slug)-tls-key.file = ../($secret);"
}
+53 -341
View File
@@ -2,6 +2,14 @@ use types.nu *
use profile.nu *
use helpers.nu *
export use remote.nu *
export use os.nu *
export use secrets.nu *
export use ca.nu *
export use pkgs.nu *
export use flake.nu *
export use build.nu *
export use render.nu *
export use hm.nu *
export def skyg [] {
print $REPO_ROOT
@@ -21,357 +29,61 @@ export def "skyg profiles" [only_remote: bool = false] {
}
}
export def "skyg check" [] {
nix flake check --no-build
# --- Deprecated aliases (backward compatibility) ---
export def "skyg decrypt" [secret: string@secret-names] {
print $"(ansi yellow)Deprecated: use `skyg secrets show` instead(ansi reset)"
skyg secrets show $secret
}
# Validate that all versioned flake inputs use the same NixOS release
export def "skyg check-flake-versions" [] {
let flake = "flake.nix"
if not ($flake | path exists) {
print "check-flake-versions: flake.nix not found, skipping"
return
}
# Only scan url lines to avoid false positives from embedded script strings
let url_lines = (open $flake | lines | enumerate | where { |row|
($row.item | str contains "url") and ($row.item =~ 'release-\d+\.\d+')
})
let versions = ($url_lines
| each {|row| $row.item | parse --regex '.*release-(?P<version>\d+\.\d+).*' | get version }
| flatten
| uniq)
if ($versions | length) <= 1 {
print "check-flake-versions: OK"
return
}
print "check-flake-versions: mismatched NixOS release versions in flake.nix:"
print ""
for version in $versions {
print $" release-($version):"
$url_lines | where {|row| $row.item | str contains $"release-($version)" } | each { |row|
print $" line ($row.index + 1): ($row.item | str trim)"
}
}
print ""
print "All versioned inputs (home-manager, stylix, etc.) must use the same NixOS release."
error make {msg: "Mismatched NixOS release versions"}
}
# rollback configuration
export def "skyg rollback" [] {
sudo nixos-rebuild switch --rollback
}
# update some flakes
export def "skyg update" [input_name: string = ""] {
cd $REPO_ROOT
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
}
# Build local os
export def "skyg os" [cmd: string, --build-host: string = ""] {
cd $REPO_ROOT
mut runcmd = $"nh os ($cmd)"
if $build_host != "" {
$runcmd = $"($runcmd) --build-host ($build_host).lab.internal"
}
$runcmd | print
bash -c $runcmd
}
# Deploy OpenWrt router configuration
export def "skyg openwrt" [
router: string = "glmain",
--dry-run # Render configs to .tmp/openwrt-<router>/ without touching the router
] {
cd $REPO_ROOT
let decrypted_file = skyg decrypt $"($router).json"
if $dry_run {
^cat $decrypted_file | nix run .#openwrt-($router)-dry-run -- ($router)
} else {
^cat $decrypted_file | nix run .#openwrt-($router)
}
}
# Build a bootable image: ISO, or Pi SD card image (fully-baked, no on-device rebuild)
export def "skyg build-image" [target: string] {
cd $REPO_ROOT
let spec = (match $target {
"iso" => { config: "iso", out: "iso", attr: "isoImage" }
"pi1" => { config: "hl-pi1", out: "sd-image", attr: "sdImage" }
"pi2" => { config: "hl-pi2", out: "sd-image", attr: "sdImage" }
_ => { error make { msg: $"Unknown image target '($target)'. Expected: iso, pi1, pi2" } }
})
let imageBuildTime = date now | format date "%Y.%m.%d_%H_%M_%S"
let rootOutputFolder = $REPO_ROOT | path join "build" $spec.config
let outPutFolder = $rootOutputFolder | path join $imageBuildTime
rm -rf $rootOutputFolder
mkdir $rootOutputFolder
nix build $"#nixosConfigurations.($spec.config).config.system.build.($spec.attr)" -o $outPutFolder
printf $outPutFolder
}
# Home Manager operations
export def "skyg hm" [action: string, profile: string = "ari"] {
cd $REPO_ROOT
$"Running home-manager ($action) for profile ($profile)" | print
home-manager $action --flake $".#($profile)"
}
# List all secret names
export def "skyg secrets" [] {
secret-names
}
# Decrypt a secret from secrets/ folder
export def "skyg decrypt" [secret: string] {
cd $REPO_ROOT
let src = $"secrets/($secret).age"
if not ($src | path exists) {
error make {msg: $"Secret not found: ($src)"}
}
mkdir .tmp
let dest = $".tmp/unencrypted-($secret)"
agenix -d $src | save -f $dest
print $"Decrypted to ($dest)"
return $dest
}
# Encrypt a file to secrets/ folder (re-encrypts using agenix)
# --yaml Validate the content as YAML (via yq) before encrypting
export def "skyg encrypt" [
secret: string@secret-names,
source?: string,
--yaml # Validate the content as YAML (via yq) before encrypting
--yaml
] {
cd $REPO_ROOT
let src = $source | default $".tmp/unencrypted-($secret)"
if not ($src | path exists) {
let encrypted = $"secrets/($secret).age"
if ($encrypted | path exists) {
agenix -d $encrypted | save -f $src
} else {
touch $src
}
}
vi $src
if $yaml {
# `complete` captures stdout/stderr/exit_code; `try/catch` guards a missing yq
let lint = (
try {
yq e '.' $src | complete
} catch { null }
)
if $lint == null {
print $"❌ Could not run yq — is it on PATH? Add 'yq' to the devShell in flake.nix."
return
}
if $lint.exit_code != 0 {
print $"❌ YAML validation failed for ($src):"
print ($lint.stderr | str trim)
print $"Fix the syntax, then re-run: skyg encrypt ($secret) --yaml"
return
}
print $"✅ YAML valid: ($src)"
}
let dest = $"secrets/($secret).age"
cat $src | agenix -e $dest
print $"Encrypted ($dest)"
return $dest
print $"(ansi yellow)Deprecated: use `skyg secrets edit` instead(ansi reset)"
skyg secrets edit $secret $source --yaml=$yaml
}
# Compare unencrypted local version with encrypted version of a secret
export def "skyg compare-secret" [secret: string@secret-names] {
cd $REPO_ROOT
let unencrypted = $".tmp/unencrypted-($secret)"
let encrypted = $"secrets/($secret).age"
let temp_decrypted = $"/tmp/skyg-compare-($secret)-($env.USER)-(random uuid)"
agenix -d $encrypted | save -f $temp_decrypted
print $"Comparing ($unencrypted) with decrypted ($encrypted)"
try {
print $"diff -u $(unencrypted) $(temp_decrypted)"
diff -u $unencrypted $temp_decrypted | print
} catch {
print "Files are identical"
}
rm -f $temp_decrypted
print $"(ansi yellow)Deprecated: use `skyg secrets compare` instead(ansi reset)"
skyg secrets compare $secret
}
# Generate the lab root CA: key encrypted to secrets/lab-ca-key.age,
# public cert written to configs/pki/lab-ca.crt. Run once, before `ca issue`.
export def "skyg ca init" [
--days: int = 3650 # CA lifetime in days
export def "skyg secrets" [] {
print $"(ansi yellow)Deprecated: use `skyg secrets list` instead(ansi reset)"
skyg secrets list
}
export def "skyg rollback" [] {
print $"(ansi yellow)Deprecated: use `skyg os rollback` instead(ansi reset)"
skyg os rollback
}
export def "skyg update" [input_name?: string] {
print $"(ansi yellow)Deprecated: use `skyg flake update` instead(ansi reset)"
skyg flake update $input_name
}
export def "skyg check" [] {
print $"(ansi yellow)Deprecated: use `skyg flake check` instead(ansi reset)"
skyg flake check
}
export def "skyg check-flake-versions" [] {
print $"(ansi yellow)Deprecated: use `skyg flake check-versions` instead(ansi reset)"
skyg flake check-versions
}
export def "skyg build-image" [target: string] {
print $"(ansi yellow)Deprecated: use `skyg build image` instead(ansi reset)"
skyg build image $target
}
export def "skyg openwrt" [
router?: string,
--dry-run
] {
cd $REPO_ROOT
let cert = "configs/pki/lab-ca.crt"
let key_secret = "secrets/lab-ca-key.age"
if ($cert | path exists) {
error make {msg: $"($cert) already exists — refusing to overwrite the CA. Delete it manually to rotate."}
}
ensure-secret-entry $key_secret ["ari"]
mkdir .tmp configs/pki
let tmp_key = ".tmp/lab-ca-key.pem"
(openssl req -x509 -newkey rsa:4096 -sha256 -days $days -nodes
-keyout $tmp_key -out $cert
-subj "/CN=Skyg Lab CA"
-addext "basicConstraints=critical,CA:TRUE"
-addext "keyUsage=critical,keyCertSign,cRLSign")
^cat $tmp_key | agenix -e $key_secret
rm -f $tmp_key
print $"✅ CA cert: ($cert) — commit this"
print $"✅ CA key encrypted: ($key_secret)"
print "Next: skyg ca issue <domain> --for <host>"
}
# Issue a TLS cert for a domain, signed by the lab CA.
# Writes configs/pki/<domain>.crt; encrypts the key to secrets/<name>-tls-key.age.
export def "skyg ca issue" [
domain: string # e.g. buzz.app.internal
--for: string # secrets.nix key name allowed to decrypt the leaf key (e.g. minipc1)
--days: int = 825 # leaf lifetime (825 = browser max)
--name: string # secret slug override (default: first DNS label)
] {
cd $REPO_ROOT
let ca_cert = "configs/pki/lab-ca.crt"
let ca_key_secret = "secrets/lab-ca-key.age"
if not ($ca_cert | path exists) {
error make {msg: "No CA found — run `skyg ca init` first"}
}
let key_names = (^cat secrets.nix | parse --regex '(\w+) = "ssh-' | get capture0)
if ($for not-in $key_names) {
error make {msg: $"Unknown recipient '($for)'. Known: ($key_names | str join ', ')"}
}
let slug = $name | default ($domain | split row "." | first)
let secret = $"secrets/($slug)-tls-key.age"
let cert = $"configs/pki/($domain).crt"
if ($cert | path exists) {
error make {msg: $"($cert) already exists — delete it manually to re-issue."}
}
ensure-secret-entry $secret ["ari" $for]
mkdir .tmp configs/pki
let ca_key = ".tmp/lab-ca-key.pem"
agenix -d $ca_key_secret | save -f $ca_key
let leaf_key = $".tmp/($slug)-tls-key.pem"
let csr = $".tmp/($slug).csr"
let ext = $".tmp/($slug)-ext.cnf"
$"basicConstraints=critical,CA:FALSE\nkeyUsage=critical,digitalSignature,keyEncipherment\nextendedKeyUsage=serverAuth\nsubjectAltName=DNS:($domain)\n" | save -f $ext
(openssl req -newkey rsa:2048 -nodes
-keyout $leaf_key -out $csr
-subj $"/CN=($domain)")
(openssl x509 -req -in $csr
-CA $ca_cert -CAkey $ca_key -CAcreateserial
-out $cert -days $days -sha256 -extfile $ext)
^cat $leaf_key | agenix -e $secret
rm -f $ca_key $leaf_key $csr $ext
print $"✅ Cert: ($cert) — commit this"
print $"✅ Key encrypted: ($secret)"
print $"Wire it up: age.secrets.($slug)-tls-key.file = ../($secret);"
}
# Update one or all packages. With a version, bumps explicitly.
# Without a version, auto-detects the latest from upstream.
#
# skyg pkgs update --all
# skyg pkgs update buzz-desktop
# skyg pkgs update buzz-desktop 0.6.0
export def "skyg pkgs update" [
pkg_name?: string@updatable-pkgs # Package to update (omit with --all)
version?: string # Explicit version (omit for auto-detect)
--all # Update all packages that have update.sh
] {
cd $REPO_ROOT
if $all and $version != null {
error make {msg: "Cannot use --all with a specific version. Run without --all to bump a single package."}
}
let targets = if $all {
updatable-pkgs
} else if $pkg_name != null {
[$pkg_name]
} else {
error make {msg: "Specify a package name or use --all to update all packages"}
}
if ($targets | length) == 0 {
print "No updatable packages found (no pkgs/*/update.sh scripts)"
return
}
print $"Updating ($targets | length) package\(s): ($targets | str join ', ')"
print ""
for pkg in $targets {
let update_script = $"pkgs/($pkg)/update.sh"
if not ($update_script | path exists) {
print $"⚠️ Skipping ($pkg) — no update.sh"
continue
}
print $"=== ($pkg) ==="
cd $"pkgs/($pkg)"
try {
if $version != null {
bash $"update.sh ($version)" | print
} else {
bash "update.sh" | print
}
} catch { |e|
print $"❌ Failed to update ($pkg): ($e)"
}
cd $REPO_ROOT
print ""
}
print ""
if $version != null {
print "Bump complete. Review with:"
git --no-pager diff pkgs/ | print
} else {
print "All updates complete. Review with:"
git --no-pager diff pkgs/ | print
}
}
# Render a Gitea HTML template and serve it locally for preview.
# Runs in the foreground — Ctrl+C to stop. Wrap it in nohup yourself to detach.
export def "skyg render html-tpl" [
file: string@html-tpl-files # Template to render (e.g. hosts/hl-minipc1/services/gitea-home.tmpl)
--port: int = 8787 # Port for the local preview server
] {
cd $REPO_ROOT
let src = ($file | path expand)
if not ($src | path exists) {
error make {msg: $"Template not found: ($file)"}
}
let out_dir = ".tmp/render-html-tpl"
mkdir $out_dir
let name = ($src | path basename | str replace -r '\.tmpl$' '')
let out = $"($out_dir)/($name).html"
render-html-tpl $src $out
print $"Rendered ($file) -> ($out)"
print $"Preview: http://127.0.0.1:($port)/($name).html"
print "Press Ctrl+C to stop."
^python3 -m http.server $port --bind 127.0.0.1 --directory $out_dir
print $"(ansi yellow)Deprecated: use `skyg build openwrt` instead(ansi reset)"
skyg build openwrt $router --dry-run=$dry_run
}
+57
View File
@@ -0,0 +1,57 @@
use types.nu *
use helpers.nu *
# update some flakes
export def "skyg flake update" [input_name?: string@flake-inputs] {
cd $REPO_ROOT
if $input_name == null {
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
}
# Run nix flake check
export def "skyg flake check" [] {
nix flake check --no-build
}
# Validate that all versioned flake inputs use the same NixOS release
export def "skyg flake check-versions" [] {
let flake = "flake.nix"
if not ($flake | path exists) {
print "check-versions: flake.nix not found, skipping"
return
}
# Only scan url lines to avoid false positives from embedded script strings
let url_lines = (open $flake | lines | enumerate | where { |row|
($row.item | str contains "url") and ($row.item =~ 'release-\d+\.\d+')
})
let versions = ($url_lines
| each {|row| $row.item | parse --regex '.*release-(?P<version>\d+\.\d+).*' | get version }
| flatten
| uniq)
if ($versions | length) <= 1 {
print "check-versions: OK"
return
}
print "check-versions: mismatched NixOS release versions in flake.nix:"
print ""
for version in $versions {
print $" release-($version):"
$url_lines | where {|row| $row.item | str contains $"release-($version)" } | each { |row|
print $" line ($row.index + 1): ($row.item | str trim)"
}
}
print ""
print "All versioned inputs (home-manager, stylix, etc.) must use the same NixOS release."
error make {msg: "Mismatched NixOS release versions"}
}
+13
View File
@@ -0,0 +1,13 @@
use types.nu *
use profile.nu *
use helpers.nu *
# Home Manager operations
export def "skyg hm" [
action: string@hm-actions,
profile: string@valid_profiles = "ari",
] {
cd $REPO_ROOT
$"Running home-manager ($action) for profile ($profile)" | print
home-manager $action --flake $".#($profile)"
}
+22
View File
@@ -0,0 +1,22 @@
use types.nu *
use profile.nu *
use helpers.nu *
# Build local os
export def "skyg os" [
cmd: string@os-actions,
--build-host: string@remote_targets = "",
] {
cd $REPO_ROOT
mut runcmd = $"nh os ($cmd)"
if $build_host != "" {
$runcmd = $"($runcmd) --build-host ($build_host).lab.internal"
}
$runcmd | print
bash -c $runcmd
}
# rollback configuration
export def "skyg os rollback" [] {
sudo nixos-rebuild switch --rollback
}
+67
View File
@@ -0,0 +1,67 @@
use types.nu *
use helpers.nu *
# Update one or all packages. With a version, bumps explicitly.
# Without a version, auto-detects the latest from upstream.
#
# skyg pkgs update --all
# skyg pkgs update buzz-desktop
# skyg pkgs update buzz-desktop 0.6.0
export def "skyg pkgs update" [
pkg_name?: string@updatable-pkgs # Package to update (omit with --all)
version?: string # Explicit version (omit for auto-detect)
--all # Update all packages that have update.sh
] {
cd $REPO_ROOT
if $all and $version != null {
error make {msg: "Cannot use --all with a specific version. Run without --all to bump a single package."}
}
let targets = if $all {
updatable-pkgs
} else if $pkg_name != null {
[$pkg_name]
} else {
error make {msg: "Specify a package name or use --all to update all packages"}
}
if ($targets | length) == 0 {
print "No updatable packages found (no pkgs/*/update.sh scripts)"
return
}
print $"Updating ($targets | length) package\(s): ($targets | str join ', ')"
print ""
for pkg in $targets {
let update_script = $"pkgs/($pkg)/update.sh"
if not ($update_script | path exists) {
print $"⚠️ Skipping ($pkg) — no update.sh"
continue
}
print $"=== ($pkg) ==="
cd $"pkgs/($pkg)"
try {
if $version != null {
bash $"update.sh ($version)" | print
} else {
bash "update.sh" | print
}
} catch { |e|
print $"❌ Failed to update ($pkg): ($e)"
}
cd $REPO_ROOT
print ""
}
print ""
if $version != null {
print "Bump complete. Review with:"
git --no-pager diff pkgs/ | print
} else {
print "All updates complete. Review with:"
git --no-pager diff pkgs/ | print
}
}
+13 -4
View File
@@ -5,7 +5,7 @@ use remote.utils.nu *
# Deploy to remote machine
export def "skyg remote" [
cmd: string@remote-cmds,
cmd: string@os-actions,
target: string@remote_targets = "",
--build-host: string@remote_targets = "", # Optional remote builder host (e.g. builder.lab.internal)
] {
@@ -183,12 +183,21 @@ Report written to ($report_file)"
print $report
}
export def "skyg remote status" [ target: string@remote_targets ] {
get-remote-boot-info $target
export def "skyg remote status" [
target?: string@remote_targets,
--all # Check status of all remote hosts
] {
if $all {
skyg remote status-all
} else if $target != null {
get-remote-boot-info $target
} else {
error make {msg: "Specify a target host or use --all"}
}
}
# Check status of all remotes: generation, pending reboot, needs rebuild
export def "skyg remote status all" [] {
export def "skyg remote status-all" [] {
cd $REPO_ROOT
mkdir .tmp
let current_host = "fwbook"
+27
View File
@@ -0,0 +1,27 @@
use types.nu *
use helpers.nu *
# Render a Gitea HTML template and serve it locally for preview.
# Runs in the foreground — Ctrl+C to stop. Wrap it in nohup yourself to detach.
export def "skyg render html-tpl" [
file: string@html-tpl-files # Template to render (e.g. hosts/hl-minipc1/services/gitea-home.tmpl)
--port: int = 8787 # Port for the local preview server
] {
cd $REPO_ROOT
let src = ($file | path expand)
if not ($src | path exists) {
error make {msg: $"Template not found: ($file)"}
}
let out_dir = ".tmp/render-html-tpl"
mkdir $out_dir
let name = ($src | path basename | str replace -r '\.tmpl$' '')
let out = $"($out_dir)/($name).html"
render-html-tpl $src $out
print $"Rendered ($file) -> ($out)"
print $"Preview: http://127.0.0.1:($port)/($name).html"
print "Press Ctrl+C to stop."
^python3 -m http.server $port --bind 127.0.0.1 --directory $out_dir
}
+86
View File
@@ -0,0 +1,86 @@
use types.nu *
use helpers.nu *
# List all secret names
export def "skyg secrets list" [] {
secret-names
}
# Decrypt a secret from secrets/ folder
export def "skyg secrets show" [secret: string@secret-names] {
cd $REPO_ROOT
let src = $"secrets/($secret).age"
if not ($src | path exists) {
error make {msg: $"Secret not found: ($src)"}
}
mkdir .tmp
let dest = $".tmp/unencrypted-($secret)"
agenix -d $src | save -f $dest
print $"Decrypted to ($dest)"
return $dest
}
# Encrypt a file to secrets/ folder (re-encrypts using agenix)
# --yaml Validate the content as YAML (via yq) before encrypting
export def "skyg secrets edit" [
secret: string@secret-names,
source?: string,
--yaml # Validate the content as YAML (via yq) before encrypting
] {
cd $REPO_ROOT
let src = $source | default $".tmp/unencrypted-($secret)"
if not ($src | path exists) {
let encrypted = $"secrets/($secret).age"
if ($encrypted | path exists) {
agenix -d $encrypted | save -f $src
} else {
touch $src
}
}
vi $src
if $yaml {
# `complete` captures stdout/stderr/exit_code; `try/catch` guards a missing yq
let lint = (
try {
yq e '.' $src | complete
} catch { null }
)
if $lint == null {
print $"❌ Could not run yq — is it on PATH? Add 'yq' to the devShell in flake.nix."
return
}
if $lint.exit_code != 0 {
print $"❌ YAML validation failed for ($src):"
print ($lint.stderr | str trim)
print $"Fix the syntax, then re-run: skyg secrets edit ($secret) --yaml"
return
}
print $"✅ YAML valid: ($src)"
}
let dest = $"secrets/($secret).age"
cat $src | agenix -e $dest
print $"Encrypted ($dest)"
return $dest
}
# Compare unencrypted local version with encrypted version of a secret
export def "skyg secrets compare" [secret: string@secret-names] {
cd $REPO_ROOT
let unencrypted = $".tmp/unencrypted-($secret)"
let encrypted = $"secrets/($secret).age"
let temp_decrypted = $"/tmp/skyg-compare-($secret)-($env.USER)-(random uuid)"
agenix -d $encrypted | save -f $temp_decrypted
print $"Comparing ($unencrypted) with decrypted ($encrypted)"
try {
print $"diff -u $(unencrypted) $(temp_decrypted)"
diff -u $unencrypted $temp_decrypted | print
} catch {
print "Files are identical"
}
rm -f $temp_decrypted
}
+23 -1
View File
@@ -4,7 +4,7 @@ export def hm-actions [] {
["switch", "build"]
}
export def remote-cmds [] {
export def os-actions [] {
[
"test"
"dry-activate"
@@ -37,3 +37,25 @@ export def html-tpl-files [] {
| each {|f| $f | path relative-to $REPO_ROOT }
| sort
}
# Flake input names from flake.nix
export def flake-inputs [] {
cd $REPO_ROOT
open flake.nix
| lines
| where {|l| $l =~ '^\s+\w+\.url\s*=' }
| each {|l| $l | str trim | split row "." | first }
| uniq
}
# OpenWrt router names from openwrt-routers/*.nix
export def router-names [] {
cd $REPO_ROOT
glob openwrt-routers/*.nix | each {|f| $f | path basename | str replace ".nix" "" }
}
# CA recipient names from secrets.nix
export def ca-recipients [] {
cd $REPO_ROOT
^cat secrets.nix | parse --regex '(\w+) = "ssh-' | get capture0
}
+1 -1
View File
@@ -29,9 +29,9 @@ Packages here are exposed via an overlay defined in `modules/core/default.nix`.
Each package can have an `update.sh` script that automates version bumps.
- **`skyg pkgs bump <pkg-name> <version>`** — bump a specific package to a specific version.
- **`skyg pkgs update --all`** — auto-detect the latest version for all packages that have `update.sh`.
- **`skyg pkgs update <pkg-name>`** — auto-detect the latest version for a single package.
- **`skyg pkgs update <pkg-name> <version>`** — bump a specific package to a specific version.
Each `update.sh` supports two modes:
+2 -2
View File
@@ -23,11 +23,11 @@
let
pname = "buzz-desktop";
version = "0.5.27";
version = "0.5.28";
src = fetchurl {
url = "https://github.com/block/buzz/releases/download/desktop-v${version}/Buzz_${version}_amd64.AppImage";
hash = "sha256-GVlFK6n3yCuMZH0fySHrZSqQ4AdypGq9q9yr1o2tmyg=";
hash = "sha256-YCI6wn2HQiJqC149teH5dEGyZ/9jq7kFeTsz/mVoh0w=";
};
extracted = appimageTools.extractType2 {
+2 -2
View File
@@ -29,7 +29,7 @@
let
pname = "delta-editor";
version = "0.19.2";
version = "0.20.1";
apiUrl = "https://delta.dev/api/releases/nightly/${version}/asset?asset=delta&os=linux&arch=x86_64";
@@ -38,7 +38,7 @@ let
inherit version;
outputHashMode = "flat";
outputHash = "sha256-gtSFnzH45o0DBx/vyx0N8cUQkvZwSc8lNcPlrQ0MIYI=";
outputHash = "sha256-97/XaIOQo5ni077fRErzfN2IK5jh5PjxFE1vK5Z7Oco=";
nativeBuildInputs = [ curl jq cacert ];
SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt";
+2 -2
View File
@@ -23,11 +23,11 @@
let
pname = "superset-desktop";
version = "1.37.0";
version = "1.38.0";
src = fetchurl {
url = "https://github.com/superset-sh/superset/releases/download/desktop-v${version}/superset-${version}-x86_64.AppImage";
hash = "sha256-kWVH+BsZxUGgHwWL6RjjhRjHQ7+vH4LEIM1FAdsGyKo=";
hash = "sha256-F0Dka9zVsbtsPlmSgaQo/hh2z4qc9Sf/cOIV5HubrSw=";
};
extracted = appimageTools.extractType2 {