Create separate option holding win users

This commit is contained in:
Manuel Thalmann 2024-08-24 03:25:28 +02:00
parent e185bbe3c9
commit 6f2e9b894e
4 changed files with 78 additions and 16 deletions

View file

@ -0,0 +1,44 @@
{ lib, ... }:
let
inherit (lib)
mkEnableOption
mkOption
types
;
syncType = types.submodule (
{ ... }: {
options = {
remotePath = mkOption {
type = types.str;
description = "The path to the folder on the cloud to sync.";
};
localPath = mkOption {
type = types.str;
description = "The path to sync the cloud content to.";
};
virtualFiles = (mkEnableOption "virtual file support") // {
default = true;
};
};
});
in {
options = {
valhalla.windows.users = mkOption {
type = types.attrsOf (types.submodule (
{ ... }: {
options = {
nextcloud = {
folderSyncs = mkOption {
type = types.listOf syncType;
description = "The folders to synchronize.";
default = [];
};
};
};
}));
};
};
}

View file

@ -1,11 +1,10 @@
{ config, lib, ... }: { lib, ... }:
let let
inherit (lib) inherit (lib)
mkOption mkOption
types types
; ;
cfg = config.valhalla;
capitalize = (import ../text.nix { inherit lib; }).capitalize; capitalize = (import ../text.nix { inherit lib; }).capitalize;
userType = types.submodule ( userType = types.submodule (
@ -65,18 +64,29 @@
type = types.attrsOf linuxUserType; type = types.attrsOf linuxUserType;
}; };
windows.users = mkOption { windows = mkOption {
type = types.attrsOf winUserType; type = types.submoduleWith {
modules = [
({ config, options, ... }: {
options = {
users = mkOption {
type = types.attrsOf winUserType;
};
winUsers = mkOption {
type = options.users.type;
default = (lib.attrsets.concatMapAttrs (
name: options: {
${capitalize name} = options // {
groups = [];
};
}) config.users);
};
};
})
];
};
}; };
}; };
}; };
config = {
valhalla.windows.users = lib.mkForce (lib.attrsets.concatMapAttrs (
name: options: {
${capitalize name} = options // {
groups = [];
};
}) cfg.users);
};
} }

View file

@ -11,7 +11,7 @@
linuxPercentage = 70; # better safe than sorry linuxPercentage = 70; # better safe than sorry
}; };
users.Manuel = { users.manuel = {
microsoftAccount = true; microsoftAccount = true;
groups = ["Administrators"]; groups = ["Administrators"];
}; };

View file

@ -164,6 +164,14 @@ $null = New-Module {
return "valhalla.$($IsWindows ? "windows" : "linux")"; return "valhalla.$($IsWindows ? "windows" : "linux")";
} }
<#
.SYNOPSIS
Gets the name of the user root.
#>
function Get-UserRootName {
return "$(Get-ConfigRootName).$($IsWindows ? "winUsers" : "users")";
}
<# <#
.SYNOPSIS .SYNOPSIS
Gets a user configuration. Gets a user configuration.
@ -182,7 +190,7 @@ $null = New-Module {
) )
if ((Get-Users) -contains $UserName) { if ((Get-Users) -contains $UserName) {
Get-Config "$(Get-ConfigRootName).users.$UserName.$Name"; Get-Config "$(Get-UserRootName).$UserName.$Name";
} else { } else {
return $null; return $null;
} }
@ -210,7 +218,7 @@ $null = New-Module {
function Get-Users { function Get-Users {
[OutputType([string[]])] [OutputType([string[]])]
param() param()
Get-Attributes "$(Get-ConfigRootName).users"; Get-Attributes "$(Get-UserRootName)";
} }
<# <#