diff --git a/bin/ABOUTME.md b/bin/ABOUTME.md index d75ecf1..14f3162 100644 --- a/bin/ABOUTME.md +++ b/bin/ABOUTME.md @@ -22,6 +22,7 @@ bin/ |---|---| | `skyg os switch` | Rebuild and switch local system | | `skyg remote switch ` | Deploy to a remote host | +| `skyg remote install ` | Fresh-install a remote host via nixos-anywhere, using `hosts/.disko.nix` (errors if that file is missing) | | `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`) | diff --git a/bin/lib/cmds.nu b/bin/lib/cmds.nu index c3f42b6..5fd31f7 100644 --- a/bin/lib/cmds.nu +++ b/bin/lib/cmds.nu @@ -118,6 +118,28 @@ export def "skyg remote" [ bash -c $runcmd } +# Fresh-install a remote machine via nixos-anywhere, using its disko config +# Errors out if hosts/.disko.nix is missing — refuses to wipe a disk blind +export def "skyg remote install" [ + target: string@remote_targets, +] { + cd $REPO_ROOT + let target_host = $"root@($target).lab.internal" + let profile = $"hl-($target)" + if not (is-valid-profile $profile true) { + print $"Invalid Remote Profile '(ansi green_bold)($target)(ansi reset)', please select one of:" + return (remote_targets) + } + let disko_file = $"hosts/($profile).disko.nix" + if not ($disko_file | path exists) { + error make { msg: $"Missing disko config: ($disko_file). Refusing to install ($profile) without a disko layout." } + } + $"Installing [(ansi green_bold)($profile)(ansi reset)] on ($target_host) via nixos-anywhere, using ($disko_file)" | print + let runcmd = $"nix run github:nix-community/nixos-anywhere -- --flake .#($profile) ($target_host)" + $runcmd | print + bash -c $runcmd +} + # Boot all remote hosts except the current machine (fwbook) # Checks online status first, runs `skyg remote boot --build-host fwdesk ` for each online host, # and writes a summary report to .tmp/boot-report.txt diff --git a/flake.lock b/flake.lock index ef8b2e2..f9ca32f 100644 --- a/flake.lock +++ b/flake.lock @@ -270,6 +270,26 @@ "url": "https://install.determinate.systems/determinate-nixd/tag/v3.22.0/x86_64-linux" } }, + "disko": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1781152676, + "narHash": "sha256-RxWs5ND31KzTG7wvMM+PMfUjyNpmIEr999lqNARaM5o=", + "owner": "nix-community", + "repo": "disko", + "rev": "ff8702b4de27f72b4c78573dfb89ec74e36abdf1", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "disko", + "type": "github" + } + }, "dms": { "inputs": { "flake-compat": "flake-compat_2", @@ -1710,6 +1730,7 @@ "agenix": "agenix", "claude-desktop": "claude-desktop", "determinate": "determinate", + "disko": "disko", "dms": "dms", "flox": "flox", "git-hooks": "git-hooks", diff --git a/flake.nix b/flake.nix index 6560327..78ab1c1 100644 --- a/flake.nix +++ b/flake.nix @@ -65,6 +65,11 @@ inputs.nixpkgs.follows = "nixpkgs"; }; herdr.url = "github:herdrdev/herdr"; + # Declarative disk partitioning (for nixos-anywhere installs) + disko = { + url = "github:nix-community/disko"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; outputs = { self @@ -89,6 +94,7 @@ , tether , herdr , claude-desktop + , disko }: let # Libs @@ -237,7 +243,9 @@ configuration = [ ./hosts/hl-fws1.nix ./hosts/hl-fws1.hardware-configuration.nix + ./hosts/hl-fws1.disko.nix nixos-hardware.nixosModules.framework-11th-gen-intel + disko.nixosModules.disko ]; }; hl-fwdesk = lib.makeNixOs { diff --git a/hosts/ABOUTME.md b/hosts/ABOUTME.md index 5b23c40..fd8638f 100644 --- a/hosts/ABOUTME.md +++ b/hosts/ABOUTME.md @@ -8,6 +8,8 @@ One NixOS configuration file per managed machine, plus hardware configs and host hosts/ ├── .nix # Host configuration (packages, services, options) ├── .hardware-configuration.nix # Generated by nixos-generate-config — DO NOT EDIT +├── .disko.nix # Optional: declarative disk layout for `skyg remote install` (nixos-anywhere). +│ # Only present for hosts installed/reinstalled this way (currently: hl-fws1) └── scripts/ ├── fwbook/ # fwbook-specific shell scripts │ ├── functions.sh # ZSH functions sourced at shell startup @@ -37,5 +39,6 @@ hosts/ - **Do not add `imports = [...]`** to host files — module composition happens in `flake.nix` via `modules/main.nix` - **Do not edit `*.hardware-configuration.nix`** — these are generated and will be overwritten +- Hosts with a `.disko.nix` own their `fileSystems` via disko; if a generated `hardware-configuration.nix` still contains its own `fileSystems` stanzas for the same host, that's a conflict the machine's owner needs to resolve by hand (regenerating or trimming it) — not something to script around - Host-specific packages and one-off settings belong here; anything reused across hosts belongs in `modules/` - See `docs/hosts/README.md` for full per-host service/port/package reference diff --git a/hosts/hl-fws1.disko.nix b/hosts/hl-fws1.disko.nix new file mode 100644 index 0000000..7819d95 --- /dev/null +++ b/hosts/hl-fws1.disko.nix @@ -0,0 +1,49 @@ +{ + disko.devices = { + disk = { + main = { + device = "/dev/nvme0n1"; + type = "disk"; + content = { + type = "gpt"; + partitions = { + ESP = { + size = "1G"; + type = "EF00"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + mountOptions = [ "umask=0077" ]; + }; + }; + swap = { + size = "80G"; + content = { + type = "swap"; + }; + }; + root = { + size = "100%"; + content = { + type = "btrfs"; + extraArgs = [ "-f" ]; + subvolumes = { + "@" = { + mountpoint = "/"; + }; + "@home" = { + mountpoint = "/home"; + }; + "@nix" = { + mountpoint = "/nix"; + }; + }; + }; + }; + }; + }; + }; + }; + }; +} diff --git a/hosts/hl-fws1.hardware-configuration.nix b/hosts/hl-fws1.hardware-configuration.nix index e239446..aacb676 100644 --- a/hosts/hl-fws1.hardware-configuration.nix +++ b/hosts/hl-fws1.hardware-configuration.nix @@ -13,23 +13,6 @@ boot.initrd.kernelModules = [ ]; boot.kernelModules = [ "kvm-intel" ]; boot.extraModulePackages = [ ]; - - fileSystems."/" = - { - device = "/dev/disk/by-uuid/3fbf3ccf-655a-4040-b898-b97a1d555912"; - fsType = "ext4"; - }; - - fileSystems."/boot" = - { - device = "/dev/disk/by-uuid/3342-B2BE"; - fsType = "vfat"; - }; - - swapDevices = [{ - device = "/var/lib/swapfile"; - size = 64 * 1024; - }]; nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; }