2023-08-03 18:29:12 +00:00
|
|
|
# given a package with a $name.desktop file, makes a copy
|
2012-02-01 22:06:49 +00:00
|
|
|
# as autostart item.
|
|
|
|
|
|
|
|
{stdenv, lib}:
|
2012-02-29 12:50:17 +00:00
|
|
|
{ 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'
|
2012-02-01 22:06:49 +00:00
|
|
|
, after ? null
|
|
|
|
, condition ? null
|
|
|
|
, phase ? "2"
|
2024-01-27 02:15:57 +00:00
|
|
|
, prependExtraArgs ? []
|
|
|
|
, appendExtraArgs ? []
|
2012-02-01 22:06:49 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
# the builder requires that
|
|
|
|
# $package/share/applications/$name.desktop
|
|
|
|
# exists as file.
|
|
|
|
|
|
|
|
stdenv.mkDerivation {
|
|
|
|
name = "autostart-${name}";
|
|
|
|
priority = 5;
|
|
|
|
|
2024-01-27 02:15:57 +00:00
|
|
|
buildCommand = let
|
|
|
|
escapeArgs = args: lib.escapeRegex (lib.escapeShellArgs args);
|
|
|
|
prependArgs = lib.optionalString (prependExtraArgs != []) "${escapeArgs prependExtraArgs} ";
|
|
|
|
appendArgs = lib.optionalString (appendExtraArgs != []) " ${escapeArgs appendExtraArgs}";
|
|
|
|
in ''
|
2017-07-05 22:44:41 +00:00
|
|
|
mkdir -p $out/etc/xdg/autostart
|
2012-02-01 22:06:49 +00:00
|
|
|
target=${name}.desktop
|
2012-02-29 12:50:17 +00:00
|
|
|
cp ${package}/share/applications/${srcPrefix}${name}.desktop $target
|
2024-01-27 02:15:57 +00:00
|
|
|
${lib.optionalString (prependExtraArgs != [] || appendExtraArgs != []) ''
|
2024-08-18 10:27:06 +00:00
|
|
|
sed -i -r "s/(Exec=)([^ \n]*) *(.*)/\1\2 ${prependArgs}\3${appendArgs}/" $target
|
2024-01-27 02:15:57 +00:00
|
|
|
''}
|
2012-02-01 22:06:49 +00:00
|
|
|
chmod +rw $target
|
|
|
|
echo "X-KDE-autostart-phase=${phase}" >> $target
|
|
|
|
${lib.optionalString (after != null) ''echo "${after}" >> $target''}
|
|
|
|
${lib.optionalString (condition != null) ''echo "${condition}" >> $target''}
|
2017-07-05 22:44:41 +00:00
|
|
|
cp $target $out/etc/xdg/autostart
|
2012-02-01 22:06:49 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
# this will automatically put 'package' in the environment when you
|
|
|
|
# put its startup item in there.
|
|
|
|
propagatedBuildInputs = [ package ];
|
2012-02-29 12:50:17 +00:00
|
|
|
}
|