fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , pkgs , lib , ...} : 2 3with lib ; 4 5let 6cfg = config . programs . hexchat ; 7 8channelOptions = with types ; 9submodule { 10options = { 11autoconnect = mkOption { 12type = nullOr bool ; 13default = false ; 14description = "Autoconnect to network." ; 15}; 16 17connectToSelectedServerOnly = mkOption { 18type = nullOr bool ; 19default = true ; 20description = "Connect to selected server only." ; 21}; 22 23bypassProxy = mkOption { 24type = nullOr bool ; 25default = true ; 26description = "Bypass proxy." ; 27}; 28 29forceSSL = mkOption { 30type = nullOr bool ; 31default = false ; 32description = "Use SSL for all servers." ; 33}; 34 35acceptInvalidSSLCertificates = mkOption { 36type = nullOr bool ; 37default = false ; 38description = "Accept invalid SSL certificates." ; 39}; 40 41useGlobalUserInformation = mkOption { 42type = nullOr bool ; 43default = false ; 44description = "Use global user information." ; 45}; 46}; 47}; 48 49modChannelOption = with types ; 50submodule { 51options = { 52autojoin = mkOption { 53type = listOf str ; 54default = [ ]; 55example = [ "#home-manager" "#linux" "#nix" ]; 56description = "Channels list to autojoin on connecting to server." ; 57}; 58 59charset = mkOption { 60type = nullOr str ; 61default = null ; 62example = "UTF-8 (Unicode)" ; 63description = "Character set." ; 64}; 65 66commands = mkOption { 67type = listOf str ; 68default = [ ]; 69example = literalExpression ''[ "ECHO Greetings fellow Nixer! ]'' ; 70description = "Commands to be executed on connecting to server." ; 71}; 72 73loginMethod = mkOption { 74type = nullOr ( enum ( attrNames loginMethodMap )); 75default = null ; 76description = '' 77The login method. The allowed options are: 78 79`null` 80: Default 81 82`"nickServMsg"` 83: NickServ (`/MSG NickServ` + password) 84 85`"nickServ"` 86: NickServ (`/NICKSERV` + password) 87 88`"challengeAuth"` 89: Challenge Auth (username + password) 90 91`"sasl"` 92: SASL (username + password) 93 94`"serverPassword"` 95: Server password (`/PASS` password) 96 97`"saslExternal"` 98: SASL EXTERNAL (cert) 99 100`"customCommands"` 101: Use "commands" field for auth. For example 102```nix 103commands = [ "/msg NickServ IDENTIFY my_password" ] 104``` 105'' ; 106}; 107 108nickname = mkOption { 109type = nullOr str ; 110default = null ; 111description = "Primary nickname." ; 112}; 113 114nickname2 = mkOption { 115type = nullOr str ; 116default = null ; 117description = "Secondary nickname." ; 118}; 119 120options = mkOption { 121type = nullOr channelOptions ; 122default = null ; 123example = { 124autoconnect = true ; 125useGlobalUserInformation = true ; 126}; 127description = "Channel options." ; 128}; 129 130password = mkOption { 131type = nullOr str ; 132default = null ; 133description = '' 134Password to use. Note this password will be readable by all user's 135in the Nix store. 136'' ; 137}; 138 139realName = mkOption { 140type = nullOr str ; 141default = null ; 142description = '' 143Real name. Is used to populate the real name field that appears when 144someone uses the `WHOIS` command on your nick. 145'' ; 146}; 147 148userName = mkOption { 149type = nullOr str ; 150default = null ; 151description = '' 152User name. Part of your `user@host` hostmask that 153appears to other on IRC. 154'' ; 155}; 156 157servers = mkOption { 158type = listOf str ; 159default = [ ]; 160example = [ "irc.oftc.net" ]; 161description = "IRC Server Address List." ; 162}; 163}; 164}; 165 166transformField = k :v :if ( v != null ) then " ${ k } = ${ v } " else null ; 167 168listChar = c :l : 169if l != [ ] then concatMapStringsSep "\n" ( transformField c ) l else null ; 170 171computeFieldsValue = channel : 172let 173ifTrue = p :n :if p then n else 0 ; 174result = with channel . options ; 175foldl' ( a :b :a + b ) 0 [ 176( ifTrue ( ! connectToSelectedServerOnly ) 1 ) 177( ifTrue useGlobalUserInformation 2 ) 178( ifTrue forceSSL 4 ) 179( ifTrue autoconnect 8 ) 180( ifTrue ( ! bypassProxy ) 16 ) 181( ifTrue acceptInvalidSSLCertificates 32 ) 182]; 183in toString ( if channel . options == null then 0 else result ); 184 185loginMethodMap = { 186nickServMsg = 1 ; 187nickServ = 2 ; 188challengeAuth = 4 ; 189sasl = 6 ; 190serverPassword = 7 ; 191customCommands = 9 ; 192saslExternal = 10 ; 193}; 194 195loginMethod = channel : 196transformField "L" ( optionalString ( channel . loginMethod != null ) 197( toString loginMethodMap .${ channel . loginMethod })); 198 199# Note: Missing option `D=`. 200transformChannel = channelName : 201let channel = cfg . channels .${ channelName }; 202in concatStringsSep "\n" ( remove null [ 203"" # leave a space between one server and another 204( transformField "N" channelName ) 205( loginMethod channel ) 206( transformField "E" channel . charset ) 207( transformField "F" ( computeFieldsValue channel )) 208( transformField "I" channel . nickname ) 209( transformField "i" channel . nickname2 ) 210( transformField "R" channel . realName ) 211( transformField "U" channel . userName ) 212( transformField "P" channel . password ) 213( listChar "S" channel . servers ) 214( listChar "J" channel . autojoin ) 215( listChar "C" channel . commands ) 216]); 217 218in { 219meta . maintainers = with maintainers ; [ thiagokokada ]; 220 221options . programs . hexchat = with types ; { 222enable = mkEnableOption "HexChat, a graphical IRC client" ; 223 224channels = mkOption { 225type = attrsOf modChannelOption ; 226default = { }; 227example = literalExpression '' 228{ 229oftc = { 230autojoin = [ 231"#home-manager" 232"#linux" 233]; 234charset = "UTF-8 (Unicode)"; 235commands = [ 236"ECHO Buzz Lightyear sent you a message: 'To Infinity... and Beyond!'" 237]; 238loginMethod = sasl; 239nickname = "my_nickname"; 240nickname2 = "my_secondchoice"; 241options = { 242acceptInvalidSSLCertificates = false; 243autoconnect = true; 244bypassProxy = true; 245connectToSelectedServerOnly = true; 246useGlobalUserInformation = false; 247forceSSL = false; 248}; 249password = "my_password"; 250realName = "my_realname"; 251servers = [ 252"irc.oftc.net" 253]; 254userName = "my_username"; 255}; 256}'' ; 257description = '' 258Configures {file}`$XDG_CONFIG_HOME/hexchat/servlist.conf`. 259'' ; 260}; 261 262settings = mkOption { 263default = null ; 264type = nullOr ( attrsOf str ); 265example = literalExpression '' 266{ 267irc_nick1 = "mynick"; 268irc_username = "bob"; 269irc_realname = "Bart Simpson"; 270text_font = "Monospace 14"; 271}; 272'' ; 273description = '' 274Configuration for {file}`$XDG_CONFIG_HOME/hexchat/hexchat.conf`, see 275<https://hexchat.readthedocs.io/en/latest/settings.html#list-of-settings> 276for supported values. 277'' ; 278}; 279 280overwriteConfigFiles = mkOption { 281type = nullOr bool ; 282default = false ; 283description = '' 284Enables overwriting HexChat configuration files 285({file}`hexchat.conf`, {file}`servlist.conf`). 286Any existing HexChat configuration will be lost. Make sure to back up 287any previous configuration before enabling this. 288 289Enabling this setting is recommended, because everytime HexChat 290application is closed it overwrites Nix/Home Manager provided 291configuration files, causing: 292 2931. Nix/Home Manager provided configuration to be out of sync with 294actual active HexChat configuration. 2952. Nix/Home Manager updates to be blocked until configuration files are 296manually removed. 297'' ; 298}; 299 300theme = mkOption { 301type = nullOr package ; 302default = null ; 303example = literalExpression '' 304source = pkgs.fetchzip { 305url = "https://dl.hexchat.net/themes/Monokai.hct#Monokai.zip"; 306sha256 = "sha256-WCdgEr8PwKSZvBMs0fN7E2gOjNM0c2DscZGSKSmdID0="; 307stripRoot = false; 308}; 309'' ; 310description = '' 311Theme package for HexChat. Expects a derivation containing decompressed 312theme files. Note, `.hct` files are actually ZIP files, 313as seen in example. 314'' ; 315}; 316}; 317 318config = mkIf cfg . enable { 319assertions = [ 320( hm . assertions . assertPlatform "programs.hexchat" pkgs platforms . linux ) 321]; 322 323home . packages = [ pkgs . hexchat ]; 324 325xdg . configFile . "hexchat" = mkIf ( cfg . theme != null ) { 326source = cfg . theme ; 327recursive = true ; 328}; 329 330xdg . configFile . "hexchat/hexchat.conf" = mkIf ( cfg . settings != null ) { 331force = cfg . overwriteConfigFiles ; 332text = concatMapStringsSep "\n" ( x :x + " = " + cfg . settings .${ x }) 333( attrNames cfg . settings ); 334}; 335 336xdg . configFile . "hexchat/servlist.conf" = mkIf ( cfg . channels != { }) { 337force = cfg . overwriteConfigFiles ; 338# Final line breaks is required to avoid cropping last field value. 339text = concatMapStringsSep "\n" transformChannel ( attrNames cfg . channels ) 340+ "\n\n" ; 341}; 342}; 343}