mirror of
https://github.com/ryan4yin/nix-config.git
synced 2026-05-27 01:49:25 +02:00
feat: idols-ai - add new data disk via disko (#250)
feat: luks automatic unlock via tpm2 chip for all physical hosts feat: enable login manager fix: Rename network interface config back following hardware change
This commit is contained in:
@@ -6,7 +6,10 @@ Desktop (NixOS + preservation, LUKS + btrfs on nvme). Disk layout is declarative
|
||||
Related:
|
||||
|
||||
- [nixos-installer README](/nixos-installer/README.md) – install from ISO using disko
|
||||
- [disko-fs.nix](./disko-fs.nix) – partition/layout definition (ESP + LUKS + btrfs)
|
||||
- [disko-fs.nix](./disko-fs.nix) – main disk layout (ESP + LUKS + btrfs). From
|
||||
`nix-config/nixos-installer`:
|
||||
`nix run github:nix-community/disko -- --mode destroy,format,mount ../hosts/idols-ai/disko-fs.nix`
|
||||
- [disko-fs-media.nix](./disko-fs-media.nix) – media disk layout (LUKS + btrfs at /persistent/media)
|
||||
|
||||
## TODOs
|
||||
|
||||
|
||||
@@ -20,8 +20,11 @@ in
|
||||
{
|
||||
imports = [
|
||||
disko.nixosModules.default
|
||||
# disks
|
||||
./disko-fs.nix
|
||||
./disko-fs-data.nix
|
||||
./netdev-mount.nix
|
||||
|
||||
# Include the results of the hardware scan.
|
||||
./hardware-configuration.nix
|
||||
./nvidia.nix
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
# Disko layout for idols-ai data disk (LUKS + btrfs, mount at /persistent/data).
|
||||
#
|
||||
# Destroy, format & mount (wipes disk; from nixos-installer: cd nix-config/nixos-installer):
|
||||
# nix run github:nix-community/disko -- --mode destroy,format,mount ../hosts/idols-ai/disko-fs-data.nix
|
||||
# Mount only (after first format):
|
||||
# nix run github:nix-community/disko -- --mode mount ../hosts/idols-ai/disko-fs-data.nix
|
||||
#
|
||||
{
|
||||
disko.devices = {
|
||||
disk.data = {
|
||||
type = "disk";
|
||||
device = "/dev/disk/by-id/nvme-Fanxiang_S790_2TB_FXS790254050582";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
datapart = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "luks";
|
||||
name = "data-luks"; # Mapper name; match boot.initrd.luks
|
||||
settings = {
|
||||
allowDiscards = true; # TRIM for SSDs; slightly less secure, better performance
|
||||
};
|
||||
# Add boot.initrd.luks.devices so initrd prompts for passphrase at boot
|
||||
initrdUnlock = true;
|
||||
# cryptsetup luksFormat options
|
||||
extraFormatArgs = [
|
||||
"--type luks2"
|
||||
"--cipher aes-xts-plain64"
|
||||
"--hash sha512"
|
||||
"--iter-time 5000"
|
||||
"--key-size 256"
|
||||
"--pbkdf argon2id"
|
||||
"--use-random" # Block until enough entropy from /dev/random
|
||||
];
|
||||
extraOpenArgs = [
|
||||
"--timeout 10"
|
||||
];
|
||||
content = {
|
||||
type = "btrfs";
|
||||
extraArgs = [ "-f" ]; # Force overwrite if filesystem already exists
|
||||
subvolumes = {
|
||||
"@data" = {
|
||||
mountpoint = "/data";
|
||||
mountOptions = [
|
||||
"compress-force=zstd:1"
|
||||
];
|
||||
};
|
||||
};
|
||||
postMountHook = ''
|
||||
chown ryan:users /mnt/data
|
||||
# Set SGID + rwx for owner/group, read-only for others; new files inherit group
|
||||
chmod 2755 /mnt/data
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
# Disko layout for idols-ai on nvme1n1 (target disk after migration).
|
||||
# Same structure as current nvme0n1: ESP + LUKS + btrfs with ephemeral root (tmpfs).
|
||||
#
|
||||
# Format & mount (from installer or live system):
|
||||
# nix run github:nix-community/disko -- --mode disko ./disko-fs.nix
|
||||
# Destroy, format & mount (wipes disk; from nixos-installer: cd nix-config/nixos-installer):
|
||||
# nix run github:nix-community/disko -- --mode destroy,format,mount ../hosts/idols-ai/disko-fs.nix
|
||||
# Mount only (after first format):
|
||||
# nix run github:nix-community/disko -- --mode mount ./disko-fs.nix
|
||||
# nix run github:nix-community/disko -- --mode mount ../hosts/idols-ai/disko-fs.nix
|
||||
#
|
||||
# Use by-id for stability; override device when installing, e.g.:
|
||||
# Override device when installing, e.g.:
|
||||
# nixos-install --flake .#ai --option disko.devices.disk.nixos-ai.device /dev/nvme1n1
|
||||
{
|
||||
# Ephemeral root; preservation mounts /persistent for state.
|
||||
@@ -24,8 +24,7 @@
|
||||
|
||||
disk.nixos-ai = {
|
||||
type = "disk";
|
||||
# Override at install time if needed: --option disko.devices.disk.nixos-ai.device /dev/nvme1n1
|
||||
device = "/dev/nvme1n1";
|
||||
device = "/dev/disk/by-id/nvme-KINGBANK_KP260_CN092BH3203917";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# auto disk partitioning:
|
||||
# nix run github:nix-community/disko -- --mode disko ./disko-fs.nix
|
||||
# Auto disk partitioning (from repo root: nix-config):
|
||||
# nix run github:nix-community/disko -- --mode destroy,format,mount hosts/idols-aquamarine/disko-fs.nix
|
||||
# Mount only (after first format):
|
||||
# nix run github:nix-community/disko -- --mode mount hosts/idols-aquamarine/disko-fs.nix
|
||||
let
|
||||
cryptKeyFile = "/etc/agenix/hdd-luks-crypt-key";
|
||||
unlockDisk = "data-encrypted";
|
||||
|
||||
@@ -1,37 +1,6 @@
|
||||
# Disko Config
|
||||
|
||||
Generate LUKS keyfile to encrypt the root partition, it's used by disko.
|
||||
|
||||
```bash
|
||||
# partition the usb stick
|
||||
DEV=/dev/sdX
|
||||
parted $DEV -- mklabel gpt
|
||||
parted $DEV -- mkpart primary 2M 512MB
|
||||
parted $DEV -- mkpart primary 512MB 1024MB
|
||||
mkfs.fat -F 32 -n NIXOS_DSC ${DEV}1
|
||||
mkfs.fat -F 32 -n NIXOS_K3S ${DEV}2
|
||||
|
||||
# Generate a keyfile from the true random number generator
|
||||
KEYFILE=./kubevirt-luks-keyfile
|
||||
dd bs=512 count=64 iflag=fullblock if=/dev/random of=$KEYFILE
|
||||
|
||||
# generate token for k3s
|
||||
K3S_TOKEN_FILE=./kubevirt-k3s-token
|
||||
K3S_TOKEN=$(grep -ao '[A-Za-z0-9]' < /dev/random | head -64 | tr -d '\n' ; echo "")
|
||||
echo $K3S_TOKEN > $K3S_TOKEN_FILE
|
||||
|
||||
# copy the keyfile and token to the usb stick
|
||||
KEYFILE=./kubevirt-luks-keyfile
|
||||
DEVICE=/dev/disk/by-label/NIXOS_DSC
|
||||
# seek=128 skip N obs-sized output blocks to avoid overwriting the filesystem header
|
||||
dd bs=512 count=64 iflag=fullblock seek=128 if=$KEYFILE of=$DEVICE
|
||||
|
||||
K3S_TOKEN_FILE=./kubevirt-k3s-token
|
||||
USB_PATH=/run/media/ryan/NIXOS_K3S
|
||||
cp $K3S_TOKEN_FILE $USB_PATH
|
||||
```
|
||||
|
||||
### 2. Partition the SSD & install NixOS via disko
|
||||
## Partition the SSD & install NixOS via disko
|
||||
|
||||
```bash
|
||||
# enter an shell with git/vim/ssh-agent/gnumake available
|
||||
@@ -41,15 +10,13 @@ git clone https://github.com/ryan4yin/nix-config.git
|
||||
|
||||
cd nix-config
|
||||
|
||||
# one line
|
||||
sudo nix run --experimental-features "nix-command flakes" 'github:nix-community/disko#disko-install' -- \
|
||||
--write-efi-boot-entries --disk main /dev/nvme0n1 --flake .#kubevirt-shoryu
|
||||
|
||||
|
||||
# or step by step
|
||||
## 1. partition & format the disk via disko
|
||||
sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko -- --mode disko hosts/k8s/disko-config/kukubevirt-disko-fs.nix
|
||||
## 2. install nixos
|
||||
# encrypt the root partition with luks2 and argon2id, will prompt for a passphrase, which will be used to unlock the partition.
|
||||
sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko -- --mode destroy,format,mount hosts/k8s/disko-config/kubevirt-disko-fs.nix
|
||||
## 2. setup the automatic unlock via the tpm2 chip
|
||||
systemd-cryptenroll --tpm2-device=auto --tpm2-pcrs=0+7 /dev/<encrypted-disk-part-path>
|
||||
|
||||
## 3. install nixos
|
||||
sudo nixos-install --root /mnt --no-root-password --show-trace --verbose --flake .#kubevirt-shoryu
|
||||
|
||||
# enter into the installed system, check password & users
|
||||
@@ -66,4 +33,6 @@ mv /etc/machine-id /persistent/etc/
|
||||
mv /etc/ssh /persistent/etc/
|
||||
mkdir -p /persistent/home/ryan
|
||||
chown -R ryan:ryan /persistent/home/ryan
|
||||
|
||||
# add your k3s token at /persistent/kubevirt-k3s-token
|
||||
```
|
||||
|
||||
@@ -2,13 +2,6 @@
|
||||
# required by preservation
|
||||
fileSystems."/persistent".neededForBoot = true;
|
||||
|
||||
# contains the k3s's token
|
||||
fileSystems."/run/media/nixos_k3s" = {
|
||||
device = "/dev/disk/by-label/NIXOS_K3S";
|
||||
fsType = "vfat";
|
||||
options = [ "ro" ];
|
||||
};
|
||||
|
||||
disko.devices = {
|
||||
nodev."/" = {
|
||||
fsType = "tmpfs";
|
||||
@@ -50,11 +43,6 @@
|
||||
type = "luks";
|
||||
name = "encrypted";
|
||||
settings = {
|
||||
keyFile = "/dev/disk/by-label/NIXOS_DSC"; # The keyfile is stored on a USB stick
|
||||
# The maximum size of the keyfile is 8192 KiB
|
||||
# type `cryptsetup --help` to see the compiled-in key and passphrase maximum sizes
|
||||
keyFileSize = 512 * 64; # match the `bs * count` of the `dd` command
|
||||
keyFileOffset = 512 * 128; # match the `bs * skip` of the `dd` command
|
||||
# fallbackToPassword = true;
|
||||
allowDiscards = true;
|
||||
};
|
||||
|
||||
@@ -17,7 +17,7 @@ let
|
||||
k3sModule = mylib.genK3sServerModule {
|
||||
inherit pkgs;
|
||||
kubeconfigFile = "/home/${myvars.username}/.kube/config";
|
||||
tokenFile = "/run/media/nixos_k3s/kubevirt-k3s-token";
|
||||
tokenFile = "/persistent/kubevirt-k3s-token";
|
||||
# the first node in the cluster should be the one to initialize the cluster
|
||||
clusterInit = true;
|
||||
# use my own domain & kube-vip's virtual IP for the API server
|
||||
|
||||
@@ -16,7 +16,7 @@ let
|
||||
k3sModule = mylib.genK3sServerModule {
|
||||
inherit pkgs;
|
||||
kubeconfigFile = "/home/${myvars.username}/.kube/config";
|
||||
tokenFile = "/run/media/nixos_k3s/kubevirt-k3s-token";
|
||||
tokenFile = "/persistent/kubevirt-k3s-token";
|
||||
# use my own domain & kube-vip's virtual IP for the API server
|
||||
# so that the API server can always be accessed even if some nodes are down
|
||||
masterHost = "kubevirt-cluster-1.writefor.fun";
|
||||
|
||||
@@ -16,7 +16,7 @@ let
|
||||
k3sModule = mylib.genK3sServerModule {
|
||||
inherit pkgs;
|
||||
kubeconfigFile = "/home/${myvars.username}/.kube/config";
|
||||
tokenFile = "/run/media/nixos_k3s/kubevirt-k3s-token";
|
||||
tokenFile = "/persistent/kubevirt-k3s-token";
|
||||
# use my own domain & kube-vip's virtual IP for the API server
|
||||
# so that the API server can always be accessed even if some nodes are down
|
||||
masterHost = "kubevirt-cluster-1.writefor.fun";
|
||||
|
||||
Reference in New Issue
Block a user