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.
This commit is contained in:
Ricardo M. Correia 2014-10-22 18:48:57 +02:00
parent ace49e400c
commit 3b0fa60a98
3 changed files with 43 additions and 47 deletions

View File

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

View File

@ -20,24 +20,32 @@ stdenv.mkDerivation {
NIX_CFLAGS_LINK = "-lgcc_s"; NIX_CFLAGS_LINK = "-lgcc_s";
preConfigure = '' 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" ./autogen.sh
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"
''; '';
configureFlags = [ configureFlags = [
"--disable-systemd" "--enable-systemd"
"--with-linux=${kernel.dev}/lib/modules/${kernel.modDirVersion}/source" "--with-linux=${kernel.dev}/lib/modules/${kernel.modDirVersion}/source"
"--with-linux-obj=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build" "--with-linux-obj=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
"--with-spl=${spl}/libexec/spl" "--with-spl=${spl}/libexec/spl"
"--with-dracutdir=$(out)/lib/dracut" "--with-dracutdir=$(out)/lib/dracut"
"--with-udevdir=$(out)/lib/udev" "--with-udevdir=$(out)/lib/udev"
"--with-systemdunitdir=$(out)/etc/systemd/system"
"--with-systemdpresetdir=$(out)/etc/systemd/system-preset"
"--sysconfdir=/etc"
"--localstatedir=/var"
]; ];
enableParallelBuilding = true; enableParallelBuilding = true;

View File

@ -17,24 +17,32 @@ stdenv.mkDerivation {
NIX_CFLAGS_LINK = "-lgcc_s"; NIX_CFLAGS_LINK = "-lgcc_s";
preConfigure = '' 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" ./autogen.sh
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"
''; '';
configureFlags = [ configureFlags = [
"--disable-systemd" "--enable-systemd"
"--with-linux=${kernel.dev}/lib/modules/${kernel.modDirVersion}/source" "--with-linux=${kernel.dev}/lib/modules/${kernel.modDirVersion}/source"
"--with-linux-obj=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build" "--with-linux-obj=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
"--with-spl=${spl_git}/libexec/spl" "--with-spl=${spl_git}/libexec/spl"
"--with-dracutdir=$(out)/lib/dracut" "--with-dracutdir=$(out)/lib/dracut"
"--with-udevdir=$(out)/lib/udev" "--with-udevdir=$(out)/lib/udev"
"--with-systemdunitdir=$(out)/etc/systemd/system"
"--with-systemdpresetdir=$(out)/etc/systemd/system-preset"
"--sysconfdir=/etc"
"--localstatedir=/var"
]; ];
enableParallelBuilding = true; enableParallelBuilding = true;