Inherit Windows users from linux

This commit is contained in:
Manuel Thalmann 2024-08-08 15:28:29 +02:00
parent 976fec72ad
commit dd1bc94d75
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,7 +24,8 @@
}; };
}); });
userType = types.submodule ( mkUserType = { options }: (
types.submodule (
{ ... }: { { ... }: {
options = { options = {
displayName = mkOption { displayName = mkOption {
@ -48,8 +52,6 @@
default = null; default = null;
}; };
git = (import ./git/options.nix) { inherit lib; };
rclone = { rclone = {
configurations = mkOption { configurations = mkOption {
type = types.attrsOf syncType; type = types.attrsOf syncType;
@ -57,8 +59,22 @@
default = {}; 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)
);
}