From f58889c07efa8e1328fdf93dc1796ec2a5c47f38 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Sat, 29 Jul 2023 19:01:04 +0200 Subject: [PATCH] gnome-terminal: add assertion on profile names --- modules/programs/gnome-terminal.nix | 20 ++++++++++++++- .../gnome-terminal/bad-profile-name.nix | 25 +++++++++++++++++++ .../programs/gnome-terminal/default.nix | 5 +++- 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 tests/modules/programs/gnome-terminal/bad-profile-name.nix diff --git a/modules/programs/gnome-terminal.nix b/modules/programs/gnome-terminal.nix index e1922cd0..83cfc027 100644 --- a/modules/programs/gnome-terminal.nix +++ b/modules/programs/gnome-terminal.nix @@ -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"; diff --git a/tests/modules/programs/gnome-terminal/bad-profile-name.nix b/tests/modules/programs/gnome-terminal/bad-profile-name.nix new file mode 100644 index 00000000..ebd85440 --- /dev/null +++ b/tests/modules/programs/gnome-terminal/bad-profile-name.nix @@ -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'']; +} diff --git a/tests/modules/programs/gnome-terminal/default.nix b/tests/modules/programs/gnome-terminal/default.nix index 2cfb4923..d4a22427 100644 --- a/tests/modules/programs/gnome-terminal/default.nix +++ b/tests/modules/programs/gnome-terminal/default.nix @@ -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; +}