From df931a59a5864d6ff0c5d83598135816f8593647 Mon Sep 17 00:00:00 2001 From: oxalica Date: Wed, 24 Nov 2021 10:33:03 +0800 Subject: [PATCH] taskwarrior: change config file location and use relative theme paths (#2455) After taskwarrior 2.6.0, its default config file now locates at `$XDG_CONFIG_HOME/task/taskrc`, and builtin themes can be included via relative paths. --- docs/release-notes/rl-2111.adoc | 4 ++ modules/misc/news.nix | 9 +++++ modules/programs/taskwarrior.nix | 21 ++++------ tests/default.nix | 1 + .../modules/programs/taskwarrior/default.nix | 1 + .../programs/taskwarrior/taskwarrior.nix | 40 +++++++++++++++++++ 6 files changed, 62 insertions(+), 14 deletions(-) create mode 100644 tests/modules/programs/taskwarrior/default.nix create mode 100644 tests/modules/programs/taskwarrior/taskwarrior.nix diff --git a/docs/release-notes/rl-2111.adoc b/docs/release-notes/rl-2111.adoc index 0db9e9010..fdd1220c1 100644 --- a/docs/release-notes/rl-2111.adoc +++ b/docs/release-notes/rl-2111.adoc @@ -37,6 +37,10 @@ https://github.com/nix-community/home-manager/issues/1906[issue #1906]. + You can replicate your old configuration by moving those options to <>. Keep in mind that the syntax is different so you may need to do some changes. +* Taskwarrior version 2.6.0 respects XDG Specification for the config file now. +Option <> and friends now generate the config file at +`$XDG_CONFIG_HOME/task/taskrc` instead of `~/.taskrc`. + [[sec-release-21.11-state-version-changes]] === State Version Changes diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 09e6a2352..5c78dec34 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -2241,6 +2241,15 @@ in A new module is available: 'wayland.windowManager.sway.swaynag'. ''; } + + { + time = "2021-11-23T20:26:37+00:00"; + message = '' + Taskwarrior version 2.6.0 respects XDG Specification for the config file now. + Option 'opt-programs.taskwarrior.config' and friends now generate the config file at + '$XDG_CONFIG_HOME/task/taskrc' instead of '~/.taskrc'. + ''; + } ]; }; } diff --git a/modules/programs/taskwarrior.nix b/modules/programs/taskwarrior.nix index f0f5f1e92..441313252 100644 --- a/modules/programs/taskwarrior.nix +++ b/modules/programs/taskwarrior.nix @@ -6,16 +6,6 @@ let cfg = config.programs.taskwarrior; - themePath = theme: "${pkgs.taskwarrior}/share/doc/task/rc/${theme}.theme"; - - includeTheme = location: - if location == null then - "" - else if isString location then - "include ${themePath location}" - else - "include ${location}"; - formatValue = value: if isBool value then if value then "true" else "false" @@ -59,7 +49,7 @@ in { ''; description = '' Key-value configuration written to - ~/.taskrc. + $XDG_CONFIG_HOME/task/taskrc. ''; }; @@ -89,7 +79,7 @@ in { default = ""; description = '' Additional content written at the end of - ~/.taskrc. + $XDG_CONFIG_HOME/task/taskrc. ''; }; }; @@ -98,9 +88,12 @@ in { config = mkIf cfg.enable { home.packages = [ pkgs.taskwarrior ]; - home.file.".taskrc".text = '' + xdg.configFile."task/taskrc".text = '' data.location=${cfg.dataLocation} - ${includeTheme cfg.colorTheme} + ${optionalString (cfg.colorTheme != null) (if isString cfg.colorTheme then + "include ${cfg.colorTheme}.theme" + else + "include ${cfg.colorTheme}")} ${concatStringsSep "\n" (mapAttrsToList formatPair cfg.config)} diff --git a/tests/default.nix b/tests/default.nix index 63b062c73..2b760dab7 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -87,6 +87,7 @@ import nmt { ./modules/programs/sm64ex ./modules/programs/ssh ./modules/programs/starship + ./modules/programs/taskwarrior ./modules/programs/texlive ./modules/programs/tmux ./modules/programs/topgrade diff --git a/tests/modules/programs/taskwarrior/default.nix b/tests/modules/programs/taskwarrior/default.nix new file mode 100644 index 000000000..52377b75a --- /dev/null +++ b/tests/modules/programs/taskwarrior/default.nix @@ -0,0 +1 @@ +{ taskwarrior = ./taskwarrior.nix; } diff --git a/tests/modules/programs/taskwarrior/taskwarrior.nix b/tests/modules/programs/taskwarrior/taskwarrior.nix new file mode 100644 index 000000000..98d0a3544 --- /dev/null +++ b/tests/modules/programs/taskwarrior/taskwarrior.nix @@ -0,0 +1,40 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + programs.taskwarrior = { + enable = true; + colorTheme = "dark-violets-256"; + dataLocation = "/some/data/location"; + config = { + urgency.user.tag.next.coefficient = 42.42; + urgency.blocked.coefficient = -42; + }; + extraConfig = '' + include /my/stuff + urgency.user.tag.test.coefficient=-42.42 + ''; + }; + + test.stubs.taskwarrior = { }; + + nmt.script = '' + assertFileExists home-files/.config/task/taskrc + assertFileContent home-files/.config/task/taskrc ${ + pkgs.writeText "taskwarrior.expected" '' + data.location=/some/data/location + include dark-violets-256.theme + + urgency.blocked.coefficient=-42 + urgency.user.tag.next.coefficient=42.420000 + + include /my/stuff + urgency.user.tag.test.coefficient=-42.42 + + '' + } + ''; + }; +}