This commit is contained in:
Hunter Haugen 2025-04-20 14:36:58 -04:00
commit 97c737637d
12 changed files with 1351 additions and 0 deletions

13
qemu/boot.sh Executable file
View file

@ -0,0 +1,13 @@
qemu-system-x86_64 \
-enable-kvm \
-m 4G \
-smp 4 \
-cpu host \
-drive file=/home/hunner/Downloads/latest-nixos-minimal-x86_64-linux.iso,media=cdrom \
-drive file=disk1.qcow2,format=qcow2,if=virtio \
-drive file=disk2.qcow2,format=qcow2,if=virtio \
-boot menu=on,splash-time=5000 \
-nic user,model=virtio-net-pci,hostfwd=tcp::2222-:22 \
-display gtk
#-drive file=/home/hunner/Downloads/nixos-minimal-23.05.2664.9034b46dc4c7-x86_64-linux.iso,media=cdrom \

116
qemu/configuration.nix Normal file
View file

@ -0,0 +1,116 @@
{ config, pkgs, lib, ... }:
#zpool import -f rpool
#mount -t zfs rpool/local/root /mnt
#mkdir -p /mnt/{boot,nix,home,persist,var/lib,var/log}
#mount /dev/vda2 /mnt/boot
#mount -t zfs rpool/local/nix /mnt/nix
#mount -t zfs rpool/safe/home /mnt/home
#mount -t zfs rpool/safe/persist /mnt/persist
#mount -t zfs rpool/local/var/lib /mnt/var/lib
#mount -t zfs rpool/local/var/log /mnt/var/log
let
impermanence = builtins.fetchTarball "https://github.com/nix-community/impermanence/archive/master.tar.gz";
in
{
imports =
[
./hardware-configuration.nix
"${impermanence}/nixos.nix"
];
# Enable ZFS support
boot.supportedFilesystems = [ "zfs" ];
boot.zfs.requestEncryptionCredentials = false;
fileSystems = {
"/persist" = {
device = "rpool/safe/persist";
fsType = "zfs";
neededForBoot = true; # Only /persist needs to be marked as needed for boot
};
};
# Import the existing ZFS pool from the second disk without formatting it
boot.zfs.extraPools = [ "tank" ];
boot.zfs.devNodes = "/dev/disk/by-path"; # This is neede for ZFS to find the pool at boot
# Use GRUB with MBR for BIOS booting
boot.loader.grub.enable = true;
boot.loader.grub.device = "/dev/vda";
boot.loader.grub.zfsSupport = true;
boot.loader.grub.efiSupport = false;
# Impermanence configuration
# Set up impermanence - root filesystem will be reset on each boot
boot.initrd.postResumeCommands = lib.mkAfter ''
zfs rollback -r rpool/local/root@blank
'';
# /var/log and /var/lib ar persisted through zfs datasets, but not backed up.
# Anything stored in /persist should get backed up.
environment.persistence."/persist" = {
hideMounts = true;
directories = [
"/root"
"/etc/nixos"
"/etc/ssh"
];
files = [
"/etc/machine-id"
#"/etc/nix/id_rsa" # Needed?
];
};
# Files are not copied to /persist during install, so need to do so manually
#rsync -azPH /mnt/root/ /mnt/persist/root
#rsync -azPH /mnt/etc/nixos/ /mnt/persist/etc/nixos
#rsync -azPH /mnt/etc/ssh/ /mnt/persist/etc/ssh
#cp /mnt/etc/machine-id /mnt/persist/etc/machine-id
# Swap configuration
swapDevices = [ {
device = "/dev/vda3";
randomEncryption.enable = true;
} ];
# Basic system configuration
networking.hostId = "5472a981"; # Required for ZFS
networking.hostName = "cryochamber";
# Enable networking
networking.networkmanager.enable = true;
# Set your time zone
time.timeZone = "UTC";
# Docker configuration
virtualisation.docker = {
enable = true;
extraOptions = "--storage-driver=overlay2";
};
# System packages
environment.systemPackages = with pkgs; [
git
vim
wget
curl
htop
zfs
zsh
tmux
docker-compose
];
# Define a user account
users.users.hunner = {
isNormalUser = true;
extraGroups = [ "wheel" "docker" "networkmanager" ];
initialPassword = "a";
shell = pkgs.zsh;
};
programs.zsh.enable = true;
services.openssh.enable = true;
system.stateVersion = "24.11";
}

106
qemu/disko-gpt.nix Normal file
View file

@ -0,0 +1,106 @@
{
disko.devices = {
disk = {
vda = {
type = "disk";
device = "/dev/vda";
content = {
type = "gpt";
partitions = {
boot = {
size = "1M";
type = "EF02";
};
ESP = {
name = "ESP";
size = "512M";
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
mountOptions = [ "umask=0077" ];
};
};
swap = {
size = "8G";
content = {
type = "swap";
randomEncryption = true;
};
};
zfs = {
size = "100%";
content = {
type = "zfs";
pool = "rpool";
};
};
};
};
};
};
zpool = {
rpool = {
type = "zpool";
rootFsOptions = {
acltype = "posixacl";
compression = "lz4";
dnodesize = "auto";
normalization = "formD";
relatime = "on";
xattr = "sa";
};
options = {
ashift = "12";
autotrim = "on";
};
datasets = {
"local/root" = {
type = "zfs_fs";
options = {
mountpoint = "legacy";
canmount = "noauto";
};
mountpoint = "/";
postCreateHook = ''
zfs snapshot rpool/local/root@blank
'';
};
"local/nix" = {
type = "zfs_fs";
options.mountpoint = "legacy";
mountpoint = "/nix";
};
"safe/persist" = {
type = "zfs_fs";
options.mountpoint = "legacy";
mountpoint = "/persist";
};
"safe/home" = {
type = "zfs_fs";
options.mountpoint = "legacy";
mountpoint = "/home";
};
"local/var" = {
type = "zfs_fs";
options = {
mountpoint = "none";
canmount = "off";
};
};
"local/var/lib" = {
type = "zfs_fs";
options.mountpoint = "legacy";
mountpoint = "/var/lib";
};
"local/var/log" = {
type = "zfs_fs";
options.mountpoint = "legacy";
mountpoint = "/var/log";
};
};
};
};
};
}

104
qemu/disko-mbr.nix Normal file
View file

@ -0,0 +1,104 @@
{
disko.devices = {
disk = {
vda = {
device = "/dev/vda";
type = "disk";
content = {
type = "mbr"; # Use MBR instead of GPT
partitions = {
boot = {
size = "1G";
type = "83"; # Linux type
bootable = true; # Mark as bootable
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/boot";
};
};
swap = {
size = "8G";
type = "82"; # Linux swap type
content = {
type = "swap";
randomEncryption = true; # Enable random encryption for swap
};
};
zfs = {
size = "100%";
type = "83"; # Linux type
content = {
type = "zfs";
pool = "rpool";
};
};
};
};
};
};
zpool = {
rpool = {
type = "zpool";
rootFsOptions = {
acltype = "posixacl";
compression = "lz4";
dnodesize = "auto";
normalization = "formD";
relatime = "on"; # Using relatime as you requested
xattr = "sa";
};
options = {
ashift = "12";
autotrim = "on";
};
datasets = {
"local/root" = {
type = "zfs_fs";
options = {
mountpoint = "legacy";
canmount = "noauto";
};
mountpoint = "/";
postCreateHook = ''
zfs snapshot rpool/local/root@blank
zfs rollback rpool/local/root@blank
'';
};
"local/nix" = {
type = "zfs_fs";
options.mountpoint = "legacy";
mountpoint = "/nix";
};
"safe/persist" = {
type = "zfs_fs";
options.mountpoint = "legacy";
mountpoint = "/persist";
};
"safe/home" = {
type = "zfs_fs";
options.mountpoint = "legacy";
mountpoint = "/home";
};
"local/var" = {
type = "zfs_fs";
options = {
mountpoint = "none";
canmount = "off";
};
};
"local/var/lib" = {
type = "zfs_fs";
options.mountpoint = "legacy";
mountpoint = "/var/lib";
};
"local/var/log" = {
type = "zfs_fs";
options.mountpoint = "legacy";
mountpoint = "/var/log";
};
};
};
};
};
}

101
qemu/disko.nix Normal file
View file

@ -0,0 +1,101 @@
{
disko.devices = {
disk = {
vda = {
device = "/dev/vda";
type = "disk";
content = {
type = "gpt";
partitions = {
boot = {
size = "1G";
type = "EF02"; # BIOS boot partition
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/boot";
};
};
swap = {
size = "8G";
content = {
type = "swap";
randomEncryption = true;
};
};
zfs = {
size = "100%";
content = {
type = "zfs";
pool = "rpool";
};
};
};
};
};
};
zpool = {
rpool = {
type = "zpool";
rootFsOptions = {
acltype = "posixacl";
compression = "lz4";
dnodesize = "auto";
normalization = "formD";
relatime = "on";
xattr = "sa";
};
options = {
ashift = "12";
autotrim = "on";
};
datasets = {
"local/root" = {
type = "zfs_fs";
options = {
mountpoint = "legacy";
canmount = "noauto";
};
mountpoint = "/";
postCreateHook = ''
zfs snapshot rpool/local/root@blank
zfs rollback rpool/local/root@blank
'';
};
"local/nix" = {
type = "zfs_fs";
options.mountpoint = "legacy";
mountpoint = "/nix";
};
"safe/persist" = {
type = "zfs_fs";
options.mountpoint = "legacy";
mountpoint = "/persist";
};
"safe/home" = {
type = "zfs_fs";
options.mountpoint = "legacy";
mountpoint = "/home";
};
"local/var" = {
type = "zfs_fs";
options = {
mountpoint = "none";
canmount = "off";
};
};
"local/var/lib" = {
type = "zfs_fs";
options.mountpoint = "legacy";
mountpoint = "/var/lib";
};
"local/var/log" = {
type = "zfs_fs";
options.mountpoint = "legacy";
mountpoint = "/var/log";
};
};
};
};
};
}