From 103753221b762937aa851be12d9692b0ec5076d5 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Tue, 29 Apr 2025 12:35:08 +0800 Subject: [PATCH] lib: add naive get XDG autostart file function --- lib/xdg.nix | 28 ++++++++++++++++++++++++++++ tests/lib/xdg.nix | 11 +++++++++++ 2 files changed, 39 insertions(+) diff --git a/lib/xdg.nix b/lib/xdg.nix index 137cbfa9..6ccbb2a6 100644 --- a/lib/xdg.nix +++ b/lib/xdg.nix @@ -28,4 +28,32 @@ rec { */ getXdgDesktop = drv: name: "${drv}/share/applications/${name}.desktop"; + + /** + Naively get the absolute path of an autostart file given a derivation and a + name. + + # Arguments + + drv + : The derivation. + + name + : The name of the `.desktop` file (without the `.desktop` extension). + + # Type + + ``` + getXdgDesktop :: Derivation -> String -> Path + ``` + + # Example + + ```nix + getXdgDesktop pkgs.wezterm "org.wezfurlong.wezterm" + => /nix/store/$HASH-wezterm-org.wezterm.wezterm.desktop + ``` + */ + getXdgAutostartFile = drv: name: + "${drv}/etc/xdg/autostart/${name}.desktop"; } diff --git a/tests/lib/xdg.nix b/tests/lib/xdg.nix index da05316a..31c13e77 100644 --- a/tests/lib/xdg.nix +++ b/tests/lib/xdg.nix @@ -11,4 +11,15 @@ lib.runTests { expr = self.xdg.getXdgDesktop pkgs.hello "non-existing-desktop"; expected = "${pkgs.hello}/share/applications/non-existing-desktop.desktop"; }; + + testGetXdgAutostartFile = { + expr = self.xdg.getXdgAutostartFile pkgs.valent "valent"; + expected = "${pkgs.valent}/etc/xdg/autostart/valent.desktop"; + }; + + # This should be a naive function so it should just naively get things. + testGetXdgAutostartFile2 = { + expr = self.xdg.getXdgAutostartFile pkgs.hello "non-existing-autostart"; + expected = "${pkgs.hello}/etc/xdg/autostart/non-existing-autostart.desktop"; + }; }