Fix inheritance of user config

This commit is contained in:
Manuel Thalmann 2024-08-23 18:28:20 +02:00
parent ec1368950e
commit 2af3a6de6f
2 changed files with 56 additions and 69 deletions

View file

@ -8,22 +8,6 @@
cfg = config.valhalla; cfg = config.valhalla;
capitalize = (import ../text.nix { inherit lib; }).capitalize; capitalize = (import ../text.nix { inherit lib; }).capitalize;
linuxOptions = {
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 = {};
};
};
};
syncType = types.submodule ( syncType = types.submodule (
{ ... }: { { ... }: {
options = { options = {
@ -39,73 +23,76 @@
}; };
}; };
}); });
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 = [];
};
git = (import ./git/options.nix) { inherit lib; };
} // options;
}));
userType = mkUserType {
options = linuxOptions;
};
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 = {
users = mkOption { users = mkOption {
type = types.attrsOf userType; type = types.attrsOf (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 = [];
};
git = (import ./git/options.nix) { inherit lib; };
};
}));
description = "The users to create on the machine."; description = "The users to create on the machine.";
default = {}; default = {};
}; };
linux.users = mkOption {
type = types.attrsOf (types.submodule {
options = {
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 = {};
};
};
};
});
};
windows.users = mkOption { windows.users = mkOption {
type = types.attrsOf winUserType; type = types.attrsOf (types.submodule {
description = "The users to create on the Windows machine."; options = {
microsoftAccount = mkOption {
type = types.bool;
description = "A value indicating whether this user is a Microsoft Account.";
default = false;
};
};
});
}; };
}; };
}; };
config = { config = {
valhalla.windows.users = (lib.attrsets.concatMapAttrs ( valhalla.windows.users = lib.mkForce (lib.attrsets.concatMapAttrs (
name: options: { name: options: {
${capitalize name} = (lib.attrsets.concatMapAttrs ( ${capitalize name} = options // {
name: value:
if builtins.elem name (builtins.attrNames linuxOptions)
then {}
else {
${name} = value;
}
) options) // {
groups = []; groups = [];
}; };
}) cfg.users); }) cfg.users);

View file

@ -9,7 +9,7 @@ begin
function userConfig -V dir -a name function userConfig -V dir -a name
source "$dir/../../Scripts/config.fish" source "$dir/../../Scripts/config.fish"
set -l key "valhalla.users.$name.rclone.configurations" set -l key "valhalla.linux.users.$name.rclone.configurations"
set -l configs (getConfig "$key" --apply "builtins.attrNames" --json) set -l configs (getConfig "$key" --apply "builtins.attrNames" --json)
if [ (echo "$configs" | jq "length") -gt 0 ] if [ (echo "$configs" | jq "length") -gt 0 ]