hjem/collection: add autostart module

This commit is contained in:
Anthony Rodriguez 2025-02-11 19:34:31 +01:00
parent 2719bbada1
commit 6129318685
Signed by: nezia
SSH key fingerprint: SHA256:Ihfpl0rUpqDevYqnzSR34OYfVLbDNkBiUjs3CpX4ykA

View file

@ -0,0 +1,45 @@
{
lib,
config,
...
}: let
inherit (lib.modules) mkIf;
inherit (lib.options) mkOption;
inherit (lib.types) listOf package;
cfg = config.autostart;
# stolen from https://github.com/nix-community/home-manager/issues/3447#issuecomment-1328294558
mkAutostartEntries = builtins.listToAttrs (map
(pkg: {
name = ".config/autostart/" + pkg.pname + ".desktop";
value =
if pkg ? desktopItem
then {
# Application has a desktopItem entry.
# Assume that it was made with makeDesktopEntry, which exposes a
# text attribute with the contents of the .desktop file
inherit (pkg.desktopItem) text;
}
else {
# Application does *not* have a desktopItem entry. Try to find a
# matching .desktop name in /share/apaplications
source = pkg + "/share/applications/" + pkg.pname + ".desktop";
};
})
cfg.programs);
in {
options.autostart = {
programs = mkOption {
type = listOf package;
default = [];
description = ''
A list of packages that will be started automatically,
according to the Desktop Application Autostart
Specification.
'';
};
};
config = mkIf (cfg.programs != []) {
files = mkAutostartEntries;
};
}