From 81237e88b06edf81d5f0d91ebed6ae61a99b65f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vili=20Sinerv=C3=A4?= Date: Mon, 9 Jun 2025 00:16:35 +0300 Subject: [PATCH] Create new install system with disko --- flake.lock | 21 +++++++ flake.nix | 14 ++++- hosts/installer-minimal/configuration.nix | 25 ++++++++ hosts/installer-minimal/state.nix | 1 + installer/base.nix | 72 ----------------------- installer/graphical.nix | 7 --- installer/minimal.nix | 9 --- shared/disko/basic-ext4.nix | 35 +++++++++++ 8 files changed, 95 insertions(+), 89 deletions(-) create mode 100644 hosts/installer-minimal/configuration.nix create mode 100644 hosts/installer-minimal/state.nix delete mode 100644 installer/base.nix delete mode 100644 installer/graphical.nix delete mode 100644 installer/minimal.nix create mode 100644 shared/disko/basic-ext4.nix diff --git a/flake.lock b/flake.lock index fdfe92f..650fa6c 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,25 @@ { "nodes": { + "disko": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1749200714, + "narHash": "sha256-W8KiJIrVwmf43JOPbbTu5lzq+cmdtRqaNbOsZigjioY=", + "owner": "nix-community", + "repo": "disko", + "rev": "17d08c65c241b1d65b3ddf79e3fac1ddc870b0f6", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "disko", + "type": "github" + } + }, "flake-parts": { "inputs": { "nixpkgs-lib": [ @@ -131,6 +151,7 @@ }, "root": { "inputs": { + "disko": "disko", "nixpkgs": "nixpkgs", "nixvim": "nixvim" } diff --git a/flake.nix b/flake.nix index fb8afa1..22114f7 100644 --- a/flake.nix +++ b/flake.nix @@ -7,10 +7,19 @@ url = "github:nix-community/nixvim"; inputs.nixpkgs.follows = "nixpkgs"; }; + disko = { + url = "github:nix-community/disko"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; outputs = - { nixpkgs, nixvim, ... }: + { + nixpkgs, + nixvim, + disko, + ... + }: { nixosConfigurations = ( @@ -27,10 +36,12 @@ specialArgs = { nixpkgs-flake = nixpkgs; inherit nixvim; + inherit disko; }; system = "x86_64-linux"; modules = [ { networking.hostName = host; } + disko.nixosModules.disko ./hosts/${host}/configuration.nix ./hosts/${host}/state.nix ]; @@ -51,6 +62,7 @@ specialArgs = { nixpkgs-flake = nixpkgs; inherit nixvim; + inherit disko; }; system = "aarch64-linux"; modules = [ diff --git a/hosts/installer-minimal/configuration.nix b/hosts/installer-minimal/configuration.nix new file mode 100644 index 0000000..d4a4c5a --- /dev/null +++ b/hosts/installer-minimal/configuration.nix @@ -0,0 +1,25 @@ +{ + pkgs, + lib, + nixpkgs-flake, + ... +}: +{ + imports = [ + "${nixpkgs-flake}/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix" + ../../shared/base.nix + ]; + + environment.systemPackages = ( + with pkgs; + [ + cryptsetup + ] + ); + + isoImage.squashfsCompression = "gzip -Xcompression-level 1"; + networking.networkmanager.enable = lib.mkForce false; + + #Many installs will need this, and it won't hurt either way + services.qemuGuest.enable = true; +} diff --git a/hosts/installer-minimal/state.nix b/hosts/installer-minimal/state.nix new file mode 100644 index 0000000..ffcd441 --- /dev/null +++ b/hosts/installer-minimal/state.nix @@ -0,0 +1 @@ +{ } diff --git a/installer/base.nix b/installer/base.nix deleted file mode 100644 index 237b949..0000000 --- a/installer/base.nix +++ /dev/null @@ -1,72 +0,0 @@ -{ pkgs, ... }: -let - create-partitions = pkgs.writeScriptBin "create-partitions" '' - if [[ $# -ne 3 ]] - then - echo "Usage: create-partitions " - exit - fi - - read -p "Erasing disk $1 -- Creating partition $1$2 as BOOT -- Creating partition $1$3 as root -- Are you sure? " -n 1 -r - echo - if [[ $REPLY =~ ^[Yy]$ ]] - then - parted $1 -- mklabel gpt - parted $1 -- mkpart ESP fat32 1MB 512MB - parted $1 -- set 1 esp on - parted $1 -- mkpart root ext4 512MB 100% - fi - - read -p "Setup root partition encryption?" -n 1 -r - echo - if [[ $REPLY =~ ^[Yy]$ ]] - then - cryptsetup luksFormat $1$3 - if cryptsetup open $1$3 nixos - then - echo "Encrypted device accessible via /dev/mapper/nixos" - fi - fi - ''; - create-filesystems = pkgs.writeScriptBin "create-filesystems" '' - if [[ $# -ne 2 ]] - then - echo "Usage: create-filesystems " - exit - fi - - mkfs.fat -F 32 -n BOOT $1 - mkfs.ext4 -L nixos $2 - ''; - prep-install = pkgs.writeScriptBin "prep-install" '' - mkdir /mnt - mount /dev/disk/by-label/nixos /mnt - mkdir /mnt/boot - mount -o umask=077 /dev/disk/by-label/BOOT /mnt/boot - - nixos-generate-config --root /mnt - mv /mnt/etc/nixos/configuration.nix configuration.nix.old - curl https://forgejo.sinerva.eu/VSinerva/nixos-conf/raw/branch/main/installer/template-configuration.nix -o /mnt/etc/nixos/configuration.nix - ''; -in -{ - imports = [ - - ../base.nix - ]; - - environment.systemPackages = - (with pkgs; [ - cryptsetup - ]) - ++ [ - create-partitions - create-filesystems - prep-install - ]; - - isoImage.squashfsCompression = "gzip -Xcompression-level 1"; - - #Many installs will need this, and it won't hurt either way - services.qemuGuest.enable = true; -} diff --git a/installer/graphical.nix b/installer/graphical.nix deleted file mode 100644 index dfd8bec..0000000 --- a/installer/graphical.nix +++ /dev/null @@ -1,7 +0,0 @@ -{ ... }: -{ - imports = [ - - ./base.nix - ]; -} diff --git a/installer/minimal.nix b/installer/minimal.nix deleted file mode 100644 index 30f4160..0000000 --- a/installer/minimal.nix +++ /dev/null @@ -1,9 +0,0 @@ -{ lib, ... }: -{ - imports = [ - - ./base.nix - ]; - - networking.networkmanager.enable = lib.mkForce false; -} diff --git a/shared/disko/basic-ext4.nix b/shared/disko/basic-ext4.nix new file mode 100644 index 0000000..3b23e20 --- /dev/null +++ b/shared/disko/basic-ext4.nix @@ -0,0 +1,35 @@ +{ + disko.devices = { + disk = { + main-disk = { + device = "/dev/sda"; + type = "disk"; + content = { + type = "gpt"; + partitions = { + ESP = { + name = "boot"; + type = "EF00"; + size = "512M"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + mountOptions = [ "umask=0077" ]; + }; + }; + root = { + name = "nixos"; + size = "100%"; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/"; + }; + }; + }; + }; + }; + }; + }; +}