Create new install system with disko

This commit is contained in:
Vili Sinervä 2025-06-09 00:16:35 +03:00
parent 29c9b505d1
commit 81237e88b0
Signed by: Vili Sinervä
SSH key fingerprint: SHA256:FladqYjaE4scJY3Hi+gnShZ6ygnTJgixy0I6BAoHyos
8 changed files with 95 additions and 89 deletions

21
flake.lock generated
View file

@ -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"
}

View file

@ -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 = [

View file

@ -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;
}

View file

@ -0,0 +1 @@
{ }

View file

@ -1,72 +0,0 @@
{ pkgs, ... }:
let
create-partitions = pkgs.writeScriptBin "create-partitions" ''
if [[ $# -ne 3 ]]
then
echo "Usage: create-partitions <device prefix> <BOOT suffix> <root suffix>"
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 <BOOT partition> <root partition>"
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 = [
<nixpkgs/nixos/modules/installer/cd-dvd/channel.nix>
../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;
}

View file

@ -1,7 +0,0 @@
{ ... }:
{
imports = [
<nixpkgs/nixos/modules/installer/cd-dvd/installation-cd-graphical-combined.nix>
./base.nix
];
}

View file

@ -1,9 +0,0 @@
{ lib, ... }:
{
imports = [
<nixpkgs/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix>
./base.nix
];
networking.networkmanager.enable = lib.mkForce false;
}

View file

@ -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 = "/";
};
};
};
};
};
};
};
}