Inherit Windows users from linux

This commit is contained in:
Manuel Thalmann 2024-08-08 15:28:29 +02:00
parent 6cd1cbb541
commit b28a38b191
3 changed files with 73 additions and 56 deletions

View file

@ -1,10 +1,13 @@
{ lib, ... }: { config, lib, ... }:
let let
inherit (lib) inherit (lib)
mkOption mkOption
types types
; ;
cfg = config.valhalla;
capitalize = (import ../text.nix { inherit lib; }).capitalize;
syncType = types.submodule ( syncType = types.submodule (
{ ... }: { { ... }: {
options = { options = {
@ -21,44 +24,57 @@
}; };
}); });
userType = types.submodule ( mkUserType = { options }: (
{ ... }: { types.submodule (
options = { { ... }: {
displayName = mkOption { options = {
type = types.nullOr types.str; displayName = mkOption {
description = "The human-readable name of the user."; type = types.nullOr types.str;
default = null; description = "The human-readable name of the user.";
}; default = null;
mailAddress = mkOption {
type = types.nullOr types.str;
description = "The mail address of the user.";
default = null;
};
groups = mkOption {
type = types.listOf types.str;
description = "The additional groups of the user.";
default = [];
};
defaultShell = mkOption {
type = types.nullOr types.str;
description = "The default shell of the user.";
default = null;
};
git = (import ./git/options.nix) { inherit lib; };
rclone = {
configurations = mkOption {
type = types.attrsOf syncType;
description = "The configurations of the rclone mounts.";
default = {};
}; };
};
mailAddress = mkOption {
type = types.nullOr types.str;
description = "The mail address of the user.";
default = null;
};
groups = mkOption {
type = types.listOf types.str;
description = "The additional groups of the user.";
default = [];
};
defaultShell = mkOption {
type = types.nullOr types.str;
description = "The default shell of the user.";
default = null;
};
rclone = {
configurations = mkOption {
type = types.attrsOf syncType;
description = "The configurations of the rclone mounts.";
default = {};
};
};
git = (import ./git/options.nix) { inherit lib; };
} // options;
}));
userType = mkUserType { options = {}; };
winUserType = mkUserType {
options = {
microsoftAccount = mkOption {
type = types.bool;
description = "A value indicating whether this user is a Microsoft Account.";
default = false;
}; };
}); };
};
in { in {
options = { options = {
valhalla = { valhalla = {
@ -67,6 +83,15 @@
description = "The users to create on the machine."; description = "The users to create on the machine.";
default = {}; default = {};
}; };
windows.users = mkOption {
type = types.attrsOf winUserType;
description = "The users to create on the Windows machine.";
default = lib.attrsets.concatMapAttrs (
name: options: {
${capitalize name} = options;
}) cfg.users;
};
}; };
}; };
} }

View file

@ -1,4 +1,4 @@
{ lib, config, options, ... }: { lib, config, ... }:
let let
inherit (lib) inherit (lib)
mkOption mkOption
@ -7,16 +7,8 @@
types types
; ;
users = config.valhalla.users;
setupUser = config.valhalla.setupUser.name; setupUser = config.valhalla.setupUser.name;
capitalize = (import ../text.nix { inherit lib; }).capitalize;
capitalize = text:
let
chars = lib.strings.stringToCharacters text;
in lib.strings.concatStrings (
[(lib.strings.toUpper (builtins.elemAt chars 0))] ++
(lib.lists.drop 1 chars)
);
winType = types.submodule ( winType = types.submodule (
{ config, ... }: { { config, ... }: {
@ -27,15 +19,6 @@
default = capitalize setupUser; default = capitalize setupUser;
}; };
users = mkOption {
type = options.valhalla.users.type;
description = "The users to add.";
default = lib.attrsets.concatMapAttrs (
name: options: {
${capitalize name} = options;
}) users;
};
dualboot = { dualboot = {
enable = mkEnableOption "dual boot"; enable = mkEnableOption "dual boot";

9
lib/text.nix Normal file
View file

@ -0,0 +1,9 @@
{ lib, ... }: {
capitalize = text:
let
chars = lib.strings.stringToCharacters text;
in lib.strings.concatStrings (
[(lib.strings.toUpper (builtins.elemAt chars 0))] ++
(lib.lists.drop 1 chars)
);
}