X-Git-Url: https://git.sourcephile.fr/julm/julm-nix.git/blobdiff_plain/a9a74a2a96a2bc054b5243092d001f9bf693e05f..4ed833c90d7a247929afa7e528aa46381e8c8b27:/nixos/profiles/zfs.nix diff --git a/nixos/profiles/zfs.nix b/nixos/profiles/zfs.nix index 062ffdd..cfad168 100644 --- a/nixos/profiles/zfs.nix +++ b/nixos/profiles/zfs.nix @@ -19,11 +19,12 @@ # Stable enough, clearer, and faster than the default /dev/disk/by-id boot.zfs.devNodes = "/dev/disk/by-partlabel"; # Not useful so far. + # See also https://github.com/NixOS/nixpkgs/issues/62644#issuecomment-1479523469 boot.zfs.forceImportAll = false; # More resilient for remote hosts, # though it may call zpool clear. boot.zfs.forceImportRoot = true; - boot.zfs.requestEncryptionCredentials = lib.mkDefault [ hostName ]; + boot.zfs.requestEncryptionCredentials = lib.mkDefault [ "${hostName}/root" ]; boot.zfs.enableUnstable = false; @@ -37,9 +38,43 @@ services.zfs.trim.enable = true; services.zfs.trim.interval = "Sun *-*-01..07 00:15:00"; + # Hide ZFS mountpoints from gio, hence nautilus or caja + systemd.services.zfs-mount.postStart = '' + /run/wrappers/bin/mount -t zfs | cut -f 1 -d ' ' | + xargs -n 1 -r -t /run/wrappers/bin/mount -o remount,x-gvfs-hide + ''; + environment.systemPackages = [ pkgs.lzop # For remote syncoid pkgs.mbuffer # For remote syncoid pkgs.sanoid ]; + + # Force zpool import, even if the disk has not been exported, + # (ie. still imported onto another computer). + systemd.services."zfs-import@" = { + description = "ZFS import pool: %I"; + unitConfig = { + ConditionPathIsDirectory = "/sys/module/zfs"; + StartLimitIntervalSec = 0; + }; + after = [ "systemd-modules-load.service" ]; + path = lib.mkBefore [ "/run/booted-system/sw" ]; + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + PrivateTmp = true; + SyslogIdentifier = "zfs-import@%i"; + Restart = "no"; + ExecStart = pkgs.writeShellScript "zfs-import" '' + pool="$1" + set -eux + zpool import -lFd /dev/disk/by-id/ -o cachefile=none "$pool" || + zpool reopen "$pool" || + zpool import -lfd /dev/disk/by-id/ -o cachefile=none "$pool" || + zpool clear -nFX "$pool" + ${pkgs.systemd}/bin/systemctl restart zfs-mount.service + '' + " %I"; + }; + }; }