1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2025-03-31 04:04:45 +00:00

primary-user: init

This commit is contained in:
Emily 2025-01-11 15:44:41 +00:00
parent e9f41de2a8
commit e0c3c3e7f8
3 changed files with 74 additions and 0 deletions

View file

@ -10,6 +10,7 @@
./security/sudo.nix
./system
./system/base.nix
./system/primary-user.nix
./system/checks.nix
./system/activation-scripts.nix
./system/applications.nix

View file

@ -31,6 +31,18 @@ let
fi
'';
primaryUser = ''
primaryUser=${escapeShellArg config.system.primaryUser}
if ! id -- "$primaryUser" >/dev/null 2>&1; then
printf >&2 '\e[1;31merror: primary user `%s` does not exist, aborting activation\e[0m\n' \
"$primaryUser"
printf >&2 'Please ensure that `system.primaryUser` is set to the name of an\n'
printf >&2 'existing user. Usually this should be the user you have been using to\n'
printf >&2 'run `darwin-rebuild`.\n'
exit 2
fi
'';
determinate = ''
if [[ -e /usr/local/bin/determinate-nixd ]]; then
printf >&2 '\e[1;31merror: Determinate detected, aborting activation\e[0m\n'
@ -275,6 +287,7 @@ in
system.checks.text = mkMerge [
(mkIf cfg.verifyMacOSVersion macOSVersion)
(mkIf (config.system.primaryUser != null) primaryUser)
(mkIf config.nix.enable determinate)
(mkIf cfg.verifyBuildUsers preSequoiaBuildUsers)
(mkIf cfg.verifyBuildUsers buildGroupID)

View file

@ -0,0 +1,60 @@
{
lib,
options,
config,
...
}:
{
options = {
system.primaryUser = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = ''
The user used for options that previously applied to the user
running `darwin-rebuild`.
This is a transition mechanism as nix-darwin reorganizes its
options and will eventually be unnecessary and removed.
'';
};
system.requiresPrimaryUser = lib.mkOption {
internal = true;
type = lib.types.listOf lib.types.str;
default = [ ];
};
};
config = {
assertions = [
{
assertion = config.system.primaryUser == null -> config.system.requiresPrimaryUser == [ ];
message = ''
Previously, some nix-darwin options applied to the user running
`darwin-rebuild`. As part of a longterm migration to make
nix-darwin focus on systemwide activation and support firstclass
multiuser setups, all system activation now runs as `root`, and
these options instead apply to the `system.primaryUser` user.
You currently have the following primaryuserrequiring options set:
${lib.concatMapStringsSep "\n" (name: "* `${name}`") (
lib.sort (name1: name2: name1 < name2) config.system.requiresPrimaryUser
)}
To continue using these options, set `system.primaryUser` to the name
of the user you have been using to run `darwin-rebuild`. In the long
run, this setting will be deprecated and removed after all the
functionality it is relevant for has been adjusted to allow
specifying the relevant user separately, moved under the
`users.users.*` namespace, or migrated to Home Manager.
If you run into any unexpected issues with the migration, please
open an issue at <https://github.com/LnL7/nix-darwin/issues/new>
and include as much information as possible.
'';
}
];
};
}