@@ -13,112 +13,163 @@ let
1313 buildKernel = any (n: n == configFile) [ "kernel" "all" ];
1414 buildUser = any (n: n == configFile) [ "user" "all" ];
1515
16−in stdenv.mkDerivation rec {
17− name = "zfs-${configFile}-${version}${optionalString buildKernel "-${kernel.version}"}";
18− version = "0.7.1";
19−
20− src = fetchFromGitHub {
21− owner = "zfsonlinux";
22− repo = "zfs";
23− rev = "zfs-${version}";
16+ common = { version
17+ , sha256
18+ , extraPatches
19+ , spl
20+ , rev ? "zfs-${version}"
21+ , isUnstable ? false
22+ , incompatibleKernelVersion ? null } @ args:
23+ if buildKernel &&
24+ (incompatibleKernelVersion != null) &&
25+ versionAtLeast kernel.version incompatibleKernelVersion then
26+ throw ''
27+ Linux v${kernel.version} is not yet supported by zfsonlinux v${version}.
28+ ${stdenv.lib.optional (!isUnstable) "Try zfsUnstable or set the NixOS option boot.zfs.enableUnstable."}
29+ ''
30+ else stdenv.mkDerivation rec {
31+ name = "zfs-${configFile}-${version}${optionalString buildKernel "-${kernel.version}"}";
32+
33+ src = fetchFromGitHub {
34+ owner = "zfsonlinux";
35+ repo = "zfs";
36+ inherit rev sha256;
37+ };
38+
39+ patches = extraPatches;
40+
41+ buildInputs = [ autoreconfHook nukeReferences ]
42+ ++ optionals buildKernel [ spl ]
43+ ++ optionals buildUser [ zlib libuuid python attr ];
44+
45+ # for zdb to get the rpath to libgcc_s, needed for pthread_cancel to work
46+ NIX_CFLAGS_LINK = "-lgcc_s";
47+
48+ hardeningDisable = [ "pic" ];
49+
50+ preConfigure = ''
51+ substituteInPlace ./module/zfs/zfs_ctldir.c --replace "umount -t zfs" "${utillinux}/bin/umount -t zfs"
52+ substituteInPlace ./module/zfs/zfs_ctldir.c --replace "mount -t zfs" "${utillinux}/bin/mount -t zfs"
53+ substituteInPlace ./lib/libzfs/libzfs_mount.c --replace "/bin/umount" "${utillinux}/bin/umount"
54+ substituteInPlace ./lib/libzfs/libzfs_mount.c --replace "/bin/mount" "${utillinux}/bin/mount"
55+ substituteInPlace ./cmd/ztest/ztest.c --replace "/usr/sbin/ztest" "$out/sbin/ztest"
56+ substituteInPlace ./cmd/ztest/ztest.c --replace "/usr/sbin/zdb" "$out/sbin/zdb"
57+ substituteInPlace ./config/user-systemd.m4 --replace "/usr/lib/modules-load.d" "$out/etc/modules-load.d"
58+ substituteInPlace ./config/zfs-build.m4 --replace "\$sysconfdir/init.d" "$out/etc/init.d"
59+ substituteInPlace ./etc/zfs/Makefile.am --replace "\$(sysconfdir)" "$out/etc"
60+ substituteInPlace ./cmd/zed/Makefile.am --replace "\$(sysconfdir)" "$out/etc"
61+ substituteInPlace ./module/Makefile.in --replace "/bin/cp" "cp"
62+ substituteInPlace ./etc/systemd/system/zfs-share.service.in \
63+ --replace "@bindir@/rm " "${coreutils}/bin/rm "
64+
65+ for f in ./udev/rules.d/*
66+ do
67+ substituteInPlace "$f" --replace "/lib/udev/vdev_id" "$out/lib/udev/vdev_id"
68+ done
69+
70+ ./autogen.sh
71+ '';
72+
73+ configureFlags = [
74+ "--with-config=${configFile}"
75+ ] ++ optionals buildUser [
76+ "--with-dracutdir=$(out)/lib/dracut"
77+ "--with-udevdir=$(out)/lib/udev"
78+ "--with-systemdunitdir=$(out)/etc/systemd/system"
79+ "--with-systemdpresetdir=$(out)/etc/systemd/system-preset"
80+ "--with-mounthelperdir=$(out)/bin"
81+ "--sysconfdir=/etc"
82+ "--localstatedir=/var"
83+ "--enable-systemd"
84+ ] ++ optionals buildKernel [
85+ "--with-spl=${spl}/libexec/spl"
86+ "--with-linux=${kernel.dev}/lib/modules/${kernel.modDirVersion}/source"
87+ "--with-linux-obj=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
88+ ];
89+
90+ enableParallelBuilding = true;
91+
92+ installFlags = [
93+ "sysconfdir=\${out}/etc"
94+ "DEFAULT_INITCONF_DIR=\${out}/default"
95+ ];
96+
97+ postInstall = ''
98+ # Prevent kernel modules from depending on the Linux -dev output.
99+ nuke-refs $(find $out -name "*.ko")
100+ '' + optionalString buildUser ''
101+ # Remove provided services as they are buggy
102+ rm $out/etc/systemd/system/zfs-import-*.service
103+
104+ sed -i '/zfs-import-scan.service/d' $out/etc/systemd/system/*
105+
106+ for i in $out/etc/systemd/system/*; do
107+ substituteInPlace $i --replace "zfs-import-cache.service" "zfs-import.target"
108+ done
109+
110+ # Fix pkgconfig.
111+ ln -s ../share/pkgconfig $out/lib/pkgconfig
112+
113+ # Remove tests because they add a runtime dependency on gcc
114+ rm -rf $out/share/zfs/zfs-tests
115+ '';
116+
117+ outputs = [ "out" ] ++ optionals buildUser [ "lib" "dev" ];
118+
119+ meta = {
120+ description = "ZFS Filesystem Linux Kernel module";
121+ longDescription = ''
122+ ZFS is a filesystem that combines a logical volume manager with a
123+ Copy-On-Write filesystem with data integrity detection and repair,
124+ snapshotting, cloning, block devices, deduplication, and more.
125+ '';
126+ home = http://zfsonlinux.org/;
127+ license = licenses.cddl;
128+ platforms = platforms.linux;
129+ maintainers = with maintainers; [ jcumming wizeman wkennington fpletz globin ];
130+ };
131+ };
132+in {
133+ # also check if kernel version constraints in
134+ # ./nixos/modules/tasks/filesystems/zfs.nix needs
135+ # to be adapted
136+ zfsStable = common {
137+ # comment/uncomment if breaking kernel versions are known
138+ incompatibleKernelVersion = null;
139+
140+ # this package should point to the latest release.
141+ version = "0.7.1";
142+
24143 sha256 = "0czal6lpl8igrhwmqh5jcgx07rlcgnrfg6ywzf681vsyh3gaxj9n";
144+
145+ extraPatches = [
146+ (fetchpatch {
147+ url = "https://github.com/Mic92/zfs/compare/zfs-0.7.0-rc3...nixos-zfs-0.7.0-rc3.patch";
148+ sha256 = "1vlw98v8xvi8qapzl1jwm69qmfslwnbg3ry1lmacndaxnyckkvhh";
149+ })
150+ ];
151+
152+ inherit spl;
25153 };
26154
27− patches = [
28− (fetchpatch {
29− url = "https://github.com/Mic92/zfs/compare/zfs-0.7.0-rc3...nixos-zfs-0.7.0-rc3.patch";
30− sha256 = "1vlw98v8xvi8qapzl1jwm69qmfslwnbg3ry1lmacndaxnyckkvhh";
31− })
32− ];
33−
34− buildInputs = [ autoreconfHook nukeReferences ]
35− ++ optionals buildKernel [ spl ]
36− ++ optionals buildUser [ zlib libuuid python attr ];
37−
38− # for zdb to get the rpath to libgcc_s, needed for pthread_cancel to work
39− NIX_CFLAGS_LINK = "-lgcc_s";
40−
41− hardeningDisable = [ "pic" ];
42−
43− preConfigure = ''
44− substituteInPlace ./module/zfs/zfs_ctldir.c --replace "umount -t zfs" "${utillinux}/bin/umount -t zfs"
45− substituteInPlace ./module/zfs/zfs_ctldir.c --replace "mount -t zfs" "${utillinux}/bin/mount -t zfs"
46− substituteInPlace ./lib/libzfs/libzfs_mount.c --replace "/bin/umount" "${utillinux}/bin/umount"
47− substituteInPlace ./lib/libzfs/libzfs_mount.c --replace "/bin/mount" "${utillinux}/bin/mount"
48− substituteInPlace ./cmd/ztest/ztest.c --replace "/usr/sbin/ztest" "$out/sbin/ztest"
49− substituteInPlace ./cmd/ztest/ztest.c --replace "/usr/sbin/zdb" "$out/sbin/zdb"
50− substituteInPlace ./config/user-systemd.m4 --replace "/usr/lib/modules-load.d" "$out/etc/modules-load.d"
51− substituteInPlace ./config/zfs-build.m4 --replace "\$sysconfdir/init.d" "$out/etc/init.d"
52− substituteInPlace ./etc/zfs/Makefile.am --replace "\$(sysconfdir)" "$out/etc"
53− substituteInPlace ./cmd/zed/Makefile.am --replace "\$(sysconfdir)" "$out/etc"
54− substituteInPlace ./module/Makefile.in --replace "/bin/cp" "cp"
55− substituteInPlace ./etc/systemd/system/zfs-share.service.in \
56− --replace "@bindir@/rm " "${coreutils}/bin/rm "
57−
58− for f in ./udev/rules.d/*
59− do
60− substituteInPlace "$f" --replace "/lib/udev/vdev_id" "$out/lib/udev/vdev_id"
61− done
62−
63− ./autogen.sh
64− '';
65−
66− configureFlags = [
67− "--with-config=${configFile}"
68− ] ++ optionals buildUser [
69− "--with-dracutdir=$(out)/lib/dracut"
70− "--with-udevdir=$(out)/lib/udev"
71− "--with-systemdunitdir=$(out)/etc/systemd/system"
72− "--with-systemdpresetdir=$(out)/etc/systemd/system-preset"
73− "--with-mounthelperdir=$(out)/bin"
74− "--sysconfdir=/etc"
75− "--localstatedir=/var"
76− "--enable-systemd"
77− ] ++ optionals buildKernel [
78− "--with-spl=${spl}/libexec/spl"
79− "--with-linux=${kernel.dev}/lib/modules/${kernel.modDirVersion}/source"
80− "--with-linux-obj=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
81− ];
82−
83− enableParallelBuilding = true;
84−
85− installFlags = [
86− "sysconfdir=\${out}/etc"
87− "DEFAULT_INITCONF_DIR=\${out}/default"
88− ];
89−
90− postInstall = ''
91− # Prevent kernel modules from depending on the Linux -dev output.
92− nuke-refs $(find $out -name "*.ko")
93− '' + optionalString buildUser ''
94− # Remove provided services as they are buggy
95− rm $out/etc/systemd/system/zfs-import-*.service
96−
97− sed -i '/zfs-import-scan.service/d' $out/etc/systemd/system/*
98−
99− for i in $out/etc/systemd/system/*; do
100− substituteInPlace $i --replace "zfs-import-cache.service" "zfs-import.target"
101− done
102−
103− # Fix pkgconfig.
104− ln -s ../share/pkgconfig $out/lib/pkgconfig
105−
106− # Remove tests because they add a runtime dependency on gcc
107− rm -rf $out/share/zfs/zfs-tests
108− '';
109−
110− outputs = [ "out" ] ++ optionals buildUser [ "lib" "dev" ];
111−
112− meta = {
113− description = "ZFS Filesystem Linux Kernel module";
114− longDescription = ''
115− ZFS is a filesystem that combines a logical volume manager with a
116− Copy-On-Write filesystem with data integrity detection and repair,
117− snapshotting, cloning, block devices, deduplication, and more.
118− '';
119− homepage = http://zfsonlinux.org/;
120− license = licenses.cddl;
121− platforms = platforms.linux;
122− maintainers = with maintainers; [ jcumming wizeman wkennington fpletz globin ];
155+ zfsUnstable = common {
156+ # comment/uncomment if breaking kernel versions are known
157+ incompatibleKernelVersion = null;
158+
159+ # this package should point to a version / git revision compatible with the latest kernel release
160+ version = "2017-09-12";
161+
162+ rev = "ded8f06a3cfee60b3a8ea5309e9c4d0e567ed3b5";
163+ sha256 = "0yn4fg4a00hpflmmr0jbbhfb921nygpw2xbbjy35abl57k6zk375";
164+ isUnstable = true;
165+
166+ extraPatches = [
167+ (fetchpatch {
168+ url = "https://github.com/Mic92/zfs/compare/ded8f06a3cfee...nixos-zfs-2017-09-12.patch";
169+ sha256 = "033wf4jn0h0kp0h47ai98rywnkv5jwvf3xwym30phnaf8xxdx8aj";
170+ })
171+ ];
172+
173+ spl = splUnstable;
123174 };
124175}