Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
description = "Nix flake for OpenZFS (ZFS)";

# The inputs, such as Nixpkgs and flake-utils
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; # Adjust to the desired channel or version

flake-utils.url = "github:numtide/flake-utils";
};

# Outputs from this flake (e.g. packages, system configurations)
outputs =
{
nixpkgs,
flake-utils,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
};
openzfs = pkgs.callPackage ./nix/default.nix {
kernel = pkgs.linux_6_12;
};
in
{
packages.default = openzfs;

checks.zts = pkgs.testers.runNixOSTest (import ./nix/test.nix { inherit openzfs; });
}
);
}
138 changes: 138 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
{
stdenv,
lib,
pkgs,
kernel,
kernelModuleMakeFlags ? [ ],
autoreconfHook,
attr,
coreutils,
gawk,
gnused,
gnugrep,
ksh,
libtirpc,
libuuid,
nukeReferences,
openssl,
pam,
pkg-config,
python3,
systemd,
udevCheckHook,
zlib,
}:

stdenv.mkDerivation {
pname = "zfs";
version = "2.3.4-${kernel.version}"; # Specify the version of ZFS you want

src = ./..;

preConfigure = ''
# The kernel module builds some tests during the configurePhase, this envvar controls their parallelism
export TEST_JOBS=$NIX_BUILD_CORES
if [ -z "$enableParallelBuilding" ]; then
export TEST_JOBS=1
fi
'';

postPatch = ''
patchShebangs scripts tests

substituteInPlace ./config/user-systemd.m4 --replace-fail "/usr/lib/modules-load.d" "$out/etc/modules-load.d"
substituteInPlace ./config/zfs-build.m4 --replace-fail "\$sysconfdir/init.d" "$out/etc/init.d" \
--replace-fail "/etc/default" "$out/etc/default"
substituteInPlace ./contrib/initramfs/Makefile.am \
--replace-fail "/usr/share/initramfs-tools" "$out/usr/share/initramfs-tools"

substituteInPlace ./udev/vdev_id \
--replace-fail "PATH=/bin:/sbin:/usr/bin:/usr/sbin" \
"PATH=${
lib.makeBinPath [
coreutils
gawk
gnused
gnugrep
systemd
]
}"

substituteInPlace ./config/zfs-build.m4 \
--replace-fail "bashcompletiondir=/etc/bash_completion.d" \
"bashcompletiondir=$out/share/bash-completion/completions" \
--replace-fail 'DEBUG_CFLAGS="-Werror"' ' '

# Tests
# Not required with Nix
sed -i s/"^constrain_path$"/""/ scripts/zfs-tests.sh
substituteInPlace ./scripts/zfs-tests.sh \
--replace-fail '"$STF_PATH/ksh"' "${lib.getExe pkgs.ksh}"
substituteInPlace ./tests/test-runner/bin/test-runner.py.in \
--replace-fail "/usr/share/zfs/" "$out/share/zfs/" \
--replace-fail "KILL = 'kill'" "KILL = '${lib.getExe' pkgs.coreutils "kill"}'" \
--replace-fail "SUDO = 'sudo'" "SUDO = '/run/wrappers/bin/sudo'" \
--replace-fail "TRUE = 'true'" "TRUE = '${lib.getExe' pkgs.coreutils "true"}'"
'';

buildInputs = [
attr
libtirpc
libuuid
openssl
pam
python3
systemd
zlib
];

nativeBuildInputs = [
autoreconfHook
ksh
nukeReferences
pkg-config
udevCheckHook
kernel.moduleBuildDependencies
];

enableParallelBuilding = true;

configureFlags = [
"--with-linux=${kernel.dev}/lib/modules/${kernel.modDirVersion}/source"
"--with-linux-obj=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
"--with-dracutdir=$(out)/lib/dracut"
"--with-udevdir=$(out)/lib/udev"
"--with-systemdunitdir=$(out)/etc/systemd/system"
"--with-systemdpresetdir=$(out)/etc/systemd/system-preset"
"--with-systemdgeneratordir=$(out)/lib/systemd/system-generator"
"--with-mounthelperdir=$(out)/bin"
"--libexecdir=$(out)/libexec"
"--sysconfdir=/etc"
"--localstatedir=/var"
"--enable-systemd"
"--enable-pam"

# Debug
"--enable-debug"
"--enable-debuginfo"
"--enable-asan"
"--enable-ubsan"
"--enable-debug-kmem"
"--enable-debug-kmem-tracking"
]
++ map (f: "KERNEL_${f}") kernelModuleMakeFlags;

doInstallCheck = true;

installFlags = [
"sysconfdir=\${out}/etc"
"DEFAULT_INITCONF_DIR=\${out}/default"
"INSTALL_MOD_PATH=\${out}"
];

meta = with lib; {
description = "OpenZFS on Linux";
license = licenses.cddl;
platforms = platforms.linux;
};
}
95 changes: 95 additions & 0 deletions nix/test.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{ openzfs, ... }:

{
name = "zts";

globalTimeout = 24 * 60 * 60;

nodes = {
machine =
{ pkgs, lib, ... }:
{
virtualisation = {
cores = 4;
diskSize = 10 * 1024;
memorySize = 16 * 1024;
};

boot.kernelPatches = [
{
name = "enable KASAN";
patch = null;
extraConfig = ''
KASAN y
DEBUG_KMEMLEAK y
GCOV_KERNEL y
'';
}
];

boot.kernelParams = [
"kasan.fault=report"
];

boot.loader.systemd-boot.enable = true;
boot.initrd.systemd.enable = true;

networking.hostId = "deadbeef";
boot.zfs.package = openzfs;
boot.zfs.modulePackage = openzfs;
boot.supportedFilesystems = [ "zfs" ];

environment.systemPackages =
let
zfsTestsScript = pkgs.writeShellScriptBin "zfs-tests" ''
export STF_PATH=${
lib.makeBinPath [
pkgs.bash
pkgs.coreutils
pkgs.bzip2
pkgs.gawk
pkgs.ksh
pkgs.lvm2
pkgs.su
pkgs.sudo
pkgs.systemd
pkgs.util-linux
openzfs
]
};
export LOSETUP="${lib.getExe' pkgs.util-linux "losetup"}"
export DMSETUP="${lib.getExe' pkgs.lvm2.bin "dmsetup"}"
${openzfs}/share/zfs/zfs-tests.sh -K -m -v -x
'';
in
[
zfsTestsScript
openzfs
];

users.users.tester = {
isNormalUser = true;
description = "ZFS tester";
password = "foobar";
extraGroups = [ "wheel" ];
};

security.sudo.wheelNeedsPassword = false;
};

};

testScript = ''
machine.wait_for_unit("multi-user.target")
machine.log(machine.succeed(
"sudo -u tester -- zfs-tests"
))
_, report_location = machine.execute("find /tmp -name zts-report")
machine.copy_from_vm(report_location, "")
'';
}
Loading