Skip to content

Commit

Permalink
Merge pull request #33371 from jtojnar/flatpak
Browse files Browse the repository at this point in the history
Flatpak
  • Loading branch information
jtojnar authored May 15, 2018
2 parents 91365cd + d614f32 commit d5060ac
Show file tree
Hide file tree
Showing 19 changed files with 763 additions and 8 deletions.
1 change: 1 addition & 0 deletions nixos/modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@
./services/desktops/accountsservice.nix
./services/desktops/dleyna-renderer.nix
./services/desktops/dleyna-server.nix
./services/desktops/flatpak.nix
./services/desktops/geoclue2.nix
./services/desktops/pipewire.nix
./services/desktops/gnome3/at-spi2-core.nix
Expand Down
52 changes: 52 additions & 0 deletions nixos/modules/services/desktops/flatpak.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# flatpak service.
{ config, lib, pkgs, ... }:

with lib;

let
cfg = config.services.flatpak;
in {
meta = {
doc = ./flatpak.xml;
maintainers = pkgs.flatpak.meta.maintainers;
};

###### interface
options = {
services.flatpak = {
enable = mkEnableOption "flatpak";

extraPortals = mkOption {
type = types.listOf types.package;
default = [];
description = ''
List of additional portals to add to path. Portals allow interaction
with system, like choosing files or taking screenshots. At minimum,
a desktop portal implementation should be listed. GNOME already
adds <package>xdg-desktop-portal-gtk</package>; for KDE, there
is <package>xdg-desktop-portal-kde</package>. Other desktop
environments will probably want to do the same.
'';
};
};
};


###### implementation
config = mkIf cfg.enable {
environment.systemPackages = [ pkgs.flatpak ];

services.dbus.packages = [ pkgs.flatpak pkgs.xdg-desktop-portal ] ++ cfg.extraPortals;

systemd.packages = [ pkgs.flatpak pkgs.xdg-desktop-portal ] ++ cfg.extraPortals;

environment.variables = {
PATH = [
"$HOME/.local/share/flatpak/exports/bin"
"/var/lib/flatpak/exports/bin"
];

XDG_DESKTOP_PORTAL_PATH = map (p: "${p}/share/xdg-desktop-portal/portals") cfg.extraPortals;
};
};
}
53 changes: 53 additions & 0 deletions nixos/modules/services/desktops/flatpak.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<chapter xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xi="http://www.w3.org/2001/XInclude"
version="5.0"
xml:id="module-services-flatpak">

<title>Flatpak</title>

<para><emphasis>Source:</emphasis> <filename>modules/services/desktop/flatpak.nix</filename></para>

<para><emphasis>Upstream documentation:</emphasis> <link xlink:href="https://github.com/flatpak/flatpak/wiki"/></para>

<para>Flatpak is a system for building, distributing, and running sandboxed desktop applications on Linux.</para>

<para>
To enable Flatpak, add the following to your <filename>configuration.nix</filename>:

<programlisting>
<xref linkend="opt-services.flatpak.enable"/> = true;
</programlisting>
</para>

<para>
For the sandboxed apps to work correctly, desktop integration portals need to be installed. If you run GNOME, this will be handled automatically for you; in other cases, you will need to add something like the following to your <filename>configuration.nix</filename>:

<programlisting>
<xref linkend="opt-services.flatpak.extraPortals"/> = [ pkgs.xdg-desktop-portal-gtk ];
</programlisting>
</para>

<para>
Then, you will need to add a repository, for example, <link xlink:href="https://github.com/flatpak/flatpak/wiki">Flathub</link>, either using the following commands:

<programlisting>
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
flatpak update
</programlisting>

or by opening the <link xlink:href="https://flathub.org/repo/flathub.flatpakrepo">repository file</link> in GNOME Software.
</para>

<para>
Finally, you can search and install programs:

<programlisting>
flatpak search bustle
flatpak install flathub org.freedesktop.Bustle
flatpak run org.freedesktop.Bustle
</programlisting>

