diff --git a/modules/users/default.nix b/modules/users/default.nix index f537f6be..aaf2f9a6 100644 --- a/modules/users/default.nix +++ b/modules/users/default.nix @@ -158,5 +158,16 @@ in '') deletedUsers} ''; + environment.etc = mapAttrs' (name: { packages, ... }: { + name = "profiles/per-user/${name}"; + value.source = pkgs.buildEnv { + name = "user-environment"; + paths = packages; + inherit (config.environment) pathsToLink extraOutputsToInstall; + inherit (config.system.path) postBuild; + }; + }) (filterAttrs (_: u: u.packages != []) cfg.users); + + environment.profiles = [ "/etc/profiles/per-user/$USER" ]; }; } diff --git a/modules/users/user.nix b/modules/users/user.nix index 3f39473d..ec8ecb83 100644 --- a/modules/users/user.nix +++ b/modules/users/user.nix @@ -57,6 +57,17 @@ with lib; example = literalExample "pkgs.bashInteractive"; description = "The user's shell."; }; + + packages = mkOption { + type = types.listOf types.package; + default = []; + example = literalExample "[ pkgs.firefox pkgs.thunderbird ]"; + description = '' + The set of packages that should be made availabe to the user. + This is in contrast to , + which adds packages to all users. + ''; + }; }; config = { diff --git a/tests/users-packages.nix b/tests/users-packages.nix new file mode 100644 index 00000000..dfcc743f --- /dev/null +++ b/tests/users-packages.nix @@ -0,0 +1,17 @@ +{ config, pkgs, ... }: + +{ + users.knownUsers = [ "foo" ]; + users.users.foo.uid = 42000; + users.users.foo.gid = 42000; + users.users.foo.description = "Foo user"; + users.users.foo.isHidden = false; + users.users.foo.home = "/Users/foo"; + users.users.foo.shell = "/run/current-system/sw/bin/bash"; + users.users.foo.packages = [ pkgs.hello ]; + + test = '' + echo "checking for hello in /etc/profiles/per-user/foo" >&2 + test -x /etc/profiles/per-user/foo/bin/hello + ''; +}