mirror of
https://github.com/nix-community/home-manager
synced 2024-12-26 03:39:47 +01:00
firefox: refactor duplicate profile ID detection
This commit is contained in:
parent
c28bf5c586
commit
f55c68baf9
2 changed files with 25 additions and 12 deletions
|
@ -111,6 +111,29 @@ let
|
||||||
</p></DL>
|
</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 {
|
in {
|
||||||
meta.maintainers = [ maintainers.rycee maintainers.kira-bruneau ];
|
meta.maintainers = [ maintainers.rycee maintainers.kira-bruneau ];
|
||||||
|
|
||||||
|
@ -490,17 +513,7 @@ in {
|
||||||
(", namely " + concatStringsSep ", " defaults);
|
(", namely " + concatStringsSep ", " defaults);
|
||||||
})
|
})
|
||||||
|
|
||||||
(let
|
(mkNoDuplicateAssertion cfg.profiles "profile")
|
||||||
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);
|
|
||||||
})
|
|
||||||
];
|
];
|
||||||
|
|
||||||
warnings = optional (cfg.enableGnomeExtensions or false) ''
|
warnings = optional (cfg.enableGnomeExtensions or false) ''
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
config = lib.mkIf config.test.enableBig {
|
config = lib.mkIf config.test.enableBig {
|
||||||
test.asserts.assertions.expected = [''
|
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''];
|
- ID 1 is used by first, second''];
|
||||||
|
|
||||||
programs.firefox = {
|
programs.firefox = {
|
||||||
|
|
Loading…
Reference in a new issue