Inherit Windows users from linux

This commit is contained in:
Manuel Thalmann 2024-08-08 15:28:29 +02:00
parent 5a36ee2c42
commit 1fa4adb53b
3 changed files with 73 additions and 56 deletions

View file

@ -1,10 +1,13 @@
{ lib, ... }:
{ config, lib, ... }:
let
inherit (lib)
mkOption
types
;
cfg = config.valhalla;
capitalize = (import ../text.nix { inherit lib; }).capitalize;
syncType = types.submodule (
{ ... }: {
options = {
@ -21,44 +24,57 @@
};
});
userType = types.submodule (
{ ... }: {
options = {
displayName = mkOption {
type = types.nullOr types.str;
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 = {};
mkUserType = { options }: (
types.submodule (
{ ... }: {
options = {
displayName = mkOption {
type = types.nullOr types.str;
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;
};
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 {
options = {
valhalla = {
@ -67,6 +83,15 @@
description = "The users to create on the machine.";
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
inherit (lib)
mkOption
@ -7,16 +7,8 @@
types
;
users = config.valhalla.users;
setupUser = config.valhalla.setupUser.name;
capitalize = text:
let
chars = lib.strings.stringToCharacters text;
in lib.strings.concatStrings (
[(lib.strings.toUpper (builtins.elemAt chars 0))] ++
(lib.lists.drop 1 chars)
);
capitalize = (import ../text.nix { inherit lib; }).capitalize;
winType = types.submodule (
{ config, ... }: {
@ -27,15 +19,6 @@
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 = {
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)
);
}