From 6c6c8f21645f23c75bc25417c4fe6d5fb02eabd4 Mon Sep 17 00:00:00 2001 From: Daiderd Jordan Date: Sat, 23 Feb 2019 11:43:39 +0100 Subject: [PATCH] users.users: only extend profiles if packages are defined --- modules/users/default.nix | 6 ++++-- tests/environment-path.nix | 4 ++-- tests/users-packages.nix | 3 +++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/users/default.nix b/modules/users/default.nix index b3ccb90a..5e756946 100644 --- a/modules/users/default.nix +++ b/modules/users/default.nix @@ -17,6 +17,8 @@ let createdUsers = mapAttrsToList (n: v: v) (filterAttrs (n: v: isCreated cfg.knownUsers v.name) cfg.users); deletedGroups = filter (n: isDeleted cfg.groups n) cfg.knownGroups; deletedUsers = filter (n: isDeleted cfg.users n) cfg.knownUsers; + + packageUsers = filterAttrs (_: u: u.packages != []) cfg.users; in { @@ -166,8 +168,8 @@ in inherit (config.environment) pathsToLink extraOutputsToInstall; inherit (config.system.path) postBuild; }; - }) (filterAttrs (_: u: u.packages != []) cfg.users); + }) packageUsers; - environment.profiles = mkOrder 900 [ "/etc/profiles/per-user/$USER" ]; + environment.profiles = mkIf (packageUsers != {}) (mkOrder 900 [ "/etc/profiles/per-user/$USER" ]); }; } diff --git a/tests/environment-path.nix b/tests/environment-path.nix index d347c7de..7d2f46dd 100644 --- a/tests/environment-path.nix +++ b/tests/environment-path.nix @@ -4,10 +4,10 @@ with lib; { test = '' - echo checking /run/current-system/sw/bin in setEnvironment >&2 + echo checking /run/current-system/sw/bin in environment >&2 grep 'export PATH=.*:/run/current-system/sw/bin' ${config.system.build.setEnvironment} - echo checking /bin and /sbin in setEnvironment >&2 + echo checking /bin and /sbin in environment >&2 grep 'export PATH=.*:/usr/bin:/usr/sbin:/bin:/sbin' ${config.system.build.setEnvironment} ''; } diff --git a/tests/users-packages.nix b/tests/users-packages.nix index c7d9895a..02338970 100644 --- a/tests/users-packages.nix +++ b/tests/users-packages.nix @@ -24,5 +24,8 @@ in echo checking for unexpected paths in /etc/profiles/per-user/foo/bin >&2 test -e ${config.out}/etc/profiles/per-user/foo/lib/libhello.dylib && return + + echo "checking /etc/profiles/per-user/foo/bin in environment" >&2 + grep 'export PATH=.*:/etc/profiles/per-user/$USER/bin' ${config.system.build.setEnvironment} ''; }