From a3cdc321426e69c9898d75bf7ee60af754a99637 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sat, 4 Mar 2023 00:24:48 +0000 Subject: [PATCH] define structured options for config.users --- modules/base.nix | 18 +----------------- modules/users.nix | 48 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 19 deletions(-) diff --git a/modules/base.nix b/modules/base.nix index ab13e0a..e0b8656 100644 --- 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 index 63edb2a..21f46b4 100644 --- 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 {