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 . irssi ; 8 9quoteStr = s :escape [ ''"'' ] s ; 10 11# Comma followed by newline. 12cnl = '' 13, 14'' ; 15 16assignFormat = set : 17concatStringsSep "\n" 18( mapAttrsToList ( k :v :" ${ k } = \" ${ quoteStr v } \";" ) set ); 19 20chatnetString = concatStringsSep "\n" ( flip mapAttrsToList cfg . networks 21( k :v :'' 22${ k } = { 23type = " ${ v . type } "; 24nick = " ${ quoteStr v . nick } "; 25autosendcmd = " ${ concatMapStringsSep ";" quoteStr v . autoCommands } "; 26${ 27lib . optionalString ( v . saslExternal ) '' 28sasl_username = " ${ quoteStr v . nick } "; 29sasl_mechanism = "EXTERNAL";'' 30} 31}; 32'' )); 33 34serversString = concatStringsSep cnl ( flip mapAttrsToList cfg . networks 35( k :v :'' 36{ 37chatnet = " ${ k } "; 38address = " ${ v . server . address } "; 39port = " ${ toString v . server . port } "; 40use_ssl = " ${ lib . hm . booleans . yesNo v . server . ssl . enable } "; 41ssl_verify = " ${ lib . hm . booleans . yesNo v . server . ssl . verify } "; 42autoconnect = " ${ lib . hm . booleans . yesNo v . server . autoConnect } "; 43${ 44optionalString ( v . server . ssl . certificateFile != null ) '' 45ssl_cert = " ${ v . server . ssl . certificateFile } "; 46'' 47} 48} 49'' )); 50 51channelString = concatStringsSep cnl ( concatLists 52( flip mapAttrsToList cfg . networks ( k :v : 53( flip mapAttrsToList v . channels ( c :cv :'' 54{ 55chatnet = " ${ k } "; 56name = " ${ c } "; 57autojoin = " ${ lib . hm . booleans . yesNo cv . autoJoin } "; 58} 59'' ))))); 60 61channelType = types . submodule { 62options = { 63name = mkOption { 64type = types . nullOr types . str ; 65visible = false ; 66default = null ; 67description = "Name of the channel." ; 68}; 69 70autoJoin = mkOption { 71type = types . bool ; 72default = false ; 73description = "Whether to join this channel on connect." ; 74}; 75}; 76}; 77 78networkType = types . submodule ({ name , ...} :{ 79options = { 80name = mkOption { 81visible = false ; 82default = name ; 83type = types . str ; 84}; 85 86nick = mkOption { 87type = types . str ; 88description = "Nickname in that network." ; 89}; 90 91type = mkOption { 92type = types . str ; 93description = "Type of the network." ; 94default = "IRC" ; 95}; 96 97autoCommands = mkOption { 98type = types . listOf types . str ; 99default = [ ]; 100description = "List of commands to execute on connect." ; 101}; 102 103server = { 104address = mkOption { 105type = types . str ; 106description = "Address of the chat server." ; 107}; 108 109port = mkOption { 110type = types . port ; 111default = 6667 ; 112description = "Port of the chat server." ; 113}; 114 115ssl = { 116enable = mkOption { 117type = types . bool ; 118default = true ; 119description = "Whether SSL should be used." ; 120}; 121 122verify = mkOption { 123type = types . bool ; 124default = true ; 125description = "Whether the SSL certificate should be verified." ; 126}; 127 128certificateFile = mkOption { 129type = types . nullOr types . path ; 130default = null ; 131description = '' 132Path to a file containing the certificate used for 133client authentication to the server. 134'' ; 135}; 136}; 137 138autoConnect = mkOption { 139type = types . bool ; 140default = false ; 141description = "Whether Irssi connects to the server on launch." ; 142}; 143}; 144 145channels = mkOption { 146description = "Channels for the given network." ; 147type = types . attrsOf channelType ; 148default = { }; 149}; 150 151saslExternal = mkOption { 152type = types . bool ; 153default = false ; 154description = '' 155Enable SASL external authentication. This requires setting a path in 156[](#opt-programs.irssi.networks._name_.server.ssl.certificateFile). 157'' ; 158}; 159}; 160}); 161 162in { 163 164options = { 165programs . irssi = { 166enable = mkEnableOption "the Irssi chat client" ; 167 168extraConfig = mkOption { 169default = "" ; 170description = "These lines are appended to the Irssi configuration." ; 171type = types . lines ; 172}; 173 174aliases = mkOption { 175default = { }; 176example = { 177J = "join" ; 178BYE = "quit" ; 179}; 180description = "An attribute set that maps aliases to commands." ; 181type = types . attrsOf types . str ; 182}; 183 184networks = mkOption { 185default = { }; 186example = literalExpression '' 187{ 188liberachat = { 189nick = "hmuser"; 190server = { 191address = "irc.libera.chat"; 192port = 6697; 193autoConnect = true; 194}; 195channels = { 196nixos.autoJoin = true; 197}; 198}; 199} 200'' ; 201description = "An attribute set of chat networks." ; 202type = types . attrsOf networkType ; 203}; 204}; 205}; 206 207config = mkIf cfg . enable { 208home . packages = [ pkgs . irssi ]; 209 210home . file . ".irssi/config" . text = '' 211settings = { 212core = { 213settings_autosave = "no"; 214}; 215}; 216 217aliases = { 218${ assignFormat cfg . aliases } 219}; 220 221chatnets = { 222${ chatnetString } 223}; 224 225servers = ( 226${ serversString } 227); 228 229channels = ( 230${ channelString } 231); 232 233${ cfg . extraConfig } 234'' ; 235}; 236}