fix mini config
This commit is contained in:
parent
6790828a28
commit
ead992a1ef
3 changed files with 37 additions and 75 deletions
|
@ -1,7 +1,3 @@
|
||||||
# Edit this configuration file to define what should be installed on
|
|
||||||
# your system. Help is available in the configuration.nix(5) man page
|
|
||||||
# and in the NixOS manual (accessible by running `nixos-help`).
|
|
||||||
|
|
||||||
{ config, pkgs, ... }:
|
{ config, pkgs, ... }:
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -14,9 +10,8 @@
|
||||||
/data/nixos/share/common.nix
|
/data/nixos/share/common.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
# our hostname and an ID for ZFS
|
# our hostname
|
||||||
networking.hostName = "mini";
|
networking.hostName = "mini";
|
||||||
networking.hostId = "e925ccfb";
|
|
||||||
|
|
||||||
# EurKey layout
|
# EurKey layout
|
||||||
services.xserver.xkb.layout = "eu";
|
services.xserver.xkb.layout = "eu";
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
# Do not modify this file! It was generated by ‘nixos-generate-config’
|
|
||||||
# and may be overwritten by future invocations. Please make changes
|
|
||||||
# to /etc/nixos/configuration.nix instead.
|
|
||||||
{ config, lib, pkgs, modulesPath, ... }:
|
{ config, lib, pkgs, modulesPath, ... }:
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -21,7 +18,14 @@
|
||||||
fileSystems."/boot" = {
|
fileSystems."/boot" = {
|
||||||
device = "/dev/disk/by-id/nvme-CT4000P3PSSD8_2325E6E63746-part1";
|
device = "/dev/disk/by-id/nvme-CT4000P3PSSD8_2325E6E63746-part1";
|
||||||
fsType = "vfat";
|
fsType = "vfat";
|
||||||
|
neededForBoot = true;
|
||||||
options = [ "fmask=0022" "dmask=0022" ];
|
options = [ "fmask=0022" "dmask=0022" ];
|
||||||
|
};
|
||||||
|
|
||||||
|
# /nix volume with the system & all persistent data
|
||||||
|
fileSystems."/nix" = {
|
||||||
|
device = "/dev/disk/by-id/nvme-CT4000P3PSSD8_2325E6E63746-part2:/dev/disk/by-id/ata-CT2000MX500SSD1_2138E5D5061F-part2";
|
||||||
|
fsType = "bcachefs";
|
||||||
neededForBoot = true;
|
neededForBoot = true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ HOST=mini
|
||||||
# disks to use
|
# disks to use
|
||||||
DISK=/dev/disk/by-id/nvme-CT4000P3PSSD8_2325E6E63746
|
DISK=/dev/disk/by-id/nvme-CT4000P3PSSD8_2325E6E63746
|
||||||
DISK2=/dev/disk/by-id/ata-CT2000MX500SSD1_2138E5D5061F
|
DISK2=/dev/disk/by-id/ata-CT2000MX500SSD1_2138E5D5061F
|
||||||
|
DISKS="$DISK $DISK2"
|
||||||
|
|
||||||
# ensure 4k sector size
|
# ensure 4k sector size
|
||||||
nvme format --lbaf=1 --force $DISK
|
nvme format --lbaf=1 --force $DISK
|
||||||
|
@ -35,76 +36,43 @@ nvme id-ns -H $DISK
|
||||||
sleep 5
|
sleep 5
|
||||||
|
|
||||||
# create partition table on all disks and EFI partition
|
# create partition table on all disks and EFI partition
|
||||||
for D in $DISK $DISK2; do
|
RAID=""
|
||||||
|
for D in $DISKS; do
|
||||||
# kill old data
|
# kill old data
|
||||||
sgdisk --zap-all $D
|
sgdisk --zap-all $D
|
||||||
blkdiscard -v $D
|
blkdiscard -v -f $D
|
||||||
wipefs -a $D
|
wipefs -a $D
|
||||||
sleep 5
|
sleep 5
|
||||||
|
|
||||||
# create partitions
|
# Create partition table
|
||||||
parted $D -- mklabel gpt
|
parted $D -- mklabel gpt
|
||||||
sgdisk -n 1:0:+1024M -c 1:"EFI System Partition" -t 1:EF00 $D
|
|
||||||
sgdisk -n 2:0:0 -c 2:"Linux" -t 2:8e00 $D
|
# Create a /boot as $D-part1
|
||||||
|
parted $D -- mkpart ESP fat32 1MiB 1024MiB
|
||||||
parted $D -- set 1 boot on
|
parted $D -- set 1 boot on
|
||||||
|
|
||||||
sleep 5
|
# Create a /nix as $D-part2
|
||||||
|
parted $D -- mkpart NIX 1024MiB 100%
|
||||||
|
|
||||||
# boot partition
|
# boot partition after short sleep, needed on some machines
|
||||||
mkfs.fat -F 32 -n EFIBOOT $D-part1
|
sleep 5
|
||||||
|
mkfs.vfat $D-part1
|
||||||
|
|
||||||
|
# add part2 to raid
|
||||||
|
RAID="$RAID $D-part2"
|
||||||
done
|
done
|
||||||
|
|
||||||
# take a look at the partitions
|
# take a look at the partitions
|
||||||
lsblk
|
lsblk
|
||||||
|
|
||||||
# ZFS zpool creation with compression and encryption
|
# create encrypted bcachefs
|
||||||
zpool create \
|
bcachefs format --encrypt -f $RAID
|
||||||
-o ashift=13 \
|
nix-env -iA nixos.keyutils
|
||||||
-o autotrim=off \
|
keyctl link @u @s
|
||||||
-O acltype=posixacl \
|
bcachefs unlock $DISK-part2
|
||||||
-O atime=off \
|
|
||||||
-O canmount=off \
|
|
||||||
-O compression=on \
|
|
||||||
-O dnodesize=auto \
|
|
||||||
-O utf8only=on \
|
|
||||||
-O normalization=formD \
|
|
||||||
-O xattr=sa \
|
|
||||||
-O mountpoint=none \
|
|
||||||
-O encryption=on \
|
|
||||||
-O keylocation=prompt \
|
|
||||||
-O keyformat=passphrase \
|
|
||||||
zpool $DISK-part2 $DISK2-part2
|
|
||||||
|
|
||||||
sleep 5
|
# prepare install, tmpfs root
|
||||||
|
mount -t tmpfs none /mnt
|
||||||
# take a look at the partitions
|
|
||||||
lsblk
|
|
||||||
|
|
||||||
# show the pool
|
|
||||||
zpool status
|
|
||||||
|
|
||||||
sleep 5
|
|
||||||
|
|
||||||
# create all the volumes
|
|
||||||
zfs create -o mountpoint=legacy zpool/data
|
|
||||||
zfs create -o mountpoint=legacy zpool/nix
|
|
||||||
zfs create -o mountpoint=legacy zpool/root
|
|
||||||
|
|
||||||
sleep 5
|
|
||||||
|
|
||||||
# show the pool
|
|
||||||
zpool status
|
|
||||||
|
|
||||||
sleep 5
|
|
||||||
|
|
||||||
# create ZFS snapshot that we'll rollback to on boot
|
|
||||||
# see https://ryanseipp.com/post/nixos-encrypted-root/
|
|
||||||
zfs snapshot zpool/root@blank
|
|
||||||
|
|
||||||
sleep 5
|
|
||||||
|
|
||||||
# prepare install, root
|
|
||||||
mount -t zfs zpool/root /mnt
|
|
||||||
|
|
||||||
# Create directories to mount file systems on
|
# Create directories to mount file systems on
|
||||||
mkdir -p /mnt/{data,nix,boot,root,etc/nixos}
|
mkdir -p /mnt/{data,nix,boot,root,etc/nixos}
|
||||||
|
@ -112,9 +80,12 @@ mkdir -p /mnt/{data,nix,boot,root,etc/nixos}
|
||||||
# mount the ESP
|
# mount the ESP
|
||||||
mount $DISK-part1 /mnt/boot
|
mount $DISK-part1 /mnt/boot
|
||||||
|
|
||||||
# mount volumes
|
# mount the /nix
|
||||||
mount -t zfs zpool/data /mnt/data
|
mount -t bcachefs $DISK-part2 /mnt/nix
|
||||||
mount -t zfs zpool/nix /mnt/nix
|
|
||||||
|
# mount the /data via bind mount
|
||||||
|
mkdir /mnt/nix/data
|
||||||
|
mount --bind /mnt/nix/data /mnt/data
|
||||||
|
|
||||||
# bind mount persistent stuff to data
|
# bind mount persistent stuff to data
|
||||||
mkdir -p /mnt/data/{root,nixos/$HOST}
|
mkdir -p /mnt/data/{root,nixos/$HOST}
|
||||||
|
@ -131,26 +102,18 @@ mount
|
||||||
# configure
|
# configure
|
||||||
nixos-generate-config --root /mnt
|
nixos-generate-config --root /mnt
|
||||||
|
|
||||||
# check /mnt/etc/nixos/hardware-configuration.nix /mnt/etc/nixos/configuration.nix
|
|
||||||
|
|
||||||
# copy config data from another machine including secrets
|
# copy config data from another machine including secrets
|
||||||
|
|
||||||
doas scp -r /data/nixos root@192.168.13.100:/mnt/data
|
doas scp -r /data/nixos root@192.168.13.100:/mnt/data
|
||||||
|
|
||||||
# install
|
# install
|
||||||
|
|
||||||
nixos-install --option experimental-features 'nix-command flakes' --no-root-passwd --root /mnt
|
nixos-install --option experimental-features 'nix-command flakes' --no-root-passwd --root /mnt
|
||||||
|
|
||||||
# unmount all stuff and sync
|
# unmount all stuff and sync
|
||||||
|
|
||||||
umount -Rl /data /mnt
|
umount -Rl /data /mnt
|
||||||
zpool export -a
|
|
||||||
sync
|
sync
|
||||||
|
|
||||||
# shutdown once
|
# shutdown once
|
||||||
|
|
||||||
shutdown now
|
shutdown now
|
||||||
|
|
||||||
# sync all /data after the install
|
# sync all /data after the install
|
||||||
|
|
||||||
doas rsync -va --delete --one-file-system /data/ root@192.168.13.100:/data/
|
doas rsync -va --delete --one-file-system /data/ root@192.168.13.100:/data/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue