From 724ac43d8318a009def4be726560b8e6a7f74426 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Sun, 21 Jul 2024 17:41:05 +0800 Subject: [PATCH] wrapper-manager-fds/lib: add function for getting XDG-related directories --- lib/utils.nix | 16 ++++++++++++++++ tests/lib/utils.nix | 22 ++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/lib/utils.nix b/lib/utils.nix index b65f2c8..edf5a95 100644 --- a/lib/utils.nix +++ b/lib/utils.nix @@ -9,7 +9,23 @@ rec { builtins.map (v: lib.getBin v) drvs; /* + Given a list of derivations, return a list of the store paths with the + `libexec` appended. */ getLibexec = drvs: builtins.map (v: "${v}/libexec") drvs; + + /* + Given a list of derivations, return a list of the store paths appended with + `/etc/xdg` suitable as part of the XDG_CONFIG_DIRS environment variable. + */ + getXdgConfigDirs = drvs: + builtins.map (v: "${v}/etc/xdg") drvs; + + /* + Given a list of derivations, return a list of store paths appended with + `/share` suitable as part of the XDG_DATA_DIRS environment variable. + */ + getXdgDataDirs = drvs: + builtins.map (v: "${v}/share") drvs; } diff --git a/tests/lib/utils.nix b/tests/lib/utils.nix index 76d7f97..735fc03 100644 --- a/tests/lib/utils.nix +++ b/tests/lib/utils.nix @@ -22,4 +22,26 @@ lib.runTests { "${../../modules}/libexec" ]; }; + + testsUtilsGetXdgConfigDirs = { + expr = self.utils.getXdgConfigDirs [ + ../../lib + ../../modules + ]; + expected = [ + "${../../lib}/etc/xdg" + "${../../modules}/etc/xdg" + ]; + }; + + testsUtilsGetXdgDataDirs = { + expr = self.utils.getXdgDataDirs [ + ../../lib + ../../modules + ]; + expected = [ + "${../../lib}/share" + "${../../modules}/share" + ]; + }; }