1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-26 21:19:45 +01:00

firefox: refactor duplicate profile ID detection

This commit is contained in:
Damien Cassou 2023-10-11 08:47:17 +02:00 committed by Robert Helgesson
parent 6a8444467c
commit 858fe2f09a
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
2 changed files with 25 additions and 12 deletions

View file

@ -111,6 +111,29 @@ let
</p></DL>
'';
mkNoDuplicateAssertion = entities: entityKind:
(let
# Return an attribute set with entity IDs as keys and a list of
# entity names with corresponding ID as value. An ID is present in
# the result only if more than one entity has it. The argument
# entities is a list of AttrSet of one id/name pair.
findDuplicateIds = entities:
filterAttrs (_entityId: entityNames: length entityNames != 1)
(zipAttrs entities);
duplicates = findDuplicateIds (mapAttrsToList
(entityName: entity: { "${toString entity.id}" = entityName; })
entities);
mkMsg = entityId: entityNames:
" - ID ${entityId} is used by " + concatStringsSep ", " entityNames;
in {
assertion = duplicates == { };
message = ''
Must not have a Firefox ${entityKind} with an existing ID but
'' + concatStringsSep "\n" (mapAttrsToList mkMsg duplicates);
});
in {
meta.maintainers = [ maintainers.rycee maintainers.kira-bruneau ];
@ -490,17 +513,7 @@ in {
(", namely " + concatStringsSep ", " defaults);
})
(let
duplicates = filterAttrs (_: v: length v != 1) (zipAttrs
(mapAttrsToList (n: v: { "${toString v.id}" = n; }) (cfg.profiles)));
mkMsg = n: v: " - ID ${n} is used by ${concatStringsSep ", " v}";
in {
assertion = duplicates == { };
message = ''
Must not have Firefox profiles with duplicate IDs but
'' + concatStringsSep "\n" (mapAttrsToList mkMsg duplicates);
})
(mkNoDuplicateAssertion cfg.profiles "profile")
];
warnings = optional (cfg.enableGnomeExtensions or false) ''

View file

@ -5,7 +5,7 @@
config = lib.mkIf config.test.enableBig {
test.asserts.assertions.expected = [''
Must not have Firefox profiles with duplicate IDs but
Must not have a Firefox profile with an existing ID but
- ID 1 is used by first, second''];
programs.firefox = {