1{
2 lib,
3 stdenv,
4 pkgsCross,
5 appstream,
6 bison,
7 bubblewrap,
8 buildPackages,
9 bzip2,
10 coreutils,
11 curl,
12 dconf,
13 desktop-file-utils,
14 docbook-xsl-nons,
15 docbook_xml_dtd_45,
16 fetchurl,
17 fuse3,
18 gdk-pixbuf,
19 gettext,
20 glib,
21 glib-networking,
22 gobject-introspection,
23 gpgme,
24 gsettings-desktop-schemas,
25 gtk-doc,
26 gtk3,
27 hicolor-icon-theme,
28 json-glib,
29 libarchive,
30 libcap,
31 librsvg,
32 libseccomp,
33 libxml2,
34 libxslt,
35 malcontent,
36 meson,
37 ninja,
38 nix-update-script,
39 nixos-icons,
40 ostree,
41 p11-kit,
42 pkg-config,
43 polkit,
44 python3,
45 runCommand,
46 shared-mime-info,
47 socat,
48 replaceVars,
49 systemd,
50 testers,
51 valgrind,
52 validatePkgConfig,
53 wayland,
54 wayland-protocols,
55 wayland-scanner,
56 wrapGAppsNoGuiHook,
57 xdg-dbus-proxy,
58 xmlto,
59 xorg,
60 zstd,
61 withAutoSideloading ? false,
62 withDconf ? lib.meta.availableOn stdenv.hostPlatform dconf,
63 withDocbookDocs ? true,
64 withGlibNetworking ? lib.meta.availableOn stdenv.hostPlatform glib-networking,
65 withGtkDoc ?
66 withDocbookDocs
67 && stdenv.buildPlatform.canExecute stdenv.hostPlatform
68 # https://github.com/mesonbuild/meson/pull/14257
69 && !stdenv.hostPlatform.isStatic,
70 withIntrospection ?
71 lib.meta.availableOn stdenv.hostPlatform gobject-introspection
72 && stdenv.hostPlatform.emulatorAvailable buildPackages,
73 withMalcontent ? lib.meta.availableOn stdenv.hostPlatform malcontent,
74 withMan ? withDocbookDocs,
75 withP11Kit ? lib.meta.availableOn stdenv.hostPlatform p11-kit,
76 withPolkit ? lib.meta.availableOn stdenv.hostPlatform polkit,
77 withSELinuxModule ? false,
78 withSystemd ? lib.meta.availableOn stdenv.hostPlatform systemd,
79}:
80
81stdenv.mkDerivation (finalAttrs: {
82 pname = "flatpak";
83 version = "1.16.1";
84
85 # TODO: split out lib once we figure out what to do with triggerdir
86 outputs = [
87 "out"
88 "dev"
89 ]
90 ++ lib.optionals withDocbookDocs [
91 "doc"
92 ]
93 ++ lib.optionals withGtkDoc [
94 "devdoc"
95 ]
96 ++ lib.optional finalAttrs.doCheck "installedTests"
97 ++ lib.optional withMan "man";
98
99 src = fetchurl {
100 url = "https://github.com/flatpak/flatpak/releases/download/${finalAttrs.version}/flatpak-${finalAttrs.version}.tar.xz";
101 hash = "sha256-K0fo8tkNNdKTOe144abquzbu+pz6WlyjsNHydQLENnU=";
102 };
103
104 patches = [
105 # Use flatpak from PATH to avoid references to `/nix/store` in `/desktop` files.
106 # Applications containing `DBusActivatable` entries should be able to find the flatpak binary.
107 # https://github.com/NixOS/nixpkgs/issues/138956
108 ./binary-path.patch
109
110 # Try mounting fonts and icons from NixOS locations if FHS locations don't exist.
111 # https://github.com/NixOS/nixpkgs/issues/119433
112 ./fix-fonts-icons.patch
113
114 # Nix environment hacks should not leak into the apps.
115 # https://github.com/NixOS/nixpkgs/issues/53441
116 ./unset-env-vars.patch
117
118 # The icon validator needs to access the gdk-pixbuf loaders in the Nix store
119 # and cannot bind FHS paths since those are not available on NixOS.
120 finalAttrs.passthru.icon-validator-patch
121 ]
122 ++ lib.optionals finalAttrs.doCheck [
123 # Hardcode paths used by tests and change test runtime generation to use files from Nix store.
124 # https://github.com/flatpak/flatpak/issues/1460
125 (replaceVars ./fix-test-paths.patch {
126 inherit
127 coreutils
128 gettext
129 gtk3
130 socat
131 ;
132 dfu = desktop-file-utils;
133 hicolorIconTheme = hicolor-icon-theme;
134 smi = shared-mime-info;
135 })
136 ]
137 ++ lib.optionals withP11Kit [
138 # Hardcode p11-kit path used by Flatpak itself.
139 # If disabled, will have to be on PATH.
140 (replaceVars ./fix-paths.patch {
141 p11kit = lib.getExe p11-kit;
142 })
143 ];
144
145 # Fixup shebangs in some scripts
146 #
147 # Don't prefix the already absolute `man` directory with the install prefix
148 postPatch = ''
149 patchShebangs buildutil/ tests/
150 patchShebangs --build subprojects/variant-schema-compiler/variant-schema-compiler
151
152 substituteInPlace doc/meson.build \
153 --replace-fail '$MESON_INSTALL_DESTDIR_PREFIX/@1@/@2@' '@1@/@2@'
154 '';
155
156 strictDeps = true;
157
158 depsBuildBuild = [ pkg-config ];
159
160 nativeBuildInputs = [
161 (python3.pythonOnBuildForHost.withPackages (p: [ p.pyparsing ]))
162 bison
163 glib
164 meson
165 ninja
166 pkg-config
167 validatePkgConfig
168 wayland-scanner
169 wrapGAppsNoGuiHook
170 ]
171 ++ lib.optional withGtkDoc gtk-doc
172 ++ lib.optional withIntrospection gobject-introspection
173 ++ lib.optional withMan libxslt
174 ++ lib.optional withSELinuxModule bzip2
175 ++ lib.optionals withDocbookDocs [
176 docbook-xsl-nons
177 docbook_xml_dtd_45
178 xmlto
179 ];
180
181 buildInputs = [
182 appstream
183 curl
184 fuse3
185 gdk-pixbuf
186 gpgme
187 gsettings-desktop-schemas
188 json-glib
189 libarchive
190 libcap
191 librsvg # for flatpak-validate-icon
192 libseccomp
193 libxml2
194 python3
195 wayland
196 wayland-protocols
197 xorg.libXau
198 zstd
199 ]
200 ++ lib.optional withDconf dconf
201 ++ lib.optional withGlibNetworking glib-networking
202 ++ lib.optional withMalcontent malcontent
203 ++ lib.optional withPolkit polkit
204 ++ lib.optional withSystemd systemd;
205
206 # Required by flatpak.pc
207 propagatedBuildInputs = [
208 glib
209 ostree
210 ];
211
212 mesonFlags = [
213 (lib.mesonBool "auto_sideloading" withAutoSideloading)
214 (lib.mesonBool "installed_tests" finalAttrs.finalPackage.doCheck)
215 (lib.mesonBool "tests" finalAttrs.finalPackage.doCheck)
216 (lib.mesonEnable "dconf" withDconf)
217 (lib.mesonEnable "docbook_docs" withDocbookDocs)
218 (lib.mesonEnable "gir" withIntrospection)
219 (lib.mesonEnable "gtkdoc" withGtkDoc)
220 (lib.mesonEnable "malcontent" withMalcontent)
221 (lib.mesonEnable "man" withMan)
222 (lib.mesonEnable "selinux_module" withSELinuxModule)
223 (lib.mesonEnable "system_helper" withPolkit)
224 (lib.mesonEnable "systemd" withSystemd)
225 (lib.mesonOption "dbus_config_dir" (placeholder "out" + "/share/dbus-1/system.d"))
226 (lib.mesonOption "profile_dir" (placeholder "out" + "/etc/profile.d"))
227 (lib.mesonOption "system_bubblewrap" (lib.getExe bubblewrap))
228 (lib.mesonOption "system_dbus_proxy" (lib.getExe xdg-dbus-proxy))
229 (lib.mesonOption "system_fusermount" "/run/wrappers/bin/fusermount3")
230 (lib.mesonOption "system_install_dir" "/var/lib/flatpak")
231 ];
232
233 nativeCheckInputs = [
234 polkit
235 socat
236 valgrind
237 ];
238
239 # TODO: Many issues with temporary files, FHS environments, timeouts, and our current patches
240 doCheck = false;
241
242 separateDebugInfo = true;
243
244 passthru = {
245 icon-validator-patch = replaceVars ./fix-icon-validation.patch {
246 inherit (builtins) storeDir;
247 };
248
249 tests = {
250 cross-aarch64 = pkgsCross.aarch64-multiplatform.flatpak;
251
252 pkg-config = testers.hasPkgConfigModules { package = finalAttrs.finalPackage; };
253
254 validate-icon = runCommand "test-icon-validation" { } ''
255 ${finalAttrs.finalPackage}/libexec/flatpak-validate-icon \
256 --sandbox 512 512 \
257 "${nixos-icons}/share/icons/hicolor/512x512/apps/nix-snowflake.png" > "$out"
258
259 grep format=png "$out"
260 '';
261
262 version = testers.testVersion { package = finalAttrs.finalPackage; };
263 };
264
265 updateScript = nix-update-script { };
266 };
267
268 meta = {
269 description = "Linux application sandboxing and distribution framework";
270 homepage = "https://flatpak.org/";
271 changelog = "https://github.com/flatpak/flatpak/releases/tag/${finalAttrs.version}";
272 license = lib.licenses.lgpl21Plus;
273 maintainers = with lib.maintainers; [ getchoo ];
274 mainProgram = "flatpak";
275 platforms = lib.platforms.linux;
276 pkgConfigModules = [ "flatpak" ];
277 };
278})