aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Cassou <damien@cassou.me>2020-09-09 21:53:21 +0200
committerRobert Helgesson <robert@rycee.net>2020-09-11 12:26:55 +0200
commit605a8fc92e2bb346b17d102d94d37af23c9b7d4e (patch)
tree296be1ff237b5fa78b0944bb4922d37b52a7ec23
parentb819d2cc414e0d14fd078551399f58c087a72ae7 (diff)
generic-linux: add option extraXdgDataDirs
PR #1486
-rw-r--r--modules/misc/news.nix15
-rw-r--r--modules/targets/generic-linux.nix14
-rw-r--r--tests/modules/targets-linux/generic-linux.nix7
3 files changed, 32 insertions, 4 deletions
diff --git a/modules/misc/news.nix b/modules/misc/news.nix
index b1d612cd5df..7fdbdd69df9 100644
--- a/modules/misc/news.nix
+++ b/modules/misc/news.nix
@@ -1649,6 +1649,21 @@ in
A new module is available: 'programs.ncmpcpp'
'';
}
+
+ {
+ time = "2020-09-11T10:06:47+00:00";
+ condition = hostPlatform.isLinux && config.targets.genericLinux.enable;
+ message = ''
+ A new option 'targets.genericLinux.extraXdgDataDirs' is available
+ to setup the user environment with the OS's data files.
+
+ This is useful for example to get Bash completion for
+ 'systemctl' which shouldn't be installed through Home Manager.
+
+ This is also useful to have non Home Manager applications
+ available in menus.
+ '';
+ }
];
};
}
diff --git a/modules/targets/generic-linux.nix b/modules/targets/generic-linux.nix
index a2d4189f401..47fcc87b3c0 100644
--- a/modules/targets/generic-linux.nix
+++ b/modules/targets/generic-linux.nix
@@ -14,14 +14,24 @@ in {
GNU/Linux distributions other than NixOS.
'';
};
+
+ extraXdgDataDirs = mkOption {
+ type = types.listOf types.str;
+ default = [ ];
+ example = [ "/usr/share" "/usr/local/share" ];
+ description = ''
+ List of directory names to add to <envar>XDG_DATA_DIRS</envar>.
+ '';
+ };
};
config = mkIf config.targets.genericLinux.enable {
home.sessionVariables = let
profiles =
[ "\${NIX_STATE_DIR:-/nix/var/nix}/profiles/default" profileDirectory ];
- dataDirs =
- concatStringsSep ":" (map (profile: "${profile}/share") profiles);
+ dataDirs = concatStringsSep ":"
+ (map (profile: "${profile}/share") profiles
+ ++ config.targets.genericLinux.extraXdgDataDirs);
in { XDG_DATA_DIRS = "${dataDirs}\${XDG_DATA_DIRS:+:}$XDG_DATA_DIRS"; };
home.sessionVariablesExtra = ''
diff --git a/tests/modules/targets-linux/generic-linux.nix b/tests/modules/targets-linux/generic-linux.nix
index d9bb85b651a..10481b5e988 100644
--- a/tests/modules/targets-linux/generic-linux.nix
+++ b/tests/modules/targets-linux/generic-linux.nix
@@ -4,13 +4,16 @@ with lib;
{
config = {
- targets.genericLinux.enable = true;
+ targets.genericLinux = {
+ enable = true;
+ extraXdgDataDirs = [ "/foo" ];
+ };
nmt.script = ''
assertFileExists home-path/etc/profile.d/hm-session-vars.sh
assertFileContains \
home-path/etc/profile.d/hm-session-vars.sh \
- 'export XDG_DATA_DIRS="''${NIX_STATE_DIR:-/nix/var/nix}/profiles/default/share:/home/hm-user/.nix-profile/share''${XDG_DATA_DIRS:+:}$XDG_DATA_DIRS"'
+ 'export XDG_DATA_DIRS="''${NIX_STATE_DIR:-/nix/var/nix}/profiles/default/share:/home/hm-user/.nix-profile/share:/foo''${XDG_DATA_DIRS:+:}$XDG_DATA_DIRS"'
assertFileContains \
home-path/etc/profile.d/hm-session-vars.sh \
'. "${pkgs.nix}/etc/profile.d/nix.sh"'