refactor: shared config metadata
This commit is contained in:
@@ -16,9 +16,7 @@ in
|
||||
hostSourceControlUsers = host.sourceControl.users;
|
||||
hostUserSourceControl = hostSourceControlUsers.${user.name} or { };
|
||||
|
||||
scopeEmails =
|
||||
scope:
|
||||
lib.filter (email: email.scope == scope) (builtins.attrValues user.emails);
|
||||
scopeEmails = scope: lib.filter (email: email.scope == scope) (builtins.attrValues user.emails);
|
||||
|
||||
emailForScope =
|
||||
scope:
|
||||
@@ -53,30 +51,30 @@ in
|
||||
in
|
||||
if keyConfig == null then null else keyConfig.publicKey;
|
||||
|
||||
scopesInUse = lib.unique (
|
||||
[
|
||||
"personal"
|
||||
sourceControl.projectScope
|
||||
]
|
||||
);
|
||||
scopesInUse = lib.unique ([
|
||||
"personal"
|
||||
sourceControl.projectScope
|
||||
]);
|
||||
|
||||
invalidEmailScopes = builtins.filter (scope: emailForScope scope == null) scopesInUse;
|
||||
allowedSignersLines = map (scope: "${emailForScope scope} ${publicKeyForScope scope}") (
|
||||
builtins.filter (scope: emailForScope scope != null && scopeHasSigningKey scope) scopesInUse
|
||||
);
|
||||
|
||||
gitConfigForScope =
|
||||
scope:
|
||||
lib.recursiveUpdate {
|
||||
user = {
|
||||
name = user.realName;
|
||||
email = emailForScope scope;
|
||||
};
|
||||
}
|
||||
(lib.optionalAttrs (scopeHasSigningKey scope) {
|
||||
gpg.ssh.allowedSignersFile = "${config.xdg.configHome}/git/allowed_signers";
|
||||
user.signingKey = "${privateKeyPathForScope scope}.pub";
|
||||
});
|
||||
lib.recursiveUpdate
|
||||
{
|
||||
user = {
|
||||
name = user.realName;
|
||||
email = emailForScope scope;
|
||||
};
|
||||
}
|
||||
(
|
||||
lib.optionalAttrs (scopeHasSigningKey scope) {
|
||||
gpg.ssh.allowedSignersFile = "${config.xdg.configHome}/git/allowed_signers";
|
||||
user.signingKey = "${privateKeyPathForScope scope}.pub";
|
||||
}
|
||||
);
|
||||
|
||||
gitRoots = [
|
||||
{
|
||||
@@ -92,13 +90,6 @@ in
|
||||
{
|
||||
imports = [ homeModules.git ];
|
||||
|
||||
assertions = [
|
||||
{
|
||||
assertion = invalidEmailScopes == [ ];
|
||||
message = "Expected exactly one scoped email for `${user.name}` source-control scopes: ${lib.concatStringsSep ", " invalidEmailScopes}.";
|
||||
}
|
||||
];
|
||||
|
||||
xdg.configFile."git/allowed_signers".text = lib.concatStringsSep "\n" (
|
||||
allowedSignersLines ++ [ "" ]
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user