29c5178bdf
list of user accounts that the job needs to run. For instance, the SSH daemon job says: { name = "sshd"; uid = (import ../system/ids.nix).uids.sshd; description = "SSH privilege separation user"; home = "/var/empty"; } The activation script creates the system users/groups and updates them as well. So a change in the Nix expression can be realised in /etc/{group,passwd} by running nixos-rebuild. svn path=/nixos/trunk/; revision=8846
72 lines
1.9 KiB
Nix
72 lines
1.9 KiB
Nix
{pkgs, upstartJobs, defaultShell}:
|
|
|
|
let ids = import ./ids.nix; in
|
|
|
|
rec {
|
|
|
|
# System user accounts.
|
|
systemUsers =
|
|
let
|
|
jobUsers = pkgs.lib.concatLists (map (job: job.users) upstartJobs.jobs);
|
|
|
|
defaultUsers =
|
|
[
|
|
{ name = "root";
|
|
uid = ids.uids.root;
|
|
description = "System administrator";
|
|
home = "/root";
|
|
shell = defaultShell;
|
|
}
|
|
{ name = "nobody";
|
|
uid = ids.uids.nobody;
|
|
description = "Unprivileged account (don't use!)";
|
|
}
|
|
];
|
|
|
|
makeNixBuildUser = nr:
|
|
{ name = "nixbld${toString nr}";
|
|
description = "Nix build user ${toString nr}";
|
|
uid = builtins.add ids.uids.nixbld nr;
|
|
extraGroups = ["nixbld"];
|
|
};
|
|
|
|
nixBuildUsers = map makeNixBuildUser (pkgs.lib.range 1 10);
|
|
|
|
addAttrs =
|
|
{ name
|
|
, description
|
|
, uid ? ""
|
|
, group ? "nogroup"
|
|
, extraGroups ? []
|
|
, home ? "/var/empty"
|
|
, shell ? "/noshell"
|
|
}:
|
|
{ inherit name description uid group extraGroups home shell; };
|
|
|
|
in map addAttrs (defaultUsers ++ jobUsers ++ nixBuildUsers);
|
|
|
|
|
|
# System groups.
|
|
systemGroups =
|
|
[
|
|
{ name = "root";
|
|
gid = ids.gids.root;
|
|
}
|
|
{ name = "nogroup";
|
|
gid = ids.gids.nogroup;
|
|
}
|
|
{ name = "users";
|
|
gid = ids.gids.users;
|
|
}
|
|
{ name = "nixbld";
|
|
gid = ids.gids.nixbld;
|
|
}
|
|
];
|
|
|
|
|
|
# Awful hackery necessary to pass the users/groups to the activation script.
|
|
createUsersGroups = ../helpers/create-users-groups.sh;
|
|
usersList = pkgs.writeText "users" (pkgs.lib.concatStrings (map (u: "${u.name}\n${u.description}\n${toString u.uid}\n${u.group}\n${toString u.extraGroups}\n${u.home}\n${u.shell}\n") systemUsers));
|
|
groupsList = pkgs.writeText "groups" (pkgs.lib.concatStrings (map (g: "${g.name}\n${toString g.gid}\n") systemGroups));
|
|
|
|
} |