diff --git a/modules/programs/helix.nix b/modules/programs/helix.nix index 86a17a353..1bd3eb8ec 100644 --- a/modules/programs/helix.nix +++ b/modules/programs/helix.nix @@ -229,24 +229,31 @@ in xdg.configFile = let - settings = { - "helix/config.toml" = mkIf (cfg.settings != { }) { - source = - let - configFile = tomlFormat.generate "config.toml" cfg.settings; - extraConfigFile = pkgs.writeText "extra-config.toml" ("\n" + cfg.extraConfig); - in - pkgs.runCommand "helix-config.toml" { } '' - cat ${configFile} ${extraConfigFile} >> $out - ''; + settings = + let + hasSettings = cfg.settings != { }; + hasExtraConfig = cfg.extraConfig != null; + in + { + "helix/config.toml" = mkIf (hasSettings || hasExtraConfig) { + source = + let + configFile = tomlFormat.generate "config.toml" cfg.settings; + extraConfigFile = pkgs.writeText "extra-config.toml" ( + lib.optionalString hasSettings "\n" + cfg.extraConfig + ); + in + pkgs.runCommand "helix-config.toml" { } '' + cat ${configFile} ${extraConfigFile} >> $out + ''; + }; + "helix/languages.toml" = mkIf (cfg.languages != { }) { + source = tomlFormat.generate "helix-languages-config" cfg.languages; + }; + "helix/ignore" = mkIf (cfg.ignores != [ ]) { + text = lib.concatStringsSep "\n" cfg.ignores + "\n"; + }; }; - "helix/languages.toml" = mkIf (cfg.languages != { }) { - source = tomlFormat.generate "helix-languages-config" cfg.languages; - }; - "helix/ignore" = mkIf (cfg.ignores != [ ]) { - text = lib.concatStringsSep "\n" cfg.ignores + "\n"; - }; - }; themes = lib.mapAttrs' ( n: v: diff --git a/tests/modules/programs/helix/default.nix b/tests/modules/programs/helix/default.nix index 77172c708..9838207e2 100644 --- a/tests/modules/programs/helix/default.nix +++ b/tests/modules/programs/helix/default.nix @@ -1 +1,4 @@ -{ helix-example-settings = ./example-settings.nix; } +{ + helix-example-settings = ./example-settings.nix; + helix-only-extraconfig = ./only-extraconfig.nix; +} diff --git a/tests/modules/programs/helix/only-extraconfig-expected.toml b/tests/modules/programs/helix/only-extraconfig-expected.toml new file mode 100644 index 000000000..9a653ba34 --- /dev/null +++ b/tests/modules/programs/helix/only-extraconfig-expected.toml @@ -0,0 +1,2 @@ +[editor] +auto-pairs = false diff --git a/tests/modules/programs/helix/only-extraconfig.nix b/tests/modules/programs/helix/only-extraconfig.nix new file mode 100644 index 000000000..c2d3231cb --- /dev/null +++ b/tests/modules/programs/helix/only-extraconfig.nix @@ -0,0 +1,16 @@ +{ config, ... }: +{ + programs.helix = { + enable = true; + extraConfig = '' + [editor] + auto-pairs = false + ''; + }; + + nmt.script = '' + assertFileContent \ + home-files/.config/helix/config.toml \ + ${./only-extraconfig-expected.toml} + ''; +}