From d85bf67c48f5c64ca39d3d48375e742e16933f4f Mon Sep 17 00:00:00 2001 From: Mmequignon Date: Wed, 27 Oct 2021 19:13:07 +0200 Subject: [PATCH] pet: fix settings format issue Before it was not possible to place setting values outside the `General` section. --- docs/release-notes/rl-2111.adoc | 11 +++++ modules/programs/pet.nix | 21 +++++++--- tests/modules/programs/pet/default.nix | 6 ++- tests/modules/programs/pet/settings_21_05.nix | 26 ++++++++++++ tests/modules/programs/pet/settings_21_11.nix | 42 +++++++++++++++++++ 5 files changed, 99 insertions(+), 7 deletions(-) create mode 100644 tests/modules/programs/pet/settings_21_05.nix create mode 100644 tests/modules/programs/pet/settings_21_11.nix diff --git a/docs/release-notes/rl-2111.adoc b/docs/release-notes/rl-2111.adoc index ecd189956..0db9e9010 100644 --- a/docs/release-notes/rl-2111.adoc +++ b/docs/release-notes/rl-2111.adoc @@ -45,3 +45,14 @@ changes are only active if the `home.stateVersion` option is set to "21.11" or later. * The <> option now defaults to `null`, meaning that Home Manager won't do any keyboard layout management. For example, `setxkbmap` won't be run in X sessions. + +* The <> option no longer place its value inside a `General` attribute. +For example, is you before had ++ +[source,nix] +programs.pet.settings.editor = "nvim"; ++ +then you now need ++ +[source,nix] +programs.pet.settings.General.editor = "nvim"; diff --git a/modules/programs/pet.nix b/modules/programs/pet.nix index c1411b623..e75b10df3 100644 --- a/modules/programs/pet.nix +++ b/modules/programs/pet.nix @@ -80,16 +80,25 @@ in { }; config = mkIf cfg.enable { - programs.pet.settings = { - selectcmd = mkDefault "fzf"; - snippetfile = config.xdg.configHome + "/pet/snippet.toml"; - }; + programs.pet.settings = let + defaultGeneral = { + selectcmd = mkDefault "fzf"; + snippetfile = config.xdg.configHome + "/pet/snippet.toml"; + }; + in if versionAtLeast config.home.stateVersion "21.11" then { + General = defaultGeneral; + } else + defaultGeneral; home.packages = [ pkgs.pet cfg.selectcmdPackage ]; xdg.configFile = { - "pet/config.toml".source = - format.generate "config.toml" { General = cfg.settings; }; + "pet/config.toml".source = format.generate "config.toml" + (if versionAtLeast config.home.stateVersion "21.11" then + cfg.settings + else { + General = cfg.settings; + }); "pet/snippet.toml".source = format.generate "snippet.toml" { snippets = cfg.snippets; }; }; diff --git a/tests/modules/programs/pet/default.nix b/tests/modules/programs/pet/default.nix index 553b8392c..a9d811e0b 100644 --- a/tests/modules/programs/pet/default.nix +++ b/tests/modules/programs/pet/default.nix @@ -1 +1,5 @@ -{ pet-snippets = ./snippets.nix; } +{ + pet-snippets = ./snippets.nix; + pet-settings_21_05 = ./settings_21_05.nix; + pet-settings_21_11 = ./settings_21_11.nix; +} diff --git a/tests/modules/programs/pet/settings_21_05.nix b/tests/modules/programs/pet/settings_21_05.nix new file mode 100644 index 000000000..cf7285487 --- /dev/null +++ b/tests/modules/programs/pet/settings_21_05.nix @@ -0,0 +1,26 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + home.stateVersion = "21.05"; + programs.pet = { + enable = true; + selectcmdPackage = config.lib.test.mkStubPackage { }; + settings.editor = "nvim"; + }; + + test.stubs.pet = { }; + + nmt.script = '' + assertFileContent home-files/.config/pet/config.toml \ + ${ + builtins.toFile "pet-settings.toml" '' + [General] + editor = "nvim" + selectcmd = "fzf" + snippetfile = "/home/hm-user/.config/pet/snippet.toml" + '' + } + ''; +} diff --git a/tests/modules/programs/pet/settings_21_11.nix b/tests/modules/programs/pet/settings_21_11.nix new file mode 100644 index 000000000..0b82d1f37 --- /dev/null +++ b/tests/modules/programs/pet/settings_21_11.nix @@ -0,0 +1,42 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + home.stateVersion = "21.11"; + programs.pet = { + enable = true; + selectcmdPackage = config.lib.test.mkStubPackage { }; + settings = { + General = { + backend = "Gitlab"; + editor = "nvim"; + }; + Gitlab = { + access_token = "1234"; + file_name = "pet-snippets.toml"; + visibility = "public"; + }; + }; + }; + + test.stubs.pet = { }; + + nmt.script = '' + assertFileContent home-files/.config/pet/config.toml \ + ${ + builtins.toFile "pet-settings.toml" '' + [General] + backend = "Gitlab" + editor = "nvim" + selectcmd = "fzf" + snippetfile = "/home/hm-user/.config/pet/snippet.toml" + + [Gitlab] + access_token = "1234" + file_name = "pet-snippets.toml" + visibility = "public" + '' + } + ''; +}