1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 pkg-config,
6 libuuid,
7 libsodium,
8 keyutils,
9 liburcu,
10 zlib,
11 libaio,
12 zstd,
13 lz4,
14 attr,
15 udev,
16 fuse3,
17 cargo,
18 rustc,
19 rustPlatform,
20 makeWrapper,
21 nix-update-script,
22 python3,
23 testers,
24 nixosTests,
25 installShellFiles,
26 fuseSupport ? false,
27 udevCheckHook,
28}:
29
30stdenv.mkDerivation (finalAttrs: {
31 pname = "bcachefs-tools";
32 version = "1.25.3";
33
34 src = fetchFromGitHub {
35 owner = "koverstreet";
36 repo = "bcachefs-tools";
37 tag = "v${finalAttrs.version}";
38 hash = "sha256-Nij4mOJPVA03u6mpyKsFR7vgQ9wihiNfnlSlh6MNXP0=";
39 };
40
41 nativeBuildInputs = [
42 pkg-config
43 cargo
44 rustc
45 rustPlatform.cargoSetupHook
46 rustPlatform.bindgenHook
47 makeWrapper
48 installShellFiles
49 udevCheckHook
50 ];
51
52 buildInputs = [
53 libaio
54 keyutils
55 lz4
56
57 libsodium
58 liburcu
59 libuuid
60 zstd
61 zlib
62 attr
63 udev
64 ]
65 ++ lib.optional fuseSupport fuse3;
66
67 cargoDeps = rustPlatform.fetchCargoVendor {
68 src = finalAttrs.src;
69 hash = "sha256-QkpsAQSoCmAihrE5YGzp9DalEQr+2djiPhLTXRn0u6U=";
70 };
71
72 makeFlags = [
73 "PREFIX=${placeholder "out"}"
74 "VERSION=${finalAttrs.version}"
75 "INITRAMFS_DIR=${placeholder "out"}/etc/initramfs-tools"
76
77 # Tries to install to the 'systemd-minimal' and 'udev' nix installation paths
78 "PKGCONFIG_SERVICEDIR=$(out)/lib/systemd/system"
79 "PKGCONFIG_UDEVDIR=$(out)/lib/udev"
80 ]
81 ++ lib.optional fuseSupport "BCACHEFS_FUSE=1";
82
83 env = {
84 CARGO_BUILD_TARGET = stdenv.hostPlatform.rust.rustcTargetSpec;
85 "CARGO_TARGET_${stdenv.hostPlatform.rust.cargoEnvVarTarget}_LINKER" = "${stdenv.cc.targetPrefix}cc";
86 };
87
88 # FIXME: Try enabling this once the default linux kernel is at least 6.7
89 doCheck = false; # needs bcachefs module loaded on builder
90
91 doInstallCheck = true;
92
93 postPatch = ''
94 substituteInPlace Makefile \
95 --replace-fail "target/release/bcachefs" "target/${stdenv.hostPlatform.rust.rustcTargetSpec}/release/bcachefs"
96 '';
97
98 preCheck = lib.optionalString (!fuseSupport) ''
99 rm tests/test_fuse.py
100 '';
101 checkFlags = [ "BCACHEFS_TEST_USE_VALGRIND=no" ];
102
103 postInstall = ''
104 substituteInPlace $out/libexec/bcachefsck_all \
105 --replace-fail "/usr/bin/python3" "${python3.interpreter}"
106 ''
107 + lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
108 installShellCompletion --cmd bcachefs \
109 --bash <($out/sbin/bcachefs completions bash) \
110 --zsh <($out/sbin/bcachefs completions zsh) \
111 --fish <($out/sbin/bcachefs completions fish)
112 '';
113
114 passthru = {
115 tests = {
116 version = testers.testVersion {
117 package = finalAttrs.finalPackage;
118 command = "${finalAttrs.meta.mainProgram} version";
119 version = "${finalAttrs.version}";
120 };
121 smoke-test = nixosTests.bcachefs;
122 inherit (nixosTests.installer) bcachefsSimple bcachefsEncrypted bcachefsMulti;
123 };
124
125 updateScript = nix-update-script { };
126 };
127
128 enableParallelBuilding = true;
129
130 meta = {
131 description = "Tool for managing bcachefs filesystems";
132 homepage = "https://bcachefs.org/";
133 license = lib.licenses.gpl2Only;
134 maintainers = with lib.maintainers; [
135 davidak
136 johnrtitor
137 Madouura
138 ];
139 platforms = lib.platforms.linux;
140 mainProgram = "bcachefs";
141 };
142})