Skip to content

Commit 536f2e6

Browse files
committed
nix: Initial commit of flake
1 parent e63d026 commit 536f2e6

File tree

3 files changed

+231
-0
lines changed

3 files changed

+231
-0
lines changed

flake.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
description = "Nix flake for OpenZFS (ZFS)";
3+
4+
# The inputs, such as Nixpkgs and flake-utils
5+
inputs = {
6+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; # Adjust to the desired channel or version
7+
8+
flake-utils.url = "github:numtide/flake-utils";
9+
};
10+
11+
# Outputs from this flake (e.g. packages, system configurations)
12+
outputs =
13+
{
14+
nixpkgs,
15+
flake-utils,
16+
...
17+
}:
18+
flake-utils.lib.eachDefaultSystem (
19+
system:
20+
let
21+
pkgs = import nixpkgs {
22+
inherit system;
23+
};
24+
openzfs = pkgs.callPackage ./nix/default.nix {
25+
kernel = pkgs.linux_6_12;
26+
};
27+
in
28+
{
29+
packages.default = openzfs;
30+
}
31+
);
32+
}

nix/default.nix

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
{
2+
stdenv,
3+
lib,
4+
pkgs,
5+
kernel,
6+
kernelModuleMakeFlags ? [ ],
7+
autoreconfHook,
8+
attr,
9+
coreutils,
10+
gawk,
11+
gnused,
12+
gnugrep,
13+
ksh,
14+
libtirpc,
15+
libuuid,
16+
nukeReferences,
17+
openssl,
18+
pam,
19+
pkg-config,
20+
python3,
21+
systemd,
22+
udevCheckHook,
23+
zlib,
24+
}:
25+
26+
stdenv.mkDerivation {
27+
pname = "zfs";
28+
version = "2.3.4-${kernel.version}"; # Specify the version of ZFS you want
29+
30+
src = ./..;
31+
32+
preConfigure = ''
33+
# The kernel module builds some tests during the configurePhase, this envvar controls their parallelism
34+
export TEST_JOBS=$NIX_BUILD_CORES
35+
if [ -z "$enableParallelBuilding" ]; then
36+
export TEST_JOBS=1
37+
fi
38+
'';
39+
40+
postPatch = ''
41+
patchShebangs scripts tests
42+
43+
substituteInPlace ./config/user-systemd.m4 --replace-fail "/usr/lib/modules-load.d" "$out/etc/modules-load.d"
44+
substituteInPlace ./config/zfs-build.m4 --replace-fail "\$sysconfdir/init.d" "$out/etc/init.d" \
45+
--replace-fail "/etc/default" "$out/etc/default"
46+
substituteInPlace ./contrib/initramfs/Makefile.am \
47+
--replace-fail "/usr/share/initramfs-tools" "$out/usr/share/initramfs-tools"
48+
49+
substituteInPlace ./udev/vdev_id \
50+
--replace-fail "PATH=/bin:/sbin:/usr/bin:/usr/sbin" \
51+
"PATH=${
52+
lib.makeBinPath [
53+
coreutils
54+
gawk
55+
gnused
56+
gnugrep
57+
systemd
58+
]
59+
}"
60+
61+
substituteInPlace ./config/zfs-build.m4 \
62+
--replace-fail "bashcompletiondir=/etc/bash_completion.d" \
63+
"bashcompletiondir=$out/share/bash-completion/completions" \
64+
--replace-fail 'DEBUG_CFLAGS="-Werror"' ' '
65+
66+
# Tests
67+
# Not required with Nix
68+
sed -i s/"^constrain_path$"/""/ scripts/zfs-tests.sh
69+
substituteInPlace ./scripts/zfs-tests.sh \
70+
--replace-fail '"$STF_PATH/ksh"' "${lib.getExe pkgs.ksh}"
71+
substituteInPlace ./tests/test-runner/bin/test-runner.py.in \
72+
--replace-fail "/usr/share/zfs/" "$out/share/zfs/" \
73+
--replace-fail "KILL = 'kill'" "KILL = '${lib.getExe' pkgs.coreutils "kill"}'" \
74+
--replace-fail "SUDO = 'sudo'" "SUDO = '/run/wrappers/bin/sudo'" \
75+
--replace-fail "TRUE = 'true'" "TRUE = '${lib.getExe' pkgs.coreutils "true"}'"
76+
'';
77+
78+
buildInputs = [
79+
attr
80+
libtirpc
81+
libuuid
82+
openssl
83+
pam
84+
python3
85+
systemd
86+
zlib
87+
];
88+
89+
nativeBuildInputs = [
90+
autoreconfHook
91+
ksh
92+
nukeReferences
93+
pkg-config
94+
udevCheckHook
95+
kernel.moduleBuildDependencies
96+
];
97+
98+
enableParallelBuilding = true;
99+
100+
configureFlags = [
101+
"--with-linux=${kernel.dev}/lib/modules/${kernel.modDirVersion}/source"
102+
"--with-linux-obj=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
103+
"--with-dracutdir=$(out)/lib/dracut"
104+
"--with-udevdir=$(out)/lib/udev"
105+
"--with-systemdunitdir=$(out)/etc/systemd/system"
106+
"--with-systemdpresetdir=$(out)/etc/systemd/system-preset"
107+
"--with-systemdgeneratordir=$(out)/lib/systemd/system-generator"
108+
"--with-mounthelperdir=$(out)/bin"
109+
"--libexecdir=$(out)/libexec"
110+
"--sysconfdir=/etc"
111+
"--localstatedir=/var"
112+
"--enable-systemd"
113+
"--enable-pam"
114+
115+
# Debug
116+
"--enable-debug"
117+
"--enable-debuginfo"
118+
"--enable-asan"
119+
"--enable-ubsan"
120+
"--enable-debug-kmem"
121+
"--enable-debug-kmem-tracking"
122+
]
123+
++ map (f: "KERNEL_${f}") kernelModuleMakeFlags;
124+
125+
doInstallCheck = true;
126+
127+
installFlags = [
128+
"sysconfdir=\${out}/etc"
129+
"DEFAULT_INITCONF_DIR=\${out}/default"
130+
"INSTALL_MOD_PATH=\${out}"
131+
];
132+
133+
meta = with lib; {
134+
description = "OpenZFS on Linux";
135+
license = licenses.cddl;
136+
platforms = platforms.linux;
137+
};
138+
}

0 commit comments

Comments
 (0)