mirror of
https://github.com/lhns/steam-frame-nix.git
synced 2026-10-06 02:00:13 +02:00
jellyfin: hardware decoding through a desktop entry, not an override
The shim's permissions (devices=all, its store path, LD_PRELOAD, SFN_MPV_HWDEC) were a Flatpak override: through nix-flatpak's services.flatpak.overrides, whose override file outlives the configuration (it left an empty file behind), or a Home Manager link that `flatpak override --user` would replace (hence `force`). Now a desktop entry shadowing the Flatpak's (same ID, same fields and actions; also what the "+" menu sees) passes them as `flatpak run` options (--device=all --filesystem=<shim>:ro --env=...), so nothing is written to Flatpak's overrides and they disappear with the entry. jellyfin.hardwareDecoding.command is that command line for a terminal. The entries earlier versions put into the override file are removed by steam-frame-nix-cleanup. Checked with `flatpak run ... --command=sh`: the shim's store path is visible read-only, the environment is set and /dev/video* is there.
This commit is contained in:
1 parent
1672210ead
commit
69909f5b4c
1 file changed
+63
-34
+63
-34
@@ -5,31 +5,30 @@
|
|||||||
# exists), and Jellyfin hard-sets mpv's hwdec=auto-copy, whose probe list
|
# exists), and Jellyfin hard-sets mpv's hwdec=auto-copy, whose probe list
|
||||||
# leaves out V4L2 M2M, without a way to pass mpv options. So:
|
# leaves out V4L2 M2M, without a way to pass mpv options. So:
|
||||||
# - an LD_PRELOAD shim (jellyfin/mpv-hwdec-shim.c) rewrites an "auto*" hwdec
|
# - an LD_PRELOAD shim (jellyfin/mpv-hwdec-shim.c) rewrites an "auto*" hwdec
|
||||||
# to $SFN_MPV_HWDEC. Preloaded from the store: the override exposes just
|
# to $SFN_MPV_HWDEC. Preloaded from the store: only its store path is
|
||||||
# its store path (read-only) to the sandbox.
|
# exposed (read-only) to the sandbox.
|
||||||
# - override: devices=all, that filesystem, LD_PRELOAD, SFN_MPV_HWDEC.
|
# - a desktop entry shadowing the Flatpak's (same ID, also seen by the "+"
|
||||||
# Through nix-flatpak's services.flatpak.overrides if it is imported and
|
# menu) starts it with those permissions as `flatpak run` options
|
||||||
# enabled (merged with the user's own overrides there); else home-manager
|
# (--device=all, --filesystem, --env): nothing is written to Flatpak's
|
||||||
# owns the app's override file.
|
# override files, so they apply only to launches from this entry and
|
||||||
{ config, options, lib, pkgs, ... }:
|
# disappear with it.
|
||||||
|
# Earlier versions used an override file (nix-flatpak or Home Manager);
|
||||||
|
# steam-frame-nix-cleanup removes their entries.
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
let
|
let
|
||||||
cfg = config.steamFrame.jellyfin.hardwareDecoding;
|
cfg = config.steamFrame.jellyfin.hardwareDecoding;
|
||||||
app = "org.jellyfin.JellyfinDesktop";
|
app = "org.jellyfin.JellyfinDesktop";
|
||||||
|
|
||||||
shim = pkgs.callPackage ./jellyfin/shim.nix { };
|
shim = pkgs.callPackage ./jellyfin/shim.nix { };
|
||||||
|
|
||||||
override = {
|
run = lib.concatStringsSep " " [
|
||||||
Context = { devices = [ "all" ]; filesystems = [ "${shim}:ro" ]; };
|
"flatpak run --branch=stable --arch=aarch64 --command=jellyfin-desktop"
|
||||||
Environment = { LD_PRELOAD = "${shim}/lib/mpv-hwdec-shim.so"; SFN_MPV_HWDEC = cfg.hwdec; };
|
"--device=all"
|
||||||
};
|
"--filesystem=${shim}:ro"
|
||||||
|
"--env=LD_PRELOAD=${shim}/lib/mpv-hwdec-shim.so"
|
||||||
useNixFlatpak = options ? services.flatpak.overrides && config.services.flatpak.enable;
|
"--env=SFN_MPV_HWDEC=${cfg.hwdec}"
|
||||||
|
app
|
||||||
# Flatpak's keyfile format (lists as "a;b;").
|
];
|
||||||
overrideFile = pkgs.writeText "${app}-override" (lib.concatStringsSep "\n" (lib.mapAttrsToList
|
|
||||||
(section: entries: "[${section}]\n" + lib.concatStrings (lib.mapAttrsToList (key: value:
|
|
||||||
"${key}=${if lib.isList value then lib.concatMapStrings (v: "${v};") value else value}\n") entries))
|
|
||||||
override));
|
|
||||||
in {
|
in {
|
||||||
imports = [ ./cleanup.nix ];
|
imports = [ ./cleanup.nix ];
|
||||||
|
|
||||||
@@ -39,10 +38,11 @@ in {
|
|||||||
default = false;
|
default = false;
|
||||||
description = ''
|
description = ''
|
||||||
Hardware video decoding (the Frame's V4L2 decoder) in the Jellyfin
|
Hardware video decoding (the Frame's V4L2 decoder) in the Jellyfin
|
||||||
Desktop Flatpak: device access for the sandbox (devices=all) and an
|
Desktop Flatpak: a desktop entry (shadowing the Flatpak's) that
|
||||||
LD_PRELOAD shim that makes mpv try hwdec's value below. Without
|
starts it with device access (devices=all) and an LD_PRELOAD shim
|
||||||
nix-flatpak, home-manager owns the app's Flatpak override file. Takes
|
that makes mpv try hwdec's value below. Only launches from that
|
||||||
effect at the next start of Jellyfin.
|
entry (menus, the "+" menu) get it; nothing is written to Flatpak's
|
||||||
|
overrides. Takes effect at the next start of Jellyfin.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
hwdec = lib.mkOption {
|
hwdec = lib.mkOption {
|
||||||
@@ -55,17 +55,46 @@ in {
|
|||||||
Set as SFN_MPV_HWDEC in the Flatpak's environment.
|
Set as SFN_MPV_HWDEC in the Flatpak's environment.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
command = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
readOnly = true;
|
||||||
|
default = run;
|
||||||
|
defaultText = lib.literalMD "`flatpak run … org.jellyfin.JellyfinDesktop` with the options";
|
||||||
|
description = "The command line the desktop entry runs (for a terminal).";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
# The shim copy of earlier versions is removed by steam-frame-nix-cleanup.
|
# Fields as in the Flatpak's own entry (1.x), which has no MimeType.
|
||||||
config = lib.mkMerge [
|
config = lib.mkIf cfg.enable {
|
||||||
(lib.mkIf (cfg.enable && !useNixFlatpak) {
|
xdg.dataFile."applications/${app}.desktop".text = ''
|
||||||
# force: `flatpak override --user` replaces the link with a file.
|
[Desktop Entry]
|
||||||
xdg.dataFile."flatpak/overrides/${app}" = { source = overrideFile; force = true; };
|
Version=1.0
|
||||||
})
|
Name=Jellyfin
|
||||||
# Only if nix-flatpak is imported: the option doesn't exist otherwise.
|
Comment=Desktop client for Jellyfin
|
||||||
(lib.optionalAttrs (options ? services.flatpak.overrides) {
|
Exec=${run}
|
||||||
services.flatpak.overrides = lib.mkIf (cfg.enable && useNixFlatpak) { ${app} = override; };
|
Icon=${app}
|
||||||
})
|
Terminal=false
|
||||||
];
|
Type=Application
|
||||||
|
StartupWMClass=${app}
|
||||||
|
Categories=AudioVideo;Video;Player;TV;
|
||||||
|
Actions=DesktopF;DesktopW;TVF;TVW
|
||||||
|
X-Flatpak=${app}
|
||||||
|
|
||||||
|
[Desktop Action DesktopF]
|
||||||
|
Name=Desktop [Fullscreen]
|
||||||
|
Exec=${run} --fullscreen --desktop
|
||||||
|
|
||||||
|
[Desktop Action DesktopW]
|
||||||
|
Name=Desktop [Windowed]
|
||||||
|
Exec=${run} --windowed --desktop
|
||||||
|
|
||||||
|
[Desktop Action TVF]
|
||||||
|
Name=TV [Fullscreen]
|
||||||
|
Exec=${run} --fullscreen --tv
|
||||||
|
|
||||||
|
[Desktop Action TVW]
|
||||||
|
Name=TV [Windowed]
|
||||||
|
Exec=${run} --windowed --tv
|
||||||
|
'';
|
||||||
|
};
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user