fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . programs . taskwarrior ; 8 9formatValue = value : 10if isBool value then 11if value then "true" else "false" 12else if isList value then 13concatMapStringsSep "," formatValue value 14else 15toString value ; 16 17formatLine = key :value :" ${ key } = ${ formatValue value } " ; 18 19formatSet = key :values : 20( concatStringsSep "\n" 21( mapAttrsToList ( subKey :subValue :formatPair " ${ key } . ${ subKey } " subValue ) 22values )); 23 24formatPair = key :value : 25if isAttrs value then formatSet key value else formatLine key value ; 26 27homeConf = " ${ config . xdg . configHome } /task/home-manager-taskrc" ; 28userConf = " ${ config . xdg . configHome } /task/taskrc" ; 29in { 30options = { 31programs . taskwarrior = { 32enable = mkEnableOption "Task Warrior" ; 33 34config = mkOption { 35type = types . attrsOf types . anything ; 36default = { }; 37example = literalExpression '' 38{ 39confirmation = false; 40report.minimal.filter = "status:pending"; 41report.active.columns = [ "id" "start" "entry.age" "priority" "project" "due" "description" ]; 42report.active.labels = [ "ID" "Started" "Age" "Priority" "Project" "Due" "Description" ]; 43taskd = { 44certificate = "/path/to/cert"; 45key = "/path/to/key"; 46ca = "/path/to/ca"; 47server = "host.domain:53589"; 48credentials = "Org/First Last/cf31f287-ee9e-43a8-843e-e8bbd5de4294"; 49}; 50} 51'' ; 52description = '' 53Key-value configuration written to 54{file}`$XDG_CONFIG_HOME/task/taskrc`. 55'' ; 56}; 57 58dataLocation = mkOption { 59type = types . str ; 60default = " ${ config . xdg . dataHome } /task" ; 61defaultText = "$XDG_DATA_HOME/task" ; 62description = '' 63Location where Task Warrior will store its data. 64 65Home Manager will attempt to create this directory. 66'' ; 67}; 68 69colorTheme = mkOption { 70type = with types ; nullOr ( either str path ); 71default = null ; 72example = "dark-blue-256" ; 73description = '' 74Either one of the default provided theme as string, or a 75path to a theme configuration file. 76'' ; 77}; 78 79extraConfig = mkOption { 80type = types . lines ; 81default = "" ; 82description = '' 83Additional content written at the end of 84{file}`$XDG_CONFIG_HOME/task/taskrc`. 85'' ; 86}; 87 88package = mkPackageOption pkgs "taskwarrior" { }; 89}; 90}; 91 92config = mkIf cfg . enable { 93home . packages = [ cfg . package ]; 94 95home . file . " ${ homeConf } " . text = '' 96data.location= ${ cfg . dataLocation } 97${ optionalString ( cfg . colorTheme != null ) ( if isString cfg . colorTheme then 98"include ${ cfg . colorTheme } .theme" 99else 100"include ${ cfg . colorTheme } " )} 101 102${ concatStringsSep "\n" ( mapAttrsToList formatPair cfg . config )} 103 104${ cfg . extraConfig } 105'' ; 106 107home . activation . regenDotTaskRc = hm . dag . entryAfter [ "writeBoundary" ] '' 108$VERBOSE_ECHO "Ensuring generated taskwarrior config included in taskrc" 109 110if [[ ! -s " ${ userConf } " ]]; then 111# Ensure file's existence 112if [[ -v DRY_RUN ]]; then 113$DRY_RUN_CMD echo "include ${ homeConf } " ">" " ${ userConf } " 114else 115echo "include ${ homeConf } " > " ${ userConf } " 116fi 117elif ! grep -qF "include ${ homeConf } " ${ escapeShellArg userConf } ; then 118# Add include statement for Home Manager generated config. 119$DRY_RUN_CMD sed -i '1i include ${ homeConf } ' ${ escapeShellArg userConf } 120fi 121'' ; 122}; 123}