gnome-terminal: add assertion on profile names

This commit is contained in:
Robert Helgesson 2023-07-29 19:01:04 +02:00
parent 5c23226768
commit f58889c07e
No known key found for this signature in database
GPG Key ID: 36BDAA14C2797E89
3 changed files with 48 additions and 2 deletions

View File

@ -292,12 +292,30 @@ in {
profile = mkOption {
default = { };
type = types.attrsOf profileSubModule;
description = "A set of Gnome Terminal profiles.";
description = ''
A set of Gnome Terminal profiles. Note, the name of a profile must be
a UUID. You can generate one, for example, using {command}`uuidgen`
(from `util-linux`).
'';
};
};
};
config = mkIf cfg.enable {
assertions = [
(let
uuidre =
"[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}";
erroneous =
filter (n: builtins.match uuidre n == null) (attrNames cfg.profile);
in {
assertion = erroneous == [ ];
message = ''
The attribute name of a Gnome Terminal profile must be a UUID.
Incorrect profile names: ${concatStringsSep ", " erroneous}'';
})
];
home.packages = [ pkgs.gnome.gnome-terminal ];
dconf.settings = let dconfPath = "org/gnome/terminal/legacy";

View File

@ -0,0 +1,25 @@
{ config, ... }:
{
programs.gnome-terminal = {
enable = true;
profile = {
bad-name = { visibleName = "a"; };
"e0b782ed-6aca-44eb-8c75-62b3706b6220" = {
default = true;
visibleName = "b";
};
another-bad-name = { visibleName = "c"; };
};
};
nixpkgs.overlays = [
(self: super: { gnome.gnome-terminal = config.lib.test.mkStubPackage { }; })
];
test.stubs.dconf = { };
test.asserts.assertions.expected = [''
The attribute name of a Gnome Terminal profile must be a UUID.
Incorrect profile names: another-bad-name, bad-name''];
}

View File

@ -1 +1,4 @@
{ gnome-terminal-1 = ./gnome-terminal-1.nix; }
{
gnome-terminal-1 = ./gnome-terminal-1.nix;
gnome-terminal-bad-profile-name = ./bad-profile-name.nix;
}