From 6129318685995ec6290ab37848c1365ef0fe406b Mon Sep 17 00:00:00 2001 From: Anthony Rodriguez Date: Tue, 11 Feb 2025 19:34:31 +0100 Subject: [PATCH] hjem/collection: add autostart module --- shared/modules/hjem/collection/autostart.nix | 45 ++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 shared/modules/hjem/collection/autostart.nix diff --git a/shared/modules/hjem/collection/autostart.nix b/shared/modules/hjem/collection/autostart.nix new file mode 100644 index 0000000..7b8ae1e --- /dev/null +++ b/shared/modules/hjem/collection/autostart.nix @@ -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; + }; +}