Again, GNOME Software offers graphical interface for these tasks.
</para>
</chapter>
1 change: 1 addition & 0 deletions nixos/modules/services/x11/desktop-managers/gnome3.nix
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ in {
services.xserver.libinput.enable = mkDefault true; # for controlling touchpad settings via gnome control center
services.udev.packages = [ pkgs.gnome3.gnome-settings-daemon ];
systemd.packages = [ pkgs.gnome3.vino ];
services.flatpak.extraPortals = [ pkgs.xdg-desktop-portal-gtk ];

# If gnome3 is installed, build vim for gtk3 too.
nixpkgs.config.vim.gui = "gtk3";
Expand Down
17 changes: 12 additions & 5 deletions nixos/modules/system/boot/systemd-lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

with lib;

let cfg = config.systemd; in

rec {
let
cfg = config.systemd;
lndir = "${pkgs.xorg.lndir}/bin/lndir";
in rec {

shellEscape = s: (replaceChars [ "\\" ] [ "\\\\" ] s);

Expand Down Expand Up @@ -136,7 +137,13 @@ rec {
for i in ${toString cfg.packages}; do
for fn in $i/etc/systemd/${type}/* $i/lib/systemd/${type}/*; do
if ! [[ "$fn" =~ .wants$ ]]; then
ln -s $fn $out/
if [[ -d "$fn" ]]; then
targetDir="$out/$(basename "$fn")"
mkdir -p "$targetDir"
${lndir} "$fn" "$targetDir"
else
ln -s $fn $out/
fi
fi
done
done
Expand All @@ -151,7 +158,7 @@ rec {
if [ "$(readlink -f $i/$fn)" = /dev/null ]; then
ln -sfn /dev/null $out/$fn
else
mkdir $out/$fn.d
mkdir -p $out/$fn.d
ln -s $i/$fn $out/$fn.d/overrides.conf
fi
else
Expand Down
2 changes: 2 additions & 0 deletions nixos/release.nix
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ in rec {
tests.env = callTest tests/env.nix {};
tests.ferm = callTest tests/ferm.nix {};
tests.firefox = callTest tests/firefox.nix {};
tests.flatpak = callTest tests/flatpak.nix {};
tests.firewall = callTest tests/firewall.nix {};
tests.fwupd = callTest tests/fwupd.nix {};
#tests.gitlab = callTest tests/gitlab.nix {};
Expand Down Expand Up @@ -397,6 +398,7 @@ in rec {
tests.virtualbox = callSubTestsOnMatchingSystems ["x86_64-linux"] tests/virtualbox.nix {};
tests.wordpress = callTest tests/wordpress.nix {};
tests.xautolock = callTest tests/xautolock.nix {};
tests.xdg-desktop-portal = callTest tests/xdg-desktop-portal.nix {};
tests.xfce = callTest tests/xfce.nix {};
tests.xmonad = callTest tests/xmonad.nix {};
tests.xrdp = callTest tests/xrdp.nix {};
Expand Down
23 changes: 23 additions & 0 deletions nixos/tests/flatpak.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# run installed tests
import ./make-test.nix ({ pkgs, ... }:

{
name = "flatpak";
meta = {
maintainers = pkgs.flatpak.meta.maintainers;
};

machine = { config, pkgs, ... }: {
imports = [ ./common/x11.nix ];
services.xserver.desktopManager.gnome3.enable = true; # TODO: figure out minimal environment where the tests work
services.flatpak.enable = true;
environment.systemPackages = with pkgs; [ gnupg gnome-desktop-testing ostree python2 ];
virtualisation.memorySize = 2047;
virtualisation.diskSize = 1024;
};

testScript = ''
$machine->waitForX();
$machine->succeed("gnome-desktop-testing-runner -d '${pkgs.flatpak.installedTests}/share' --timeout 3600");
'';
})
17 changes: 17 additions & 0 deletions nixos/tests/xdg-desktop-portal.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# run installed tests
import ./make-test.nix ({ pkgs, ... }:

{
name = "xdg-desktop-portal";
meta = {
maintainers = pkgs.xdg-desktop-portal.meta.maintainers;
};

machine = { config, pkgs, ... }: {
environment.systemPackages = with pkgs; [ gnome-desktop-testing ];
};

testScript = ''
$machine->succeed("gnome-desktop-testing-runner -d '${pkgs.xdg-desktop-portal.installedTests}/share'");
'';
})
5 changes: 2 additions & 3 deletions pkgs/desktops/gnome-3/core/gnome-software/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ stdenv, fetchurl, substituteAll, pkgconfig, meson, ninja, gettext, gnome3, wrapGAppsHook, packagekit, ostree
, glib, appstream-glib, libsoup, polkit, isocodes, gspell, libxslt, gobjectIntrospection
, glib, appstream-glib, libsoup, polkit, isocodes, gspell, libxslt, gobjectIntrospection, flatpak
, json-glib, libsecret, valgrind-light, docbook_xsl, docbook_xml_dtd_42, gtk-doc, desktop-file-utils }:

stdenv.mkDerivation rec {
Expand Down Expand Up @@ -27,11 +27,10 @@ stdenv.mkDerivation rec {
gnome3.gtk glib packagekit appstream-glib libsoup
gnome3.gsettings-desktop-schemas gnome3.gnome-desktop
gspell json-glib libsecret ostree
polkit
polkit flatpak
];

mesonFlags = [
"-Denable-flatpak=false"
"-Denable-rpm=false"
"-Denable-fwupd=false"
"-Denable-oauth=false"
Expand Down
74 changes: 74 additions & 0 deletions pkgs/development/libraries/flatpak/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{ stdenv, fetchurl, autoreconfHook, docbook_xml_dtd_412, docbook_xml_dtd_42, docbook_xml_dtd_43, docbook_xsl, which, libxml2
, gobjectIntrospection, gtk_doc, intltool, libxslt, pkgconfig, xmlto, appstream-glib, substituteAll, glibcLocales, yacc
, bubblewrap, bzip2, dbus, glib, gpgme, json_glib, libarchive, libcap, libseccomp, coreutils, python2, hicolor-icon-theme
, libsoup, lzma, ostree, polkit, python3, systemd, xlibs, valgrind, glib_networking, makeWrapper, gnome3 }:

let
version = "0.11.7";
desktop_schemas = gnome3.gsettings_desktop_schemas;
in stdenv.mkDerivation rec {
name = "flatpak-${version}";

outputs = [ "out" "man" "doc" "installedTests" ];

src = fetchurl {
url = "https://github.com/flatpak/flatpak/releases/download/${version}/${name}.tar.xz";
sha256 = "1vq4j7v68lp4fsvpas1bcsx1z4snpj0mkbq2mi00kx3jb48z768h";
};

patches = [
(substituteAll {
src = ./fix-test-paths.patch;
inherit coreutils python2 glibcLocales;
hicolorIconTheme = hicolor-icon-theme;
})
# patch taken from gtk_doc
./respect-xml-catalog-files-var.patch
];

nativeBuildInputs = [
autoreconfHook libxml2 docbook_xml_dtd_412 docbook_xml_dtd_42 docbook_xml_dtd_43 docbook_xsl which gobjectIntrospection
gtk_doc intltool libxslt pkgconfig xmlto appstream-glib yacc makeWrapper
] ++ stdenv.lib.optionals doCheck checkInputs;

buildInputs = [
bubblewrap bzip2 dbus glib gpgme json_glib libarchive libcap libseccomp
libsoup lzma ostree polkit python3 systemd xlibs.libXau
];

checkInputs = [ valgrind ];

doCheck = false; # TODO: some issues with temporary files

enableParallelBuilding = true;

configureFlags = [
"--with-system-bubblewrap=${bubblewrap}/bin/bwrap"
"--localstatedir=/var"
"--enable-installed-tests"
];

makeFlags = [
"installed_testdir=$(installedTests)/libexec/installed-tests/flatpak"
"installed_test_metadir=$(installedTests)/share/installed-tests/flatpak"
];

postPatch = ''
patchShebangs buildutil
patchShebangs tests
'';

postFixup = ''
wrapProgram $out/bin/flatpak \
--prefix GIO_EXTRA_MODULES : "${glib_networking.out}/lib/gio/modules" \
--prefix XDG_DATA_DIRS : "${desktop_schemas}/share/gsettings-schemas/${desktop_schemas.name}"
'';

meta = with stdenv.lib; {
description = "Linux application sandboxing and distribution framework";
homepage = https://flatpak.org/;
license = licenses.lgpl21;
maintainers = with maintainers; [ jtojnar ];
platforms = platforms.linux;
};
}
Loading

0 comments on commit d5060ac

Please sign in to comment.