fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ pkgs , config , lib , ...} : 2let 3inherit ( lib ) 4mkOption mkEnableOption mkIf maintainers literalExpression types platforms 5mkRemovedOptionModule versionAtLeast ; 6 7inherit ( lib . hm . assertions ) assertPlatform ; 8 9cfg = config . services . espanso ; 10espansoVersion = cfg . package . version ; 11 12yaml = pkgs . formats . yaml { }; 13in { 14imports = [ 15( mkRemovedOptionModule [ "services" "espanso" "settings" ] 16"Use services.espanso.configs and services.espanso.matches instead." ) 17]; 18meta . maintainers = [ 19maintainers . lucasew 20maintainers . bobvanderlinden 21lib . hm . maintainers . liyangau 22]; 23options = { 24services . espanso = { 25enable = mkEnableOption "Espanso: cross platform text expander in Rust" ; 26 27package = mkOption { 28type = types . package ; 29description = "Which espanso package to use" ; 30default = pkgs . espanso ; 31defaultText = literalExpression "pkgs.espanso" ; 32}; 33 34configs = mkOption { 35type = yaml . type ; 36default = { default = { }; }; 37example = literalExpression '' 38{ 39default = { 40show_notifications = false; 41}; 42vscode = { 43filter_title = "Visual Studio Code$"; 44backend = "Clipboard"; 45}; 46}; 47'' ; 48description = '' 49The Espanso configuration to use. See 50<https://espanso.org/docs/configuration/basics/> 51for a description of available options. 52'' ; 53}; 54 55matches = mkOption { 56type = yaml . type ; 57default = { default . matches = [ ]; }; 58example = literalExpression '' 59{ 60base = { 61matches = [ 62{ 63trigger = ":now"; 64replace = "It's {{currentdate}} {{currenttime}}"; 65} 66{ 67trigger = ":hello"; 68replace = "line1\nline2"; 69} 70{ 71regex = ":hi(?P<person>.*)\\."; 72replace = "Hi {{person}}!"; 73} 74]; 75}; 76global_vars = { 77global_vars = [ 78{ 79name = "currentdate"; 80type = "date"; 81params = {format = "%d/%m/%Y";}; 82} 83{ 84name = "currenttime"; 85type = "date"; 86params = {format = "%R";}; 87} 88]; 89}; 90}; 91'' ; 92description = '' 93The Espanso matches to use. See 94<https://espanso.org/docs/matches/basics/> 95for a description of available options. 96'' ; 97}; 98}; 99}; 100 101config = mkIf cfg . enable { 102assertions = [ 103( assertPlatform "services.espanso" pkgs platforms . linux ) 104{ 105assertion = versionAtLeast espansoVersion "2" ; 106message = '' 107The services.espanso module only supports Espanso version 2 or later. 108'' ; 109} 110]; 111 112home . packages = [ cfg . package ]; 113 114xdg . configFile = let 115configFiles = lib . mapAttrs' ( name :value :{ 116name = "espanso/config/ ${ name } .yml" ; 117value = { source = yaml . generate " ${ name } .yml" value ; }; 118}) cfg . configs ; 119matchesFiles = lib . mapAttrs' ( name :value :{ 120name = "espanso/match/ ${ name } .yml" ; 121value = { source = yaml . generate " ${ name } .yml" value ; }; 122}) cfg . matches ; 123in configFiles // matchesFiles ; 124 125systemd . user . services . espanso = { 126Unit = { Description = "Espanso: cross platform text expander in Rust" ; }; 127Service = { 128Type = "exec" ; 129ExecStart = " ${ cfg . package } /bin/espanso daemon" ; 130Restart = "on-failure" ; 131}; 132Install = { WantedBy = [ "default.target" ]; }; 133}; 134}; 135}