From 3142bdcc470e1e291e1fbe942fd69e06bd00c5df Mon Sep 17 00:00:00 2001 From: Shaw Vrana Date: Wed, 27 Mar 2024 16:03:27 -0700 Subject: [PATCH] readline: optionally place config file in XDG dir Based on PR #4189 --- modules/home-environment.nix | 6 ++++ modules/programs/readline.nix | 14 ++++++++-- tests/modules/programs/readline/default.nix | 5 +++- .../programs/readline/prefer-xdg-dirs.nix | 28 +++++++++++++++++++ 4 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 tests/modules/programs/readline/prefer-xdg-dirs.nix diff --git a/modules/home-environment.nix b/modules/home-environment.nix index 1728fa45..b3f6d6e2 100644 --- a/modules/home-environment.nix +++ b/modules/home-environment.nix @@ -473,6 +473,12 @@ in will be printed when the user configuration is being built. ''; }; + + home.preferXdgDirectories = mkEnableOption "" // { + description = '' + Whether to make programs use XDG directories whenever supported. + ''; +}; }; config = { diff --git a/modules/programs/readline.nix b/modules/programs/readline.nix index b8739e37..56e8ea98 100644 --- a/modules/programs/readline.nix +++ b/modules/programs/readline.nix @@ -68,8 +68,8 @@ in { }; }; - config = mkIf cfg.enable { - home.file.".inputrc".text = let + config = mkIf cfg.enable (let + finalConfig = let configStr = concatStringsSep "\n" (optional cfg.includeSystemConfig "$include /etc/inputrc" ++ mapAttrsToList mkSetVariableStr cfg.variables @@ -80,5 +80,13 @@ in { ${configStr} ${cfg.extraConfig} ''; - }; + in mkMerge [ + (mkIf (!config.home.preferXdgDirectories) { + home.file.".inputrc".text = finalConfig; + }) + (mkIf config.home.preferXdgDirectories { + xdg.configFile.inputrc.text = finalConfig; + home.sessionVariables.INPUTRC = "${config.xdg.configHome}/inputrc"; + }) + ]); } diff --git a/tests/modules/programs/readline/default.nix b/tests/modules/programs/readline/default.nix index c95745d1..614b4ce9 100644 --- a/tests/modules/programs/readline/default.nix +++ b/tests/modules/programs/readline/default.nix @@ -1 +1,4 @@ -{ readline-using-all-options = ./using-all-options.nix; } +{ + readline-using-all-options = ./using-all-options.nix; + readline-prefer-xdg-dirs = ./prefer-xdg-dirs.nix; +} diff --git a/tests/modules/programs/readline/prefer-xdg-dirs.nix b/tests/modules/programs/readline/prefer-xdg-dirs.nix new file mode 100644 index 00000000..869b8a2c --- /dev/null +++ b/tests/modules/programs/readline/prefer-xdg-dirs.nix @@ -0,0 +1,28 @@ +{ ... }: + +{ + home.preferXdgDirectories = true; + + programs.readline = { + enable = true; + variables.bell-style = "audible"; + }; + + nmt.script = '' + assertFileContent \ + home-files/.config/inputrc \ + ${ + builtins.toFile "readline-expected" '' + # Generated by Home Manager. + + $include /etc/inputrc + set bell-style audible + + '' + } + + assertFileContains \ + home-path/etc/profile.d/hm-session-vars.sh \ + 'export INPUTRC="/home/hm-user/.config/inputrc"' + ''; +}