lol
1{ lib
2, stdenv
3, runCommand
4, fetchFromGitHub
5, bash
6, btrfs-progs
7, coreutils
8, python3Packages
9, util-linux
10, nixosTests
11}:
12
13let
14
15 bees = stdenv.mkDerivation rec {
16 pname = "bees";
17 version = "0.9.3";
18
19 src = fetchFromGitHub {
20 owner = "Zygo";
21 repo = "bees";
22 rev = "v${version}";
23 sha256 = "sha256-krG8TzfOz3m7h3GfkBU+NJz7EdlXiWOOXY8bQRq9z4Q=";
24 };
25
26 buildInputs = [
27 btrfs-progs # for btrfs/ioctl.h
28 util-linux # for uuid.h
29 ];
30
31 nativeBuildInputs = [
32 python3Packages.markdown # documentation build
33 ];
34
35 preBuild = ''
36 git() { if [[ $1 = describe ]]; then echo ${version}; else command git "$@"; fi; }
37 export -f git
38 '';
39
40 postBuild = ''
41 unset -f git
42 '';
43
44 buildFlags = [
45 "ETC_PREFIX=/var/run/bees/configs"
46 ];
47
48 makeFlags = [
49 "SHELL=bash"
50 "PREFIX=$(out)"
51 "ETC_PREFIX=$(out)/etc"
52 "BEES_VERSION=${version}"
53 "SYSTEMD_SYSTEM_UNIT_DIR=$(out)/etc/systemd/system"
54 ];
55
56 meta = with lib; {
57 homepage = "https://github.com/Zygo/bees";
58 description = "Block-oriented BTRFS deduplication service";
59 longDescription = "Best-Effort Extent-Same: bees finds not just identical files, but also identical extents within files that differ";
60 license = licenses.gpl3;
61 platforms = platforms.linux;
62 maintainers = with maintainers; [ chaduffy ];
63 };
64 };
65
66in
67
68(runCommand "bees-service"
69 {
70 inherit bash bees coreutils;
71 utillinux = util-linux; # needs to be a valid shell variable name
72 btrfsProgs = btrfs-progs; # needs to be a valid shell variable name
73 } ''
74 mkdir -p -- "$out/bin"
75 substituteAll ${./bees-service-wrapper} "$out"/bin/bees-service-wrapper
76 chmod +x "$out"/bin/bees-service-wrapper
77 ln -s ${bees}/bin/beesd "$out"/bin/beesd
78'').overrideAttrs {
79 passthru.tests = {
80 smoke-test = nixosTests.bees;
81 };
82}