1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2024-12-14 11:57:34 +00:00

Merge pull request #127 from kalbasit/nix-darwin_user-packages

users: install user packages via users.users.<name?>.packages
This commit is contained in:
Daiderd Jordan 2019-02-23 11:45:40 +01:00 committed by GitHub
commit ece03c592e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 6 deletions

View file

@ -152,12 +152,11 @@ in
environment.systemPath = [ (makeBinPath cfg.profiles) "/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin" ];
environment.profiles =
[ # Use user, default and system profiles.
"$HOME/.nix-profile"
"/run/current-system/sw"
"/nix/var/nix/profiles/default"
];
# Use user, default and system profiles.
environment.profiles = mkMerge [
(mkOrder 800 [ "$HOME/.nix-profile" ])
[ "/run/current-system/sw" "/nix/var/nix/profiles/default" ]
];
environment.pathsToLink = [ "/bin" "/share/locale" ];

View file

@ -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 = mkOrder 900 [ "/etc/profiles/per-user/$USER" ];
};
}

View file

@ -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 <option>environment.systemPackages</option>,
which adds packages to all users.
'';
};
};
config = {

View file

@ -117,6 +117,7 @@ let
tests.system-path = makeTest ./tests/system-path.nix;
tests.system-shells = makeTest ./tests/system-shells.nix;
tests.users-groups = makeTest ./tests/users-groups.nix;
tests.users-packages = makeTest ./tests/users-packages.nix;
tests.fonts = makeTest ./tests/fonts.nix;
}

28
tests/users-packages.nix Normal file
View file

@ -0,0 +1,28 @@
{ config, pkgs, ... }:
let
hello = pkgs.runCommand "hello-0.0.0" {} ''
mkdir -p $out/bin $out/lib
touch $out/bin/hello $out/lib/libhello.dylib
'';
in
{
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 = [ hello ];
test = ''
echo checking hello binary in /etc/profiles/per-user/foo/bin >&2
test -e ${config.out}/etc/profiles/per-user/foo/bin/hello
test "$(readlink -f ${config.out}/etc/profiles/per-user/foo/bin/hello)" = "${hello}/bin/hello"
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
'';
}