char/flake
nixos flake
git clone https://git.t4t.associates/char/flake
85eec1d
main
1{ 2hostName , 3ipAddress , 4tapId , 5mac , 6} : 7{ pkgs , lib , ... } : 8let 9workspace = "/x/vm/ ${ hostName } " ; 10in 11{ 12networking . hostName = hostName ; 13time . timeZone = "Europe/London" ; 14system . stateVersion = "26.05" ; 15 16# GC of the shared lower store creates persistent overlayfs whiteouts. 17nix . gc . automatic = lib . mkForce false ; 18 19microvm = { 20hypervisor = "qemu" ; 21vcpu = 4 ; 22mem = 8192 ; 23interfaces = [ { type = "tap" ; id = tapId ; inherit mac ; } ]; 24writableStoreOverlay = "/nix/.rw-store" ; 25# whole-disk persistent root; sparse image under /var/lib/microvms/<hostName>/ 26volumes = [ { 27image = "root.img" ; 28mountPoint = "/" ; 29size = 81920 ; 30label = " ${ hostName } -root" ; 31} ]; 32shares = [ 33{ 34proto = "virtiofs" ; 35tag = "ro-store" ; 36source = "/nix/store" ; 37mountPoint = "/nix/.ro-store" ; 38} 39{ 40proto = "virtiofs" ; 41tag = "ssh-keys" ; 42source = "/var/lib/microvms/ ${ hostName } /ssh-host-keys" ; 43mountPoint = "/etc/ssh/host-keys" ; 44} 45{ 46proto = "virtiofs" ; 47tag = "user-ssh-keys" ; 48source = "/var/lib/microvms/ ${ hostName } /ssh-user-keys" ; 49mountPoint = "/etc/ssh/user-keys" ; 50} 51# tailscaled state must persist or the node re-registers on every boot 52{ 53proto = "virtiofs" ; 54tag = "tailscale-state" ; 55source = "/var/lib/microvms/ ${ hostName } /tailscale" ; 56mountPoint = "/var/lib/tailscale" ; 57} 58{ 59proto = "virtiofs" ; 60tag = "pi-agent" ; 61source = "/home/charlotte/.pi/agent" ; 62mountPoint = "/home/charlotte/.pi/agent" ; 63} 64# ~/.pi/agent/extensions symlinks into here 65{ 66proto = "virtiofs" ; 67tag = "personal-dotfiles" ; 68source = "/home/charlotte/.personal-dotfiles" ; 69mountPoint = "/home/charlotte/.personal-dotfiles" ; 70} 71{ 72proto = "virtiofs" ; 73tag = "nixos-system" ; 74source = "/home/charlotte/.nixos-system" ; 75mountPoint = "/home/charlotte/.nixos-system" ; 76} 77{ 78proto = "virtiofs" ; 79tag = "workspace" ; 80source = workspace ; 81mountPoint = "/x" ; 82} 83]; 84}; 85 86boot . loader . systemd-boot . enable = lib . mkForce false ; 87boot . loader . efi . canTouchEfiVariables = lib . mkForce false ; 88 89networking . useNetworkd = true ; 90networking . useDHCP = false ; 91networking . firewall . enable = false ; 92 93systemd . network . enable = true ; 94systemd . network . wait-online . enable = lib . mkForce true ; 95systemd . network . networks . "20-lan" = { 96matchConfig . Type = "ether" ; 97address = [ " ${ ipAddress } /16" ]; 98networkConfig . Gateway = "10.11.0.1" ; 99networkConfig . DNS = [ "10.11.0.1" ]; 100networkConfig . IPv6AcceptRA = true ; 101}; 102 103services . openssh . hostKeys = [ 104{ 105path = "/etc/ssh/host-keys/ssh_host_ed25519_key" ; 106type = "ed25519" ; 107} 108]; 109 110users . users . charlotte = { 111isNormalUser = true ; 112# virtiofs passes uids through raw; must match the host user 113uid = 1000 ; 114description = "charlotte" ; 115extraGroups = [ "wheel" ]; 116shell = pkgs . zsh ; 117openssh . authorizedKeys . keyFiles = [ 118( pkgs . fetchurl { 119url = "https://char.lt/ssh.txt" ; 120hash = "sha256-5rwSdpfUJIB9KlQp2Xw6m02/0uc9TUV0/zBgrg0nCik=" ; 121}) 122]; 123}; 124 125systemd . services . persist-user-ssh-key = { 126description = "Provision charlotte's persistent ssh key" ; 127wantedBy = [ "multi-user.target" ]; 128serviceConfig = { 129Type = "oneshot" ; 130RemainAfterExit = true ; 131}; 132path = [ pkgs . openssh ]; 133script = '' 134install -d -m 0700 -o charlotte -g users /home/charlotte/.ssh 135if [ ! -f /etc/ssh/user-keys/id_ed25519 ]; then 136ssh-keygen -t ed25519 -N "" -C "charlotte@ ${ hostName } " -f /etc/ssh/user-keys/id_ed25519 137fi 138chown charlotte:users /etc/ssh/user-keys/id_ed25519{,.pub} 139chmod 600 /etc/ssh/user-keys/id_ed25519 140ln -sf /etc/ssh/user-keys/id_ed25519{,.pub} /home/charlotte/.ssh/ 141'' ; 142}; 143}