commit a3cdc321426e69c9898d75bf7ee60af754a99637
parent 25a46dcb2c88e71f0f999842a1df8d5fc4e8cef9
Author: Daniel Barlow <dan@telent.net>
Date: Sat, 4 Mar 2023 00:24:48 +0000
define structured options for config.users
Diffstat:
2 files changed, 47 insertions(+), 19 deletions(-)
diff --git a/modules/base.nix b/modules/base.nix
@@ -35,22 +35,6 @@ in {
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 = {
commandLine = mkOption {
type = types.listOf types.nonEmptyStr;
@@ -102,7 +86,7 @@ in {
users.root = {
uid = 0; gid= 0; gecos = "Root of all evaluation";
dir = "/";
- passwd = "";
+ passwd = lib.mkDefault "";
shell = "/bin/sh";
};
groups = {
diff --git a/modules/users.nix b/modules/users.nix
@@ -1,9 +1,9 @@
{ lib, pkgs, config, ...}:
let
- inherit (lib) concatStrings concatStringsSep mapAttrsToList; # mkEnableOption mkOption types isDerivation isType hasAttr ;
+ inherit (lib)
+ concatStrings concatStringsSep mapAttrsToList mkOption types;
inherit (builtins) toString;
inherit (pkgs.pseudofile) dir symlink;
-# inherit (pkgs) busybox;
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" )
config.users;
@@ -15,6 +15,50 @@ let
config.groups;
in concatStrings lines;
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 = {
filesystem = dir {
etc = dir {