lib: init XDG-specific subset

This is arguably more suitable for certain environment but Nix ecosystem
is already largely Unix-adjacent anyways.
This commit is contained in:
Gabriel Arazas 2025-03-20 08:55:05 +08:00
parent eb4352f925
commit 48949336ff
No known key found for this signature in database
GPG Key ID: 62104B43D00AA360
4 changed files with 48 additions and 0 deletions

View File

@ -13,6 +13,7 @@ in pkgs.lib.makeExtensible (self:
trivial = callLib ./trivial.nix;
data = callLib ./data.nix;
math = callLib ./math.nix;
xdg = callLib ./xdg.nix;
# For future references, these are the only attributes that are going to be
# exported as part of nixpkgs overlay.
@ -43,6 +44,7 @@ in pkgs.lib.makeExtensible (self:
inherit (self.trivial) countAttrs filterAttrs';
inherit (self.data) importYAML renderTeraTemplate renderMustacheTemplate;
inherit (self.fetchers) fetchInternetArchive fetchUgeeDriver;
inherit (self.xdg) getXdgDesktop;
} // lib.optionalAttrs (builtins ? fetchTree) {
flake = callLib ./flake.nix;

31
lib/xdg.nix Normal file
View File

@ -0,0 +1,31 @@
{ pkgs, lib, self }:
rec {
/**
Naively get the absolute path of a `.desktop` 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
```
*/
getXdgDesktop = drv: name:
"${drv}/share/applications/${name}.desktop";
}

View File

@ -27,6 +27,7 @@ in {
trivial = callLib ./trivial.nix;
data = callLib ./data;
math = callLib ./math.nix;
xdg = callLib ./xdg.nix;
# Environment-specific subset.
home-manager = callLib ./home-manager.nix;

14
tests/lib/xdg.nix Normal file
View File

@ -0,0 +1,14 @@
{ pkgs, lib, self }:
lib.runTests {
testGetXdgDesktop = {
expr = self.xdg.getXdgDesktop pkgs.wezterm "org.wezfurlong.wezterm";
expected = "${pkgs.wezterm}/share/applications/org.wezfurlong.wezterm.desktop";
};
# This should be a naive function so it should just naively get things.
testGetXdgDesktop2 = {
expr = self.xdg.getXdgDesktop pkgs.hello "non-existing-desktop";
expected = "${pkgs.hello}/share/applications/non-existing-desktop.desktop";
};
}