From dd1bc94d75f7295c5da2b58267bc67d15ea8f0da Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Thu, 8 Aug 2024 15:28:29 +0200 Subject: [PATCH] Inherit Windows users from linux --- lib/modules/users.nix | 99 ++++++++++++++++++++++++++--------------- lib/modules/windows.nix | 21 +-------- lib/text.nix | 9 ++++ 3 files changed, 73 insertions(+), 56 deletions(-) create mode 100644 lib/text.nix diff --git a/lib/modules/users.nix b/lib/modules/users.nix index d9f56fc2..337dff7c 100644 --- a/lib/modules/users.nix +++ b/lib/modules/users.nix @@ -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; + }; }; }; } diff --git a/lib/modules/windows.nix b/lib/modules/windows.nix index da53d15e..3ae9b93d 100644 --- a/lib/modules/windows.nix +++ b/lib/modules/windows.nix @@ -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"; diff --git a/lib/text.nix b/lib/text.nix new file mode 100644 index 00000000..a203c3dc --- /dev/null +++ b/lib/text.nix @@ -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) + ); +}