bcachefs-tools/default.nix

129 lines
2.4 KiB
Nix
Raw Normal View History

{ lib
, doCheck ? true
, stdenv
, pkg-config
, attr
, libuuid
, libsodium
, keyutils
, liburcu
, zlib
, libaio
, udev
, zstd
, lz4
, python39
, python39Packages
, docutils
, nixosTests
, versionString ? "0.1"
, inShell ? false
, debugMode ? inShell
, testWithValgrind ? true
, valgrind
, fuseSupport ? false
, fuse3 ? null }:
assert fuseSupport -> fuse3 != null;
assert testWithValgrind -> valgrind != null;
stdenv.mkDerivation {
pname = "bcachefs-tools";
version = "v0.1-flake-${versionString}";
VERSION = "v0.1-flake-${versionString}";
src = (lib.cleanSource (builtins.path { name = "bcachefs-tools-src"; path = ./. ;} ));
postPatch = "patchShebangs --build doc/macro2rst.py";
nativeBuildInputs = [
# used to find dependencies
## see ./INSTALL
pkg-config
];
buildInputs = [
# bcachefs explicit dependencies
## see ./INSTALL
libaio
# libblkid
keyutils # libkeyutils
lz4 # liblz4
libsodium
liburcu
libuuid
zstd # libzstd
zlib # zlib1g
valgrind
# unspecified dependencies
attr
udev
# documentation depenedencies
docutils
python39Packages.pygments
] ++ (lib.optional fuseSupport fuse3)
++ (lib.optional testWithValgrind valgrind) ;
makeFlags = [
"PREFIX=${placeholder "out"}"
] ++ lib.optional debugMode "EXTRA_CFLAGS=-ggdb";
installFlags = [
"INITRAMFS_DIR=${placeholder "out"}/etc/initramfs-tools"
];
doCheck = doCheck; # needs bcachefs module loaded on builder
checkInputs = [
python39Packages.pytest
python39Packages.pytest-xdist
] ++ lib.optional testWithValgrind valgrind;
checkFlags = [
"BCACHEFS_TEST_USE_VALGRIND=${if testWithValgrind then "yes" else "no"}"
# cannot escape spaces within make flags, quotes are stripped
"PYTEST_CMD=pytest" # "PYTEST_ARGS='-n4 --version'"
];
preCheck =
''
2021-10-20 17:13:13 +03:00
makeFlagsArray+=(PYTEST_ARGS="--verbose -n2")
'' +
lib.optionalString fuseSupport ''
rm tests/test_fuse.py
'';
dontStrip = debugMode;
passthru = {
bcachefs_revision = let
file = builtins.readFile ./.bcachefs_revision;
removeLineFeeds = str: lib.lists.foldr (lib.strings.removeSuffix) str ["\r" "\n"];
in removeLineFeeds file;
tests = {
smoke-test = nixosTests.bcachefs;
};
};
enableParallelBuilding = true;
meta = with lib; {
description = "Userspace tools for bcachefs";
homepage = http://bcachefs.org;
license = licenses.gpl2;
platforms = platforms.linux;
maintainers =
[ "Kent Overstreet <kent.overstreet@gmail.com>"
];
};
nix: add nix expressions for development This adds Nix expressions for bcachefs-tools that are modular, work in purely sandboxed build environments (e.g. on NixOS itself, or macOS, where sandboxing is enabled by default), use a fixed copy of Nixpkgs (to avoid hidden, global state) and uses standard build idioms. This change uses a fixed version of Nixpkgs, one that will always be used for every build of bcachefs-tools, for all users, rather than relying on whatever copy of Nixpkgs the user has available. This has a major benefit in that it allows the build to work in sandboxed environments such as NixOS, and it correctly declares all of the necessary dependencies that bcachefs-tools needs. This is done simply by using stdenv.mkDerivation in order to write a "normal" Nix expression, where the previous version used a variant of the stdenv builder, but this isn't needed for the most part. (Doing this has other knock-on benefits, such as the usage of standardized options like `enableParallelBuild = true;` -- allowing `nix-build` to automatically do parallel builds, etc.) Another major benefit of this change is that anyone can now use `nix-shell` to develop/hack on bcachefs-tools incrementally; simply running nix-shell will put you in a Bash shell environment where all of bcachefs-tools' dependencies are proprerly provided, no matter the state of the outside build environment/host operating system: $ nix-shell [nix-shell:~/src/bcachefs-tools]$ make -j4 # works immediately As mentioned before, with this change, by default, nix-build and nix-shell run using a prepackaged copy of an upstream Nixpkgs snapshot. This is done purely to ensure anyone who builds bcachefs-tools using Nix does, in fact, get a reproducible build. Without this, nix-build defaults to using the the `<nixpkgs>` NIX_PATH entry in order to fetch dependencies; meaning that two users on different channels will get different results (for example, if you have the November 2017 channel but I have the October 2017 channel, the results may be different). With this patch, a user running $ nix-build will always use the exact same copy of nixpkgs to bootstrap the build, regardless of whatever channels the user has. This bootstrap mechanism does not even depend on an existing copy of Nixpkgs itself; e.g. it can work with a completely empty `NIX_PATH`. This is arguably anti-modular, but for end-user applications like bcachefs-tools, fixing the version of Nixpkgs is not normally a huge deal. Users who wish to use a different copy of Nixpkgs can provide this with an argument to nix-build directly, using the `nixpkgs` argument to the expression: $ nix-build --pure --arg nixpkgs 'import <nixpkgs> {}' This uses the `<nixpkgs>` provided inside your `NIX_PATH` environment variable to acquire dependencies, which by default is managed using `nix-channel`. If you have a copy of the Nixpkgs source code e.g. from a `git clone`, you may use that too by simply using `-I` to prepend your Nixpkgs to `NIX_PATH` (see `man nix-build` for more): $ nix-build --pure \ -I nixpkgs=$HOME/src/nixpkgs \ --arg nixpkgs 'import <nixpkgs> {}' Signed-off-by: Austin Seipp <aseipp@pobox.com>
2017-11-26 09:20:14 +03:00
}