mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-08-31 12:44:44 +00:00
Fix cases when using `makeStartupItem` and it's `prependExtraArgs` or `appendExtraArgs` option with a desktop file having a `TryExec` key. The `TryExec` key must either be an absolute path to the binary or the binary name (if present in $PATH). When using either of the two options above, the `TryExec` key will be modified to have the flags as it's content, which is invalid and will break the desktop file. The change to the sed command makes it so only lines starting with `Exec` are changed, ignoring `TryExec` and preventing the issue from happening. Link to the FDO specification: https://specifications.freedesktop.org/desktop-entry/latest/recognized-keys.html
48 lines
1.6 KiB
Nix
48 lines
1.6 KiB
Nix
# given a package with a $name.desktop file, makes a copy
|
|
# as autostart item.
|
|
|
|
{ stdenv, lib }:
|
|
{
|
|
name, # name of the desktop file (without .desktop)
|
|
package, # package where the desktop file resides in
|
|
srcPrefix ? "", # additional prefix that the desktop file may have in the 'package'
|
|
after ? null,
|
|
condition ? null,
|
|
phase ? "2",
|
|
prependExtraArgs ? [ ],
|
|
appendExtraArgs ? [ ],
|
|
}:
|
|
|
|
# the builder requires that
|
|
# $package/share/applications/$name.desktop
|
|
# exists as file.
|
|
|
|
stdenv.mkDerivation {
|
|
name = "autostart-${name}";
|
|
priority = 5;
|
|
|
|
buildCommand =
|
|
let
|
|
escapeArgs = args: lib.escapeRegex (lib.escapeShellArgs args);
|
|
prependArgs = lib.optionalString (prependExtraArgs != [ ]) "${escapeArgs prependExtraArgs} ";
|
|
appendArgs = lib.optionalString (appendExtraArgs != [ ]) " ${escapeArgs appendExtraArgs}";
|
|
in
|
|
''
|
|
mkdir -p $out/etc/xdg/autostart
|
|
target=${name}.desktop
|
|
cp ${package}/share/applications/${srcPrefix}${name}.desktop $target
|
|
${lib.optionalString (prependExtraArgs != [ ] || appendExtraArgs != [ ]) ''
|
|
sed -i -r "s/^(Exec=)([^ \n]*) *(.*)/\1\2 ${prependArgs}\3${appendArgs}/" $target
|
|
''}
|
|
chmod +rw $target
|
|
echo "X-KDE-autostart-phase=${phase}" >> $target
|
|
${lib.optionalString (after != null) ''echo "${after}" >> $target''}
|
|
${lib.optionalString (condition != null) ''echo "${condition}" >> $target''}
|
|
cp $target $out/etc/xdg/autostart
|
|
'';
|
|
|
|
# this will automatically put 'package' in the environment when you
|
|
# put its startup item in there.
|
|
propagatedBuildInputs = [ package ];
|
|
}
|