nixos

NixOS server files. Mirror from https://git.nordgedanken.dev/kubernetes/nixos
git clone git://archive.git.mtrnord.blog/MTRNord/nixos.git
Log | Files | Refs | README

darlings.nix (2146B)


      1 {
      2   lib,
      3   pkgs,
      4   config,
      5   ...
      6 }: {
      7   # Darling Erasure
      8   environment.persistence."/persist" = {
      9     directories = [
     10       "/var/lib/tailscale"
     11       "/var/lib/asterisk"
     12       "/var/lib/headscale"
     13       "/etc/nixos"
     14       "/var/lib/postgresql/${config.services.patroni.postgresqlPackage.psqlSchema}"
     15       "/var/lib/patroni"
     16       "/var/lib/etcd"
     17       "/var/lib/discourse"
     18       "/var/lib/pgadmin"
     19     ];
     20     files = [
     21       "/etc/machine-id"
     22       #"/etc/NIXOS"
     23       "/etc/secrets/initrd/ssh_host_ed25519_key"
     24       "/etc/secrets/initrd/ssh_host_ed25519_key.pub"
     25       "/var/lib/sops-nix/key.txt"
     26     ];
     27   };
     28   security.sudo.extraConfig = ''
     29     # rollback results in sudo lectures after each reboot
     30     Defaults lecture = never
     31   '';
     32   # Note `lib.mkBefore` is used instead of `lib.mkAfter` here.
     33   boot.initrd.postDeviceCommands = pkgs.lib.mkBefore ''
     34     mkdir -p /mnt
     35 
     36     # We first mount the btrfs root to /mnt
     37     # so we can manipulate btrfs subvolumes.
     38     mount -o subvol=/ /dev/mapper/enc /mnt
     39 
     40     # While we're tempted to just delete /root and create
     41     # a new snapshot from /root-blank, /root is already
     42     # populated at this point with a number of subvolumes,
     43     # which makes `btrfs subvolume delete` fail.
     44     # So, we remove them first.
     45     #
     46     # /root contains subvolumes:
     47     # - /root/var/lib/portables
     48     # - /root/var/lib/machines
     49     #
     50     # I suspect these are related to systemd-nspawn, but
     51     # since I don't use it I'm not 100% sure.
     52     # Anyhow, deleting these subvolumes hasn't resulted
     53     # in any issues so far, except for fairly
     54     # benign-looking errors from systemd-tmpfiles.
     55     btrfs subvolume list -o /mnt/root |
     56     cut -f9 -d' ' |
     57     while read subvolume; do
     58       echo "deleting /$subvolume subvolume..."
     59       btrfs subvolume delete "/mnt/$subvolume"
     60     done &&
     61     echo "deleting /root subvolume..." &&
     62     btrfs subvolume delete /mnt/root
     63 
     64     echo "restoring blank /root subvolume..."
     65     btrfs subvolume snapshot /mnt/root-blank /mnt/root
     66 
     67     # Once we're done rolling back to a blank snapshot,
     68     # we can unmount /mnt and continue on the boot process.
     69     umount /mnt
     70   '';
     71 }