From 87f5eb92d8e4dd4eb733d023cf01638904834362 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Wed, 10 Apr 2024 21:05:34 +0200 Subject: [PATCH] xdg-autostart: add module Signed-off-by: Sefa Eyeoglu --- modules/misc/xdg-autostart.nix | 40 ++++++++++++++++++++++++++++ modules/modules.nix | 1 + tests/modules/misc/xdg/autostart.nix | 20 ++++++++++++++ tests/modules/misc/xdg/default.nix | 1 + 4 files changed, 62 insertions(+) create mode 100644 modules/misc/xdg-autostart.nix create mode 100644 tests/modules/misc/xdg/autostart.nix diff --git a/modules/misc/xdg-autostart.nix b/modules/misc/xdg-autostart.nix new file mode 100644 index 00000000..f6b8b7e2 --- /dev/null +++ b/modules/misc/xdg-autostart.nix @@ -0,0 +1,40 @@ +{ config, lib, ... }: +let + inherit (builtins) baseNameOf listToAttrs map unsafeDiscardStringContext; + inherit (lib) literalExpression mkEnableOption mkIf mkOption types; + + cfg = config.xdg.autostart; + + /* "/nix/store/x-foo/application.desktop" -> { + name = "autostart/application.desktop"; + value = { source = "/nix/store/x-foo/application.desktop"; }; + } + */ + mapDesktopEntry = entry: { + name = "autostart/${unsafeDiscardStringContext (baseNameOf entry)}"; + value.source = entry; + }; +in { + meta.maintainers = with lib.maintainers; [ Scrumplex ]; + + options.xdg.autostart = { + enable = mkEnableOption "creation of XDG autostart entries"; + + entries = mkOption { + type = with types; listOf path; + description = '' + Paths to desktop files that should be linked to `XDG_CONFIG_HOME/autostart` + ''; + default = [ ]; + example = literalExpression '' + [ + "''${pkgs.evolution}/share/applications/org.gnome.Evolution.desktop" + ] + ''; + }; + }; + + config = mkIf (cfg.enable && cfg.entries != [ ]) { + xdg.configFile = listToAttrs (map mapDesktopEntry cfg.entries); + }; +} diff --git a/modules/modules.nix b/modules/modules.nix index ff48b21a..a6a8e8d1 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -40,6 +40,7 @@ let ./misc/uninstall.nix ./misc/version.nix ./misc/vte.nix + ./misc/xdg-autostart.nix ./misc/xdg-desktop-entries.nix ./misc/xdg-mime-apps.nix ./misc/xdg-mime.nix diff --git a/tests/modules/misc/xdg/autostart.nix b/tests/modules/misc/xdg/autostart.nix new file mode 100644 index 00000000..b9358041 --- /dev/null +++ b/tests/modules/misc/xdg/autostart.nix @@ -0,0 +1,20 @@ +{ pkgs, ... }: { + config = { + xdg.autostart = { + enable = true; + entries = [ + "${pkgs.evolution}/share/applications/org.gnome.Evolution.desktop" + "${pkgs.tdesktop}/share/applications/org.telegram.desktop.desktop" + ]; + }; + + nmt.script = '' + assertFileExists home-files/.config/autostart/org.gnome.Evolution.desktop + assertFileContent home-files/.config/autostart/org.gnome.Evolution.desktop \ + ${pkgs.evolution}/share/applications/org.gnome.Evolution.desktop + assertFileExists home-files/.config/autostart/org.telegram.desktop.desktop + assertFileContent home-files/.config/autostart/org.telegram.desktop.desktop \ + ${pkgs.tdesktop}/share/applications/org.telegram.desktop.desktop + ''; + }; +} diff --git a/tests/modules/misc/xdg/default.nix b/tests/modules/misc/xdg/default.nix index bc2f9a9d..7a722335 100644 --- a/tests/modules/misc/xdg/default.nix +++ b/tests/modules/misc/xdg/default.nix @@ -6,4 +6,5 @@ xdg-default-locations = ./default-locations.nix; xdg-user-dirs-null = ./user-dirs-null.nix; xdg-portal = ./portal.nix; + xdg-autostart = ./autostart.nix; }