From 973bac7ed04f4786c27ecda861fe761fa2fbe528 Mon Sep 17 00:00:00 2001 From: randogoth Date: Wed, 4 Feb 2026 15:57:45 +0200 Subject: [PATCH] feat(install): add disko direct-url workflow --- docs/install-help.txt | 33 +++++++--- flake.lock | 21 +++++++ flake.nix | 4 ++ hosts/nanuqsaurus-hardware.nix | 14 +++++ hosts/nanuqsaurus.nix | 4 +- modules/system/disko-btrfs.nix | 58 +++++++++++++++++ scripts/install-btrfs.sh | 110 +++++++++------------------------ templates/home-home.nix | 2 +- 8 files changed, 154 insertions(+), 92 deletions(-) create mode 100644 hosts/nanuqsaurus-hardware.nix create mode 100644 modules/system/disko-btrfs.nix diff --git a/docs/install-help.txt b/docs/install-help.txt index be06afd..2f37fe8 100644 --- a/docs/install-help.txt +++ b/docs/install-help.txt @@ -1,22 +1,37 @@ Nanuqsaurus NixOS installer =========================== -Run the non-interactive installer: +Direct-from-URL install (wipes the whole disk) +--------------------------------------------- + +Pick a stable disk path (prefer /dev/disk/by-id/*) and run: + + sudo nix --experimental-features "nix-command flakes" \ + run github:nix-community/disko/latest#disko-install -- \ + --mode format \ + --flake "git+https://codeberg.org//.git#nanuqsaurus" \ + --disk main /dev/disk/by-id/ \ + --mount-point /mnt + + +ISO shortcut +------------ + +If you are using the custom ISO from this repo, it embeds the flake at /etc/nixos. +You can run the wrapper script (defaults: DISK=/dev/vda, TARGET_HOST=nanuqsaurus): sudo /etc/nixos/scripts/install-btrfs.sh -Optionally set DISK and TARGET_HOST (defaults: DISK=/dev/vda, TARGET_HOST=nanuqsaurus) +Optionally set DISK, TARGET_HOST, and FLAKE: - sudo DISK=/dev/vda TARGET_HOST=nanuqsaurus /etc/nixos/scripts/install-btrfs.sh + sudo DISK=/dev/disk/by-id/ TARGET_HOST=nanuqsaurus \ + FLAKE="github:/" \ + /etc/nixos/scripts/install-btrfs.sh -The script wipes the whole disk, creates Btrfs subvolumes (root, home, nix), copies the flake, generates hardware config, and installs. It writes host files under `/etc/nixos/hosts/local-.nix` and `local--hardware.nix` (kept local to the machine). - - -If you need a more custom setup please run the partitioning manually, mount the target to /mnt and then install the system: - - nixos-install --root /mnt --flake "/mnt/etc/nixos#local-${TARGET_HOST}" --no-root-passwd +This uses disko to create a GPT disk with a 550M EFI partition and a Btrfs partition +containing subvolumes root, home, and nix, mounted with compress=zstd. After install finishes, reboot into the new system. diff --git a/flake.lock b/flake.lock index e9388b4..3426ca1 100644 --- a/flake.lock +++ b/flake.lock @@ -30,6 +30,26 @@ "type": "github" } }, + "disko": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1769524058, + "narHash": "sha256-zygdD6X1PcVNR2PsyK4ptzrVEiAdbMqLos7utrMDEWE=", + "owner": "nix-community", + "repo": "disko", + "rev": "71a3fc97d80881e91710fe721f1158d3b96ae14d", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "disko", + "type": "github" + } + }, "fenix": { "inputs": { "nixpkgs": [ @@ -359,6 +379,7 @@ }, "root": { "inputs": { + "disko": "disko", "flox": "flox", "lanzaboote": "lanzaboote", "lix-module": "lix-module", diff --git a/flake.nix b/flake.nix index 2520d63..313eded 100644 --- a/flake.nix +++ b/flake.nix @@ -3,6 +3,10 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11"; + disko = { + url = "github:nix-community/disko"; + inputs.nixpkgs.follows = "nixpkgs"; + }; nix-index-database = { url = "github:nix-community/nix-index-database"; inputs.nixpkgs.follows = "nixpkgs"; diff --git a/hosts/nanuqsaurus-hardware.nix b/hosts/nanuqsaurus-hardware.nix new file mode 100644 index 0000000..70d11f2 --- /dev/null +++ b/hosts/nanuqsaurus-hardware.nix @@ -0,0 +1,14 @@ +{ config, lib, modulesPath, ... }: + +{ + imports = [ + (modulesPath + "/profiles/qemu-guest.nix") + ]; + + boot.initrd.availableKernelModules = [ "ahci" "xhci_pci" "virtio_pci" "sr_mod" "virtio_blk" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ "kvm-intel" ]; + boot.extraModulePackages = [ ]; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; +} diff --git a/hosts/nanuqsaurus.nix b/hosts/nanuqsaurus.nix index 93c2c1d..58edbff 100644 --- a/hosts/nanuqsaurus.nix +++ b/hosts/nanuqsaurus.nix @@ -8,11 +8,13 @@ { imports = [ + inputs.disko.nixosModules.disko inputs.lix-module.nixosModules.lixFromNixpkgs inputs.nix-index-database.nixosModules.nix-index inputs.nix-flatpak.nixosModules.nix-flatpak ../modules/system/flatpak.nix ../modules/system/base.nix + ../modules/system/disko-btrfs.nix ../modules/system/packages.nix ../modules/system/shell.nix ../modules/system/home-manager-skel.nix @@ -23,8 +25,6 @@ ../modules/desktop/gnome-minimal.nix ../modules/development/flox.nix ../modules/users/admin.nix - ] - ++ lib.optionals (builtins.pathExists ./nanuqsaurus-hardware.nix) [ ./nanuqsaurus-hardware.nix ]; diff --git a/modules/system/disko-btrfs.nix b/modules/system/disko-btrfs.nix new file mode 100644 index 0000000..1e8bfa1 --- /dev/null +++ b/modules/system/disko-btrfs.nix @@ -0,0 +1,58 @@ +{ lib, ... }: + +{ + disko.devices = { + disk.main = { + type = "disk"; + device = lib.mkDefault "/dev/vda"; + content = { + type = "gpt"; + partitions = { + ESP = { + size = "550M"; + type = "EF00"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + mountOptions = [ + "fmask=0022" + "dmask=0022" + ]; + }; + }; + + nixos = { + size = "100%"; + content = { + type = "btrfs"; + extraArgs = [ "-f" ]; + subvolumes = { + root = { + mountpoint = "/"; + mountOptions = [ + "compress=zstd" + ]; + }; + + home = { + mountpoint = "/home"; + mountOptions = [ + "compress=zstd" + ]; + }; + + nix = { + mountpoint = "/nix"; + mountOptions = [ + "compress=zstd" + ]; + }; + }; + }; + }; + }; + }; + }; + }; +} diff --git a/scripts/install-btrfs.sh b/scripts/install-btrfs.sh index d47a8f2..269710a 100755 --- a/scripts/install-btrfs.sh +++ b/scripts/install-btrfs.sh @@ -1,17 +1,18 @@ #!/usr/bin/env bash set -euo pipefail -# Non-interactive Btrfs installer using the flake in this repo. +# Non-interactive Btrfs installer using disko-install. # Defaults: DISK=/dev/vda TARGET_HOST=nanuqsaurus +# If FLAKE is unset and /etc/nixos/flake.nix exists, it uses /etc/nixos. +# Otherwise, set FLAKE to a flake URI like: +# - git+https://codeberg.org//.git +# - github:/ DISK="${DISK:-/dev/vda}" TARGET_HOST="${TARGET_HOST:-nanuqsaurus}" - -SCRIPT_DIR="$(cd -- "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -REPO_ROOT="$(cd -- "$SCRIPT_DIR/.." && pwd)" +FLAKE="${FLAKE:-}" MNT=/mnt -EFI_SIZE=550M have() { command -v "$1" >/dev/null 2>&1; } @@ -27,85 +28,34 @@ confirm_disk() { sleep 5 } +resolve_flake() { + if [[ -n "$FLAKE" ]]; then + return 0 + fi + + if [[ -e /etc/nixos/flake.nix ]]; then + FLAKE=/etc/nixos + return 0 + fi + + die "FLAKE is unset. Set FLAKE to a flake URI (or run from an ISO that provides /etc/nixos)." +} + clear confirm_disk +resolve_flake -echo "[1/7] Partitioning ${DISK}" -sfdisk "$DISK" < "$HW_FILE" - -if [[ ! -e "$HOST_FILE" ]]; then - cat > "$HOST_FILE" <