zfs: Enable systemd

Also remove custom zfs services from NixOS.  This makes NixOS more aligned with
upstream.

More importantly, it prepares the way for NixOS to use ZED (the ZFS event
daemon). This service will automatically be enabled but it is not possible to
configure it via configuration.nix yet.
wip/yesman
Ricardo M. Correia 10 years ago
parent ace49e400c
commit 3b0fa60a98
  1. 38
      nixos/modules/tasks/filesystems/zfs.nix
  2. 26
      pkgs/os-specific/linux/zfs/default.nix
  3. 26
      pkgs/os-specific/linux/zfs/git.nix

@ -152,40 +152,20 @@ in
zfsSupport = true;
};
systemd.services."zpool-import" = {
description = "Import zpools";
after = [ "systemd-udev-settle.service" ];
wantedBy = [ "local-fs.target" ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
ExecStart = "${zfsPkg}/sbin/zpool import -f -a";
};
restartIfChanged = false;
};
systemd.services."zfs-mount" = {
description = "Mount ZFS Volumes";
after = [ "zpool-import.service" ];
wantedBy = [ "local-fs.target" ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
ExecStart = "${zfsPkg}/sbin/zfs mount -a";
ExecStop = "${zfsPkg}/sbin/zfs umount -a";
};
restartIfChanged = false;
};
environment.etc."zfs/zed.d".source = "${zfsPkg}/etc/zfs/zed.d/*";
system.fsPackages = [ zfsPkg ]; # XXX: needed? zfs doesn't have (need) a fsck
environment.systemPackages = [ zfsPkg ];
services.udev.packages = [ zfsPkg ]; # to hook zvol naming, etc.
systemd.packages = [ zfsPkg ];
systemd.targets."zfs".wantedBy = [ "multi-user.target" ];
})
(mkIf enableAutoSnapshots {
systemd.services."zfs-snapshot-frequent" = {
description = "ZFS auto-snapshotting every 15 mins";
after = [ "zpool-import.service" ];
after = [ "zfs-import-scan.service" "zfs-import-cache.service" ];
serviceConfig = {
Type = "oneshot";
ExecStart = "${zfsAutoSnap} frequent ${toString cfgSnapshots.frequent}";
@ -196,7 +176,7 @@ in
systemd.services."zfs-snapshot-hourly" = {
description = "ZFS auto-snapshotting every hour";
after = [ "zpool-import.service" ];
after = [ "zfs-import-scan.service" "zfs-import-cache.service" ];
serviceConfig = {
Type = "oneshot";
ExecStart = "${zfsAutoSnap} hourly ${toString cfgSnapshots.hourly}";
@ -207,7 +187,7 @@ in
systemd.services."zfs-snapshot-daily" = {
description = "ZFS auto-snapshotting every day";
after = [ "zpool-import.service" ];
after = [ "zfs-import-scan.service" "zfs-import-cache.service" ];
serviceConfig = {
Type = "oneshot";
ExecStart = "${zfsAutoSnap} daily ${toString cfgSnapshots.daily}";
@ -218,7 +198,7 @@ in
systemd.services."zfs-snapshot-weekly" = {
description = "ZFS auto-snapshotting every week";
after = [ "zpool-import.service" ];
after = [ "zfs-import-scan.service" "zfs-import-cache.service" ];
serviceConfig = {
Type = "oneshot";
ExecStart = "${zfsAutoSnap} weekly ${toString cfgSnapshots.weekly}";
@ -229,7 +209,7 @@ in
systemd.services."zfs-snapshot-monthly" = {
description = "ZFS auto-snapshotting every month";
after = [ "zpool-import.service" ];
after = [ "zfs-import-scan.service" "zfs-import-cache.service" ];
serviceConfig = {
Type = "oneshot";
ExecStart = "${zfsAutoSnap} monthly ${toString cfgSnapshots.monthly}";

@ -20,24 +20,32 @@ stdenv.mkDerivation {
NIX_CFLAGS_LINK = "-lgcc_s";
preConfigure = ''
./autogen.sh
substituteInPlace ./module/zfs/zfs_ctldir.c --replace "umount -t zfs" "${utillinux}/bin/umount -t zfs"
substituteInPlace ./module/zfs/zfs_ctldir.c --replace "mount -t zfs" "${utillinux}/bin/mount -t zfs"
substituteInPlace ./lib/libzfs/libzfs_mount.c --replace "/bin/umount" "${utillinux}/bin/umount"
substituteInPlace ./lib/libzfs/libzfs_mount.c --replace "/bin/mount" "${utillinux}/bin/mount"
substituteInPlace ./udev/rules.d/* --replace "/lib/udev/vdev_id" "$out/lib/udev/vdev_id"
substituteInPlace ./cmd/ztest/ztest.c --replace "/usr/sbin/ztest" "$out/sbin/ztest"
substituteInPlace ./cmd/ztest/ztest.c --replace "/usr/sbin/zdb" "$out/sbin/zdb"
substituteInPlace ./config/user-systemd.m4 --replace "/usr/lib/modules-load.d" "$out/etc/modules-load.d"
substituteInPlace ./config/zfs-build.m4 --replace "\$sysconfdir/init.d" "$out/etc/init.d"
substituteInPlace ./etc/zfs/Makefile.am --replace "\$(sysconfdir)" "$out/etc"
substituteInPlace ./cmd/zed/Makefile.am --replace "\$(sysconfdir)" "$out/etc"
substituteInPlace ./module/zfs/zfs_ctldir.c --replace "umount -t zfs" "${utillinux}/bin/umount -t zfs"
substituteInPlace ./module/zfs/zfs_ctldir.c --replace "mount -t zfs" "${utillinux}/bin/mount -t zfs"
substituteInPlace ./lib/libzfs/libzfs_mount.c --replace "/bin/umount" "${utillinux}/bin/umount"
substituteInPlace ./lib/libzfs/libzfs_mount.c --replace "/bin/mount" "${utillinux}/bin/mount"
substituteInPlace ./udev/rules.d/* --replace "/lib/udev/vdev_id" "$out/lib/udev/vdev_id"
substituteInPlace ./cmd/ztest/ztest.c --replace "/usr/sbin/ztest" "$out/sbin/ztest"
substituteInPlace ./cmd/ztest/ztest.c --replace "/usr/sbin/zdb" "$out/sbin/zdb"
./autogen.sh
'';
configureFlags = [
"--disable-systemd"
"--enable-systemd"
"--with-linux=${kernel.dev}/lib/modules/${kernel.modDirVersion}/source"
"--with-linux-obj=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
"--with-spl=${spl}/libexec/spl"
"--with-dracutdir=$(out)/lib/dracut"
"--with-udevdir=$(out)/lib/udev"
"--with-systemdunitdir=$(out)/etc/systemd/system"
"--with-systemdpresetdir=$(out)/etc/systemd/system-preset"
"--sysconfdir=/etc"
"--localstatedir=/var"
];
enableParallelBuilding = true;

@ -17,24 +17,32 @@ stdenv.mkDerivation {
NIX_CFLAGS_LINK = "-lgcc_s";
preConfigure = ''
./autogen.sh
substituteInPlace ./module/zfs/zfs_ctldir.c --replace "umount -t zfs" "${utillinux}/bin/umount -t zfs"
substituteInPlace ./module/zfs/zfs_ctldir.c --replace "mount -t zfs" "${utillinux}/bin/mount -t zfs"
substituteInPlace ./lib/libzfs/libzfs_mount.c --replace "/bin/umount" "${utillinux}/bin/umount"
substituteInPlace ./lib/libzfs/libzfs_mount.c --replace "/bin/mount" "${utillinux}/bin/mount"
substituteInPlace ./udev/rules.d/* --replace "/lib/udev/vdev_id" "$out/lib/udev/vdev_id"
substituteInPlace ./cmd/ztest/ztest.c --replace "/usr/sbin/ztest" "$out/sbin/ztest"
substituteInPlace ./cmd/ztest/ztest.c --replace "/usr/sbin/zdb" "$out/sbin/zdb"
substituteInPlace ./config/user-systemd.m4 --replace "/usr/lib/modules-load.d" "$out/etc/modules-load.d"
substituteInPlace ./config/zfs-build.m4 --replace "\$sysconfdir/init.d" "$out/etc/init.d"
substituteInPlace ./etc/zfs/Makefile.am --replace "\$(sysconfdir)" "$out/etc"
substituteInPlace ./cmd/zed/Makefile.am --replace "\$(sysconfdir)" "$out/etc"
substituteInPlace ./module/zfs/zfs_ctldir.c --replace "umount -t zfs" "${utillinux}/bin/umount -t zfs"
substituteInPlace ./module/zfs/zfs_ctldir.c --replace "mount -t zfs" "${utillinux}/bin/mount -t zfs"
substituteInPlace ./lib/libzfs/libzfs_mount.c --replace "/bin/umount" "${utillinux}/bin/umount"
substituteInPlace ./lib/libzfs/libzfs_mount.c --replace "/bin/mount" "${utillinux}/bin/mount"
substituteInPlace ./udev/rules.d/* --replace "/lib/udev/vdev_id" "$out/lib/udev/vdev_id"
substituteInPlace ./cmd/ztest/ztest.c --replace "/usr/sbin/ztest" "$out/sbin/ztest"
substituteInPlace ./cmd/ztest/ztest.c --replace "/usr/sbin/zdb" "$out/sbin/zdb"
./autogen.sh
'';
configureFlags = [
"--disable-systemd"
"--enable-systemd"
"--with-linux=${kernel.dev}/lib/modules/${kernel.modDirVersion}/source"
"--with-linux-obj=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
"--with-spl=${spl_git}/libexec/spl"
"--with-dracutdir=$(out)/lib/dracut"
"--with-udevdir=$(out)/lib/udev"
"--with-systemdunitdir=$(out)/etc/systemd/system"
"--with-systemdpresetdir=$(out)/etc/systemd/system-preset"
"--sysconfdir=/etc"
"--localstatedir=/var"
];
enableParallelBuilding = true;

Loading…
Cancel
Save