-
-
Save superherointj/df7157c22d5d9472217eb485519cffa9 to your computer and use it in GitHub Desktop.
HexChat Nixfmt comparison
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ config, pkgs, lib, ... }: | |
with builtins; | |
with lib; | |
let | |
cfg = config.programs.hexchat; | |
in | |
{ | |
meta.maintainers = [ maintainers.superherointj ]; | |
options.programs.hexchat = { | |
channels = | |
with lib.types; | |
let modChannelOption = submodule { | |
options = { | |
options = | |
let channelOptions = submodule { | |
options = { | |
autoconnect = mkOption { | |
type = nullOr bool; | |
description = "Autoconnect to network"; | |
default = false; | |
}; | |
connect_to_selected_server_only = mkOption { | |
type = nullOr bool; | |
description = "Connect to selected server only"; | |
default = true; | |
}; | |
bypass_proxy = mkOption { | |
type = nullOr bool; | |
description = "Bypass proxy"; | |
default = true; | |
}; | |
use_ssl_for_all_servers = mkOption { | |
type = nullOr bool; | |
description = "Use SSL for all servers"; | |
default = false; | |
}; | |
accept_invalid_ssl_certificates = mkOption { | |
type = nullOr bool; | |
description = "Accept invalid SSL certificates"; | |
default = false; | |
}; | |
use_global_user_information = mkOption { | |
type = nullOr bool; | |
description = "Use global user information"; | |
default = false; | |
}; | |
}; | |
}; in | |
mkOption { | |
type = nullOr (channelOptions); | |
default = null; | |
description = ""; | |
example = ""; | |
}; | |
nickname = mkOption { | |
type = str; | |
description = "Primary nickname"; | |
defaultText = "nickname1"; | |
}; | |
nickname2 = mkOption { | |
type = str; | |
description = "Secondary nickname"; | |
defaultText = "nickname2"; | |
}; | |
real_name = mkOption { | |
type = str; | |
description = "Real name"; | |
defaultText = ""; | |
}; | |
user_name = mkOption { | |
type = str; | |
description = "User name"; | |
defaultText = "username"; | |
}; | |
password = mkOption { | |
type = str; | |
description = "Password"; | |
defaultText = ""; | |
}; | |
charset = mkOption { | |
type = str; | |
description = "Charset"; | |
defaultText = "UTF-8 (Unicode)"; | |
example = "UTF-8 (Unicode)"; | |
}; | |
servers = mkOption { | |
type = (listOf str); | |
description = "IRC Server Address List"; | |
example = ''[ "chat.channel_name.net" "irc.channel_name.net" ]''; | |
default = [ ]; | |
}; | |
autojoin = mkOption { | |
type = nullOr (listOf str); | |
description = "Channels list to autojoin on connecting to server."; | |
example = ''[ "##linux" "#nix" ]''; | |
default = [ ]; | |
}; | |
commands = mkOption { | |
type = nullOr (listOf str); | |
description = "Commands to be executed on connecting to server."; | |
example = ''[ "ECHO Greetings fellow Nixer! ]''; | |
default = [ ]; | |
}; | |
login_method = mkOption { | |
type = with lib.types; nullOr int; | |
description = | |
''null => Default | |
1 => NickServ (/MSG NickServ + password) | |
2 => NickServ (/NICKSERV + password) | |
4 => Challenge Auth (username + password) | |
6 => SASL (username + password) | |
7 => Server password (/PASS password) | |
10 => SASL EXTERNAL (cert) | |
9 => Custom... (connect commands) | |
''; | |
default = null; | |
}; | |
}; | |
}; | |
in | |
mkOption { | |
type = nullOr (attrsOf modChannelOption); | |
default = null; | |
description = "Configures '~/.config/hexchat/servlist.conf'"; | |
example = | |
''{ | |
freenode = { | |
autojoin = [ | |
"#home-manager" | |
"##linux" | |
"#nixos" | |
]; | |
charset = "UTF-8 (Unicode)"; | |
commands = [ | |
"ECHO Buzz Lightyear sent you a message: 'To Infinity... and Beyond!'" | |
]; | |
login_method = 6; | |
nickname = "my_nickname"; | |
nickname2 = "my_secondchoice"; | |
options = { | |
accept_invalid_ssl_certificates = false; | |
autoconnect = true; | |
bypass_proxy = true; | |
connect_to_selected_server_only = true; | |
use_global_user_information = false; | |
use_ssl_for_all_servers = false; | |
}; | |
password = "my_password"; | |
real_name = "my_realname"; | |
servers = [ | |
"chat.freenode.net" | |
"irc.freenode.net" | |
]; | |
user_name = "my_username"; | |
}; | |
}''; | |
}; | |
conf = mkOption { | |
default = null; | |
description = "Configures '~/.config/hexchat/hexchat.conf'"; | |
example = | |
''{ | |
irc_nick1 = "mynick"; | |
irc_username = "bob"; | |
irc_realname = "Bart Simpson"; | |
text_font = "Monospace 14"; | |
};''; | |
type = with lib.types; nullOr (attrsOf str); | |
}; | |
enable = mkEnableOption "HexChat - Graphical IRC client"; | |
theme = mkOption { | |
default = null; | |
description = "Theme package for HexChat."; | |
# example = ""; # To-Do: Update here with a valid theme. | |
type = with lib.types; nullOr package; | |
}; | |
}; | |
config = lib.mkIf cfg.enable { | |
home.packages = [ pkgs.hexchat ]; | |
xdg.configFile."hexchat" = | |
lib.mkIf (cfg.theme != null) | |
{ | |
source = cfg.theme.out; | |
recursive = true; | |
}; | |
xdg.configFile."hexchat/hexchat.conf" = | |
lib.mkIf (cfg.conf != null) | |
{ | |
force = true; | |
text = | |
let hexchatConf = cfg.conf; in | |
concatMapStringsSep "\n" (x: x + " = " + hexchatConf.${x}) (attrNames hexchatConf); | |
}; | |
xdg.configFile."hexchat/servlist.conf" = | |
lib.mkIf (cfg.channels != null) | |
(if attrNames cfg.channels == [ ] then { text = ""; } else | |
{ | |
force = true; | |
text = | |
let tr_channel = (channel_name: | |
let | |
channel = cfg.channels.${channel_name}; | |
listChar = (c: l: (concatMapStrings (item: "\n${c}=${item}") l)); | |
in | |
let | |
name = "\nN=" + channel_name; | |
nickname = "\nI=" + channel.nickname; | |
nickname2 = "\ni=" + channel.nickname2; | |
real_name = "\nR=" + channel.real_name; | |
user_name = "\nU=" + channel.user_name; | |
password = "\nP=" + channel.password; | |
charset = "\nE=" + channel.charset; | |
login_method = "\nL=" + toString channel.login_method; | |
servers = listChar "S" channel.servers; | |
autojoin = listChar "J" channel.autojoin; | |
commands = listChar "C" channel.commands; | |
options = with channel.options; ("\nF=" + toString | |
(if channel.options == null then 0 else | |
( | |
(if autoconnect then 8 else 0) + | |
(if !connect_to_selected_server_only then 1 else 0) + | |
(if !bypass_proxy then 16 else 0) + | |
(if use_ssl_for_all_servers then 4 else 0) + | |
(if accept_invalid_ssl_certificates then 32 else 0) + | |
(if use_global_user_information then 2 else 0) | |
))); | |
# Note: Missing option `D=`. | |
in | |
name + login_method + charset + options + | |
# Note: Position for `D=`. | |
nickname + nickname2 + real_name + user_name + password + | |
servers + autojoin + commands | |
); | |
in | |
let channels = concatMapStringsSep "\n" tr_channel (attrNames cfg.channels); | |
in | |
"v=2.14.3\n" + channels + "\n\n"; | |
}); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment