refactor: simplify shared config contracts
This commit is contained in:
@@ -27,6 +27,13 @@ let
|
||||
|
||||
hasRequiredScopedEmail = scope: user: scopeEmailCount scope user == 1;
|
||||
|
||||
scopeEmailAddress =
|
||||
scope: user:
|
||||
let
|
||||
emails = lib.filter (email: email.scope == scope) (builtins.attrValues user.emails);
|
||||
in
|
||||
if emails == [ ] then "" else (builtins.head emails).address;
|
||||
|
||||
primaryEmailFallback = {
|
||||
address = "";
|
||||
primary = false;
|
||||
@@ -125,6 +132,22 @@ let
|
||||
type = sourceControlScopeType;
|
||||
default = "personal";
|
||||
};
|
||||
|
||||
scopes = lib.mkOption {
|
||||
type = lib.types.attrsOf (
|
||||
lib.types.submodule (
|
||||
{ ... }:
|
||||
{
|
||||
options.email = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
readOnly = true;
|
||||
};
|
||||
}
|
||||
)
|
||||
);
|
||||
readOnly = true;
|
||||
description = "Derived source-control identities keyed by scope.";
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
@@ -149,10 +172,6 @@ let
|
||||
type = lib.types.str;
|
||||
};
|
||||
|
||||
terminalPackagePath = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
};
|
||||
|
||||
nixosConfigurationPath = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "${config.homeDirectory}/.config/nixos";
|
||||
@@ -174,7 +193,12 @@ let
|
||||
};
|
||||
};
|
||||
|
||||
config.primaryEmail = primaryEmail;
|
||||
config = {
|
||||
primaryEmail = primaryEmail;
|
||||
sourceControl.scopes = lib.genAttrs (requiredSourceControlScopes config) (scope: {
|
||||
email = scopeEmailAddress scope config;
|
||||
});
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user