treewide: remove with lib (#6735)

Continuation of `with lib;` cleanup.
This commit is contained in:
Austin Horstman 2025-03-31 22:32:16 -05:00 committed by GitHub
parent ccd7df836e
commit 0b491b460f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
200 changed files with 2421 additions and 2817 deletions

View file

@ -1,37 +1,34 @@
{ config, lib, pkgs, ... }:
with lib;
let
inherit (lib) mkOption types;
cfg = config.programs.taskwarrior;
formatValue = value:
if isBool value then
if lib.isBool value then
if value then "true" else "false"
else if isList value then
concatMapStringsSep "," formatValue value
else if lib.isList value then
lib.concatMapStringsSep "," formatValue value
else
toString value;
formatLine = key: value: "${key}=${formatValue value}";
formatSet = key: values:
(concatStringsSep "\n"
(mapAttrsToList (subKey: subValue: formatPair "${key}.${subKey}" subValue)
values));
(lib.concatStringsSep "\n" (lib.mapAttrsToList
(subKey: subValue: formatPair "${key}.${subKey}" subValue) values));
formatPair = key: value:
if isAttrs value then formatSet key value else formatLine key value;
if lib.isAttrs value then formatSet key value else formatLine key value;
in {
options = {
programs.taskwarrior = {
enable = mkEnableOption "Task Warrior";
enable = lib.mkEnableOption "Task Warrior";
config = mkOption {
type = types.attrsOf types.anything;
default = { };
example = literalExpression ''
example = lib.literalExpression ''
{
confirmation = false;
report.minimal.filter = "status:pending";
@ -82,7 +79,7 @@ in {
'';
};
package = mkPackageOption pkgs "taskwarrior" {
package = lib.mkPackageOption pkgs "taskwarrior" {
nullable = true;
example = "pkgs.taskwarrior3";
};
@ -92,35 +89,39 @@ in {
config = let
homeConf = "${config.xdg.configHome}/task/home-manager-taskrc";
userConf = "${config.xdg.configHome}/task/taskrc";
in mkIf cfg.enable {
in lib.mkIf cfg.enable {
home.packages = lib.mkIf (cfg.package != null) [ cfg.package ];
home.file."${homeConf}".text = ''
data.location=${cfg.dataLocation}
${optionalString (cfg.colorTheme != null) (if isString cfg.colorTheme then
${lib.optionalString (cfg.colorTheme != null)
(if lib.isString cfg.colorTheme then
"include ${cfg.colorTheme}.theme"
else
"include ${cfg.colorTheme}")}
${concatStringsSep "\n" (mapAttrsToList formatPair cfg.config)}
${lib.concatStringsSep "\n" (lib.mapAttrsToList formatPair cfg.config)}
${cfg.extraConfig}
'';
home.activation.regenDotTaskRc = hm.dag.entryAfter [ "writeBoundary" ] ''
verboseEcho "Ensuring generated taskwarrior config included in taskrc"
home.activation.regenDotTaskRc =
lib.hm.dag.entryAfter [ "writeBoundary" ] ''
verboseEcho "Ensuring generated taskwarrior config included in taskrc"
if [[ ! -s "${userConf}" ]]; then
# Ensure file's existence
if [[ -v DRY_RUN ]]; then
run echo "include ${homeConf}" ">" "${userConf}"
else
echo "include ${homeConf}" > "${userConf}"
if [[ ! -s "${userConf}" ]]; then
# Ensure file's existence
if [[ -v DRY_RUN ]]; then
run echo "include ${homeConf}" ">" "${userConf}"
else
echo "include ${homeConf}" > "${userConf}"
fi
elif ! grep -qF "include ${homeConf}" ${
lib.escapeShellArg userConf
}; then
# Add include statement for Home Manager generated config.
run sed -i '1i include ${homeConf}' ${lib.escapeShellArg userConf}
fi
elif ! grep -qF "include ${homeConf}" ${escapeShellArg userConf}; then
# Add include statement for Home Manager generated config.
run sed -i '1i include ${homeConf}' ${escapeShellArg userConf}
fi
'';
'';
};
}