nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
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 versionCheckHook,
23 nixosTests,
24 installShellFiles,
25 fuseSupport ? false,
26 udevCheckHook,
27}:
28
29stdenv.mkDerivation (finalAttrs: {
30 pname = "bcachefs-tools";
31 version = "1.35.2";
32
33 src = fetchFromGitHub {
34 owner = "koverstreet";
35 repo = "bcachefs-tools";
36 tag = "v${finalAttrs.version}";
37 hash = "sha256-YreeoI9ct3Gt0za3bW4cFP8mA3mrgpVnHVUzfX1m5CI=";
38 };
39
40 cargoDeps = rustPlatform.fetchCargoVendor {
41 inherit (finalAttrs) src;
42 hash = "sha256-1TxACD4xXZ3BfVdoQUCzWe5Ovv0tKw6ALBw0+tRLOaQ=";
43 };
44
45 postPatch = ''
46 substituteInPlace Makefile \
47 --replace-fail "target/release/bcachefs" "target/${stdenv.hostPlatform.rust.rustcTargetSpec}/release/bcachefs"
48 '';
49
50 nativeBuildInputs = [
51 pkg-config
52 cargo
53 rustc
54 rustPlatform.cargoSetupHook
55 rustPlatform.bindgenHook
56 makeWrapper
57 installShellFiles
58 ];
59
60 buildInputs = [
61 libaio
62 keyutils
63 lz4
64 libsodium
65 liburcu
66 libuuid
67 zstd
68 zlib
69 attr
70 udev
71 ]
72 ++ lib.optional fuseSupport fuse3;
73
74 makeFlags = [
75 "PREFIX=${placeholder "out"}"
76 "VERSION=${finalAttrs.version}"
77 "INITRAMFS_DIR=${placeholder "out"}/etc/initramfs-tools"
78 "DKMSDIR=${placeholder "dkms"}"
79
80 # Tries to install to the 'systemd-minimal' and 'udev' nix installation paths
81 "PKGCONFIG_SERVICEDIR=$(out)/lib/systemd/system"
82 "PKGCONFIG_UDEVDIR=$(out)/lib/udev"
83 ]
84 ++ lib.optional fuseSupport "BCACHEFS_FUSE=1";
85
86 enableParallelBuilding = true;
87
88 installFlags = [
89 "install"
90 "install_dkms"
91 ];
92
93 env = {
94 CARGO_BUILD_TARGET = stdenv.hostPlatform.rust.rustcTargetSpec;
95 "CARGO_TARGET_${stdenv.hostPlatform.rust.cargoEnvVarTarget}_LINKER" = "${stdenv.cc.targetPrefix}cc";
96 };
97
98 # FIXME: Try enabling this once the default linux kernel is at least 6.7
99 doCheck = false; # needs bcachefs module loaded on builder
100
101 preCheck = lib.optionalString (!fuseSupport) ''
102 rm tests/test_fuse.py
103 '';
104 checkFlags = [ "BCACHEFS_TEST_USE_VALGRIND=no" ];
105
106 doInstallCheck = true;
107 nativeInstallCheckInputs = [
108 udevCheckHook
109 versionCheckHook
110 ];
111 versionCheckProgramArg = "version";
112
113 postInstall = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
114 installShellCompletion --cmd bcachefs \
115 --bash <($out/sbin/bcachefs completions bash) \
116 --zsh <($out/sbin/bcachefs completions zsh) \
117 --fish <($out/sbin/bcachefs completions fish)
118 '';
119
120 outputs = [
121 "out"
122 "dkms"
123 ];
124
125 passthru = {
126 # See NOTE in linux-kernels.nix
127 kernelModule = import ./kernel-module.nix finalAttrs.finalPackage;
128
129 tests = {
130 smoke-test = nixosTests.bcachefs;
131 inherit (nixosTests.installer) bcachefsSimple bcachefsEncrypted bcachefsMulti;
132 };
133
134 updateScript = nix-update-script { };
135 };
136
137 meta = {
138 description = "Tool for managing bcachefs filesystems";
139 homepage = "https://bcachefs.org/";
140 downloadPage = "https://github.com/koverstreet/bcachefs-tools";
141 license = lib.licenses.gpl2Only;
142 maintainers = with lib.maintainers; [
143 davidak
144 johnrtitor
145 ];
146 platforms = lib.platforms.linux;
147 mainProgram = "bcachefs";
148 broken = stdenv.hostPlatform.isi686; # error: stack smashing detected
149 };
150})