define structured options for config.users

This commit is contained in:
Daniel Barlow 2023-03-04 00:24:48 +00:00
parent 25a46dcb2c
commit a3cdc32142
2 changed files with 47 additions and 19 deletions

View file

@ -35,22 +35,6 @@ in {
type = types.attrsOf types.nonEmptyStr; type = types.attrsOf types.nonEmptyStr;
}; };
}; };
groups = mkOption {
type = types.attrsOf (types.submodule {
options = {
gid = mkOption {
type = types.int;
};
usernames = mkOption {
type = types.listOf types.str;
default = [];
};
};
});
};
users = mkOption {
type = types.attrsOf types.anything;
};
boot = { boot = {
commandLine = mkOption { commandLine = mkOption {
type = types.listOf types.nonEmptyStr; type = types.listOf types.nonEmptyStr;
@ -102,7 +86,7 @@ in {
users.root = { users.root = {
uid = 0; gid= 0; gecos = "Root of all evaluation"; uid = 0; gid= 0; gecos = "Root of all evaluation";
dir = "/"; dir = "/";
passwd = ""; passwd = lib.mkDefault "";
shell = "/bin/sh"; shell = "/bin/sh";
}; };
groups = { groups = {

View file

@ -1,9 +1,9 @@
{ lib, pkgs, config, ...}: { lib, pkgs, config, ...}:
let let
inherit (lib) concatStrings concatStringsSep mapAttrsToList; # mkEnableOption mkOption types isDerivation isType hasAttr ; inherit (lib)
concatStrings concatStringsSep mapAttrsToList mkOption types;
inherit (builtins) toString; inherit (builtins) toString;
inherit (pkgs.pseudofile) dir symlink; inherit (pkgs.pseudofile) dir symlink;
# inherit (pkgs) busybox;
passwd-file = passwd-file =
let lines = mapAttrsToList (name: u: "${name}:${if u ? passwd then u.passwd else "!!"}:${toString u.uid}:${toString u.gid}:${u.gecos}:${u.dir}:${u.shell}\n" ) let lines = mapAttrsToList (name: u: "${name}:${if u ? passwd then u.passwd else "!!"}:${toString u.uid}:${toString u.gid}:${u.gecos}:${u.dir}:${u.shell}\n" )
config.users; config.users;
@ -15,6 +15,50 @@ let
config.groups; config.groups;
in concatStrings lines; in concatStrings lines;
in { in {
options = {
users = mkOption {
type = types.attrsOf (types.submodule {
options = {
passwd = mkOption {
type = types.str;
default = "!!";
};
uid = mkOption {
type = types.int;
};
gid = mkOption {
type = types.int;
};
gecos = mkOption {
type = types.str;
default = "";
example = "Jo Q User";
};
dir = mkOption {
type = types.str;
default = "/run";
};
shell = mkOption {
type = types.str;
default = "/bin/sh";
};
};
});
};
groups = mkOption {
type = types.attrsOf (types.submodule {
options = {
gid = mkOption {
type = types.int;
};
usernames = mkOption {
type = types.listOf types.str;
default = [];
};
};
});
};
};
config = { config = {
filesystem = dir { filesystem = dir {
etc = dir { etc = dir {