lib: add naive get XDG autostart file function

This commit is contained in:
Gabriel Arazas 2025-04-29 12:35:08 +08:00
parent 1451905a7f
commit 103753221b
No known key found for this signature in database
GPG Key ID: 62104B43D00AA360
2 changed files with 39 additions and 0 deletions

View File

@ -28,4 +28,32 @@ rec {
*/ */
getXdgDesktop = drv: name: getXdgDesktop = drv: name:
"${drv}/share/applications/${name}.desktop"; "${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";
} }

View File

@ -11,4 +11,15 @@ lib.runTests {
expr = self.xdg.getXdgDesktop pkgs.hello "non-existing-desktop"; expr = self.xdg.getXdgDesktop pkgs.hello "non-existing-desktop";
expected = "${pkgs.hello}/share/applications/non-existing-desktop.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";
};
} }