default.nix (801B)
1 { 2 config, 3 pkgs, 4 ... 5 }: 6 { 7 config = { 8 boot.initrd.systemd.services.zfs-rotate-root = { 9 wantedBy = [ "initrd.target" ]; 10 after = [ "zfs-import-system.service" ]; 11 before = [ "sysroot.mount" ]; 12 path = with pkgs; [ 13 config.boot.zfs.package 14 coreutils 15 ]; 16 description = "rotate root dataset"; 17 unitConfig.DefaultDependencies = "no"; 18 serviceConfig.Type = "oneshot"; 19 script = '' 20 zfs rename "system/root/current" "system/root/$(date -ud "@$(zfs get -Hpo value creation system/root/current)" +%Y-%m-%dT%H-%M-%SZ)" 21 zfs create -o mountpoint=legacy "system/root/current" 22 ''; 23 }; 24 25 environment.systemPackages = [ 26 (pkgs.writeShellScriptBin "prune-roots" (builtins.readFile ./prune-roots.sh)) 27 ]; 28 }; 29 }