1{ version, sha256Hash, maintainers }:
2
3{ stdenv, fetchFromGitHub, fetchpatch
4, fusePackages, utillinux, gettext
5, autoconf, automake, libtool
6, meson, ninja, pkgconfig
7}:
8
9let
10 isFuse3 = stdenv.lib.hasPrefix "3" version;
11in stdenv.mkDerivation rec {
12 name = "fuse-${version}";
13
14 src = fetchFromGitHub {
15 owner = "libfuse";
16 repo = "libfuse";
17 rev = name;
18 sha256 = sha256Hash;
19 };
20
21 patches =
22 stdenv.lib.optional
23 (!isFuse3 && stdenv.isAarch64)
24 (fetchpatch {
25 url = "https://github.com/libfuse/libfuse/commit/914871b20a901e3e1e981c92bc42b1c93b7ab81b.patch";
26 sha256 = "1w4j6f1awjrycycpvmlv0x5v9gprllh4dnbjxl4dyl2jgbkaw6pa";
27 })
28 ++ stdenv.lib.optional isFuse3 ./fuse3-install.patch;
29
30
31 nativeBuildInputs = if isFuse3
32 then [ meson ninja pkgconfig ]
33 else [ autoconf automake libtool ];
34 buildInputs = stdenv.lib.optional (!isFuse3) gettext;
35
36 outputs = [ "out" ] ++ stdenv.lib.optional isFuse3 "common";
37
38 mesonFlags = stdenv.lib.optional isFuse3 "-Dudevrulesdir=etc/udev/rules.d";
39
40 preConfigure = ''
41 export MOUNT_FUSE_PATH=$out/sbin
42 export INIT_D_PATH=$TMPDIR/etc/init.d
43 export UDEV_RULES_PATH=$out/etc/udev/rules.d
44
45 # Ensure that FUSE calls the setuid wrapper, not
46 # $out/bin/fusermount. It falls back to calling fusermount in
47 # $PATH, so it should also work on non-NixOS systems.
48 export NIX_CFLAGS_COMPILE="-DFUSERMOUNT_DIR=\"/run/wrappers/bin\""
49
50 sed -e 's@/bin/@${utillinux}/bin/@g' -i lib/mount_util.c
51 '' + (if isFuse3 then ''
52 # The configure phase will delete these files (temporary workaround for
53 # ./fuse3-install_man.patch)
54 install -D -m444 doc/fusermount3.1 $out/share/man/man1/fusermount3.1
55 install -D -m444 doc/mount.fuse.8 $out/share/man/man8/mount.fuse.8
56 '' else ''
57 sed -e 's@CONFIG_RPATH=/usr/share/gettext/config.rpath@CONFIG_RPATH=${gettext}/share/gettext/config.rpath@' -i makeconf.sh
58 ./makeconf.sh
59 '');
60
61 postFixup = "cd $out\n" + (if isFuse3 then ''
62 mv bin/mount.fuse3 bin/mount.fuse
63
64 install -D -m555 bin/mount.fuse $common/bin/mount.fuse
65 install -D -m444 etc/udev/rules.d/99-fuse.rules $common/etc/udev/rules.d/99-fuse.rules
66 install -D -m444 share/man/man8/mount.fuse.8.gz $common/share/man/man8/mount.fuse.8.gz
67 '' else ''
68 cp ${fusePackages.fuse_3.common}/bin/mount.fuse bin/mount.fuse
69 cp ${fusePackages.fuse_3.common}/etc/udev/rules.d/99-fuse.rules etc/udev/rules.d/99-fuse.rules
70 cp ${fusePackages.fuse_3.common}/share/man/man8/mount.fuse.8.gz share/man/man8/mount.fuse.8.gz
71 '');
72
73 enableParallelBuilding = true;
74
75 meta = {
76 inherit (src.meta) homepage;
77 description = "Kernel module and library that allows filesystems to be implemented in user space";
78 platforms = stdenv.lib.platforms.linux;
79 inherit maintainers;
80 };
81}