1{ version, hash }:
2
3{
4 lib,
5 stdenv,
6 fetchFromGitHub,
7 fetchpatch,
8 fusePackages,
9 util-linux,
10 gettext,
11 shadow,
12 meson,
13 ninja,
14 pkg-config,
15 autoreconfHook,
16 runtimeShell,
17}:
18
19let
20 isFuse3 = lib.hasPrefix "3" version;
21in
22stdenv.mkDerivation rec {
23 pname = "fuse";
24 inherit version;
25
26 src = fetchFromGitHub {
27 owner = "libfuse";
28 repo = "libfuse";
29 rev = "${pname}-${version}";
30 inherit hash;
31 };
32
33 preAutoreconf = "touch config.rpath";
34
35 patches =
36 lib.optional (!isFuse3 && (stdenv.hostPlatform.isAarch64 || stdenv.hostPlatform.isLoongArch64))
37 (fetchpatch {
38 url = "https://github.com/libfuse/libfuse/commit/914871b20a901e3e1e981c92bc42b1c93b7ab81b.patch";
39 sha256 = "1w4j6f1awjrycycpvmlv0x5v9gprllh4dnbjxl4dyl2jgbkaw6pa";
40 })
41 ++ (
42 if isFuse3 then
43 [
44 ./fuse3-install.patch
45 ./fuse3-Do-not-set-FUSERMOUNT_DIR.patch
46 ]
47 else
48 [
49 ./fuse2-Do-not-set-FUSERMOUNT_DIR.patch
50 (fetchpatch {
51 url = "https://gitweb.gentoo.org/repo/gentoo.git/plain/sys-fs/fuse/files/fuse-2.9.9-closefrom-glibc-2-34.patch?id=8a970396fca7aca2d5a761b8e7a8242f1eef14c9";
52 sha256 = "sha256-ELYBW/wxRcSMssv7ejCObrpsJHtOPJcGq33B9yHQII4=";
53 })
54 ]
55 );
56
57 nativeBuildInputs =
58 if isFuse3 then
59 [
60 meson
61 ninja
62 pkg-config
63 ]
64 else
65 [
66 autoreconfHook
67 gettext
68 ];
69
70 outputs = [
71 "bin"
72 "out"
73 "dev"
74 "man"
75 ] ++ lib.optional isFuse3 "udev";
76
77 mesonFlags = lib.optionals isFuse3 [
78 "-Dudevrulesdir=/udev/rules.d"
79 "-Duseroot=false"
80 "-Dinitscriptdir="
81 ];
82
83 # Ensure that FUSE calls the setuid wrapper, not
84 # $out/bin/fusermount. It falls back to calling fusermount in
85 # $PATH, so it should also work on non-NixOS systems.
86 env.NIX_CFLAGS_COMPILE = ''-DFUSERMOUNT_DIR="/run/wrappers/bin"'';
87
88 preConfigure =
89 ''
90 substituteInPlace lib/mount_util.c \
91 --replace-fail "/bin/mount" "${lib.getBin util-linux}/bin/mount" \
92 --replace-fail "/bin/umount" "${lib.getBin util-linux}/bin/umount"
93 substituteInPlace util/mount.fuse.c \
94 --replace-fail "/bin/sh" "${runtimeShell}"
95 ''
96 + lib.optionalString (!isFuse3) ''
97 export MOUNT_FUSE_PATH=$bin/bin
98
99 # Do not install these files for fuse2 which are not useful for NixOS.
100 export INIT_D_PATH=$TMPDIR/etc/init.d
101 export UDEV_RULES_PATH=$TMPDIR/etc/udev/rules.d
102
103 # This is for `setuid=`, and needs root permission anyway.
104 # No need to use the SUID wrapper.
105 substituteInPlace util/mount.fuse.c \
106 --replace-fail '"su"' '"${lib.getBin shadow.su}/bin/su"'
107 substituteInPlace makeconf.sh \
108 --replace-fail 'CONFIG_RPATH=/usr/share/gettext/config.rpath' 'CONFIG_RPATH=${lib.getLib gettext}/share/gettext/config.rpath'
109 ./makeconf.sh
110 '';
111
112 # v2: no tests, v3: all tests get skipped in a sandbox
113 doCheck = false;
114
115 # Drop `/etc/fuse.conf` because it is a no-op config and
116 # would conflict with our fuse module.
117 postInstall = lib.optionalString isFuse3 ''
118 rm $out/etc/fuse.conf
119 mkdir $udev
120 mv $out/etc $udev
121 '';
122
123 # Don't pull in SUID `fusermount{,3}` binaries into development environment.
124 propagatedBuildOutputs = [ "out" ];
125
126 meta = {
127 description = "Library that allows filesystems to be implemented in user space";
128 longDescription = ''
129 FUSE (Filesystem in Userspace) is an interface for userspace programs to
130 export a filesystem to the Linux kernel. The FUSE project consists of two
131 components: The fuse kernel module (maintained in the regular kernel
132 repositories) and the libfuse userspace library (this package). libfuse
133 provides the reference implementation for communicating with the FUSE
134 kernel module.
135 '';
136 homepage = "https://github.com/libfuse/libfuse";
137 changelog = "https://github.com/libfuse/libfuse/releases/tag/fuse-${version}";
138 platforms = lib.platforms.linux;
139 license = with lib.licenses; [
140 gpl2Only
141 lgpl21Only
142 ];
143 maintainers = with lib.maintainers; [
144 primeos
145 oxalica
146 ];
147 outputsToInstall = [ "bin" ];
148 };
149}