2022-07-15 04:53:28 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
2022-05-22 08:27:02 +00:00
|
|
|
|
|
|
|
# installer docs: https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/profiles/installation-device.nix
|
2022-07-31 18:35:15 +00:00
|
|
|
with lib;
|
|
|
|
let
|
2022-08-01 07:23:49 +00:00
|
|
|
cfg = config.sane.users;
|
2022-08-03 07:41:59 +00:00
|
|
|
# see nixpkgs/nixos/modules/services/networking/dhcpcd.nix
|
|
|
|
hasDHCP = config.networking.dhcpcd.enable &&
|
|
|
|
(config.networking.useDHCP || any (i: i.useDHCP == true) (attrValues config.networking.interfaces));
|
|
|
|
|
2022-07-31 18:35:15 +00:00
|
|
|
in
|
2022-05-22 08:27:02 +00:00
|
|
|
{
|
2022-07-31 18:35:15 +00:00
|
|
|
options = {
|
2022-08-01 07:23:49 +00:00
|
|
|
sane.users.guest.enable = mkOption {
|
2022-07-31 18:35:15 +00:00
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
};
|
2022-05-22 08:27:02 +00:00
|
|
|
};
|
|
|
|
|
2022-07-31 18:35:15 +00:00
|
|
|
config = {
|
|
|
|
# Users are exactly these specified here;
|
|
|
|
# old ones will be deleted (from /etc/passwd, etc) upon upgrade.
|
|
|
|
users.mutableUsers = false;
|
2022-05-22 08:27:02 +00:00
|
|
|
|
2022-07-31 18:35:15 +00:00
|
|
|
# docs: https://nixpkgs-manual-sphinx-markedown-example.netlify.app/generated/options-db.xml.html#users-users
|
|
|
|
users.users.colin = {
|
|
|
|
# sets group to "users" (?)
|
|
|
|
isNormalUser = true;
|
|
|
|
home = "/home/colin";
|
2022-08-01 07:23:49 +00:00
|
|
|
uid = config.sane.allocations.colin-uid;
|
2022-07-31 18:35:15 +00:00
|
|
|
# i don't get exactly what this is, but nixos defaults to this non-deterministically
|
|
|
|
# in /var/lib/nixos/auto-subuid-map and i don't want that.
|
|
|
|
subUidRanges = [
|
|
|
|
{ startUid=100000; count=1; }
|
|
|
|
];
|
|
|
|
group = "users";
|
|
|
|
extraGroups = [
|
|
|
|
"wheel"
|
|
|
|
"nixbuild"
|
|
|
|
"networkmanager"
|
|
|
|
# phosh/mobile. XXX colin: unsure if necessary
|
|
|
|
"video"
|
|
|
|
"feedbackd"
|
|
|
|
"dialout" # required for modem access
|
|
|
|
];
|
|
|
|
initialPassword = lib.mkDefault "";
|
|
|
|
shell = pkgs.zsh;
|
|
|
|
# shell = pkgs.bashInteractive;
|
|
|
|
# XXX colin: create ssh key for THIS user by logging in and running:
|
|
|
|
# ssh-keygen -t ed25519
|
|
|
|
openssh.authorizedKeys.keys = [
|
|
|
|
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDpmFdNSVPRol5hkbbCivRhyeENzb9HVyf9KutGLP2Zu colin@lappy"
|
|
|
|
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPU5GlsSfbaarMvDA20bxpSZGWviEzXGD8gtrIowc1pX colin@desko"
|
|
|
|
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPS1qFzKurAdB9blkWomq8gI1g0T3sTs9LsmFOj5VtqX colin@servo"
|
|
|
|
# moby doesn't need to login to any other devices yet
|
|
|
|
# "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICrR+gePnl0nV/vy7I5BzrGeyVL+9eOuXHU1yNE3uCwU colin@moby"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2022-08-01 07:23:49 +00:00
|
|
|
sane.impermanence.service-dirs = mkIf cfg.guest.enable [
|
2022-07-31 18:35:15 +00:00
|
|
|
{ user = "guest"; group = "users"; directory = "/home/guest"; }
|
|
|
|
];
|
|
|
|
users.users.guest = mkIf cfg.guest.enable {
|
|
|
|
isNormalUser = true;
|
|
|
|
home = "/home/guest";
|
2022-08-01 07:23:49 +00:00
|
|
|
uid = config.sane.allocations.guest-uid;
|
2022-07-31 18:35:15 +00:00
|
|
|
subUidRanges = [
|
|
|
|
{ startUid=200000; count=1; }
|
|
|
|
];
|
|
|
|
group = "users";
|
|
|
|
initialPassword = lib.mkDefault "";
|
|
|
|
shell = pkgs.zsh;
|
|
|
|
openssh.authorizedKeys.keys = [
|
|
|
|
# TODO: insert pubkeys that should be allowed in
|
|
|
|
];
|
|
|
|
};
|
2022-07-15 04:53:28 +00:00
|
|
|
|
2022-08-03 07:41:59 +00:00
|
|
|
users.users.dhcpcd = mkIf hasDHCP {
|
|
|
|
uid = config.sane.allocations.dhcpcd-uid;
|
|
|
|
};
|
|
|
|
users.groups.dhcpcd = mkIf hasDHCP {
|
|
|
|
gid = config.sane.allocations.dhcpcd-gid;
|
|
|
|
};
|
|
|
|
|
2022-07-31 18:35:15 +00:00
|
|
|
security.sudo = {
|
|
|
|
enable = true;
|
|
|
|
wheelNeedsPassword = false;
|
|
|
|
};
|
2022-07-15 04:53:28 +00:00
|
|
|
|
2022-07-31 18:35:15 +00:00
|
|
|
services.openssh = {
|
|
|
|
enable = true;
|
|
|
|
permitRootLogin = "no";
|
|
|
|
passwordAuthentication = false;
|
|
|
|
};
|
2022-07-15 04:53:28 +00:00
|
|
|
|
2022-07-31 18:35:15 +00:00
|
|
|
# affix some UIDs which were historically auto-generated
|
2022-08-01 07:23:49 +00:00
|
|
|
users.users.sshd.uid = config.sane.allocations.sshd-uid;
|
|
|
|
users.groups.polkituser.gid = config.sane.allocations.polkituser-gid;
|
|
|
|
users.groups.sshd.gid = config.sane.allocations.sshd-gid;
|
|
|
|
users.groups.systemd-coredump.gid = config.sane.allocations.systemd-coredump-gid;
|
2022-07-31 18:35:15 +00:00
|
|
|
|
|
|
|
# guarantee determinism in uid/gid generation for users:
|
|
|
|
assertions = let
|
|
|
|
uidAssertions = builtins.attrValues (builtins.mapAttrs (name: user: {
|
|
|
|
assertion = user.uid != null;
|
|
|
|
message = "non-deterministic uid detected for: ${name}";
|
|
|
|
}) config.users.users);
|
|
|
|
gidAssertions = builtins.attrValues (builtins.mapAttrs (name: group: {
|
|
|
|
assertion = group.gid != null;
|
|
|
|
message = "non-deterministic gid detected for: ${name}";
|
|
|
|
}) config.users.groups);
|
|
|
|
autoSubAssertions = builtins.attrValues (builtins.mapAttrs (name: user: {
|
|
|
|
assertion = !user.autoSubUidGidRange;
|
|
|
|
message = "non-deterministic subUids/Guids detected for: ${name}";
|
|
|
|
}) config.users.users);
|
|
|
|
in uidAssertions ++ gidAssertions ++ autoSubAssertions;
|
|
|
|
};
|
2022-05-22 08:27:02 +00:00
|
|
|
}
|