2019-01-24 13:00:11 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.irssi;
|
|
|
|
|
2021-10-31 10:32:58 +01:00
|
|
|
quoteStr = s: escape [ ''"'' ] s;
|
2019-01-24 13:00:11 +01:00
|
|
|
|
2021-10-31 10:32:58 +01:00
|
|
|
# Comma followed by newline.
|
|
|
|
cnl = ''
|
|
|
|
,
|
|
|
|
'';
|
2019-01-24 13:00:11 +01:00
|
|
|
|
2021-10-31 10:32:58 +01:00
|
|
|
assignFormat = set:
|
2019-01-24 13:00:11 +01:00
|
|
|
concatStringsSep "\n"
|
2021-10-31 10:32:58 +01:00
|
|
|
(mapAttrsToList (k: v: " ${k} = \"${quoteStr v}\";") set);
|
|
|
|
|
|
|
|
chatnetString = concatStringsSep "\n" (flip mapAttrsToList cfg.networks
|
|
|
|
(k: v: ''
|
|
|
|
${k} = {
|
|
|
|
type = "${v.type}";
|
|
|
|
nick = "${quoteStr v.nick}";
|
|
|
|
autosendcmd = "${concatMapStringsSep ";" quoteStr v.autoCommands}";
|
2022-10-29 16:58:14 +02:00
|
|
|
${
|
|
|
|
lib.optionalString (v.saslExternal) ''
|
|
|
|
sasl_username = "${quoteStr v.nick}";
|
|
|
|
sasl_mechanism = "EXTERNAL";''
|
|
|
|
}
|
2021-10-31 10:32:58 +01:00
|
|
|
};
|
|
|
|
''));
|
|
|
|
|
|
|
|
serversString = concatStringsSep cnl (flip mapAttrsToList cfg.networks
|
|
|
|
(k: v: ''
|
|
|
|
{
|
|
|
|
chatnet = "${k}";
|
|
|
|
address = "${v.server.address}";
|
|
|
|
port = "${toString v.server.port}";
|
2022-04-08 06:36:13 +02:00
|
|
|
use_ssl = "${lib.hm.booleans.yesNo v.server.ssl.enable}";
|
|
|
|
ssl_verify = "${lib.hm.booleans.yesNo v.server.ssl.verify}";
|
|
|
|
autoconnect = "${lib.hm.booleans.yesNo v.server.autoConnect}";
|
2021-10-31 10:32:58 +01:00
|
|
|
${
|
2022-10-29 16:58:14 +02:00
|
|
|
optionalString (v.server.ssl.certificateFile != null) ''
|
2021-10-31 10:32:58 +01:00
|
|
|
ssl_cert = "${v.server.ssl.certificateFile}";
|
|
|
|
''
|
2019-01-24 13:00:11 +01:00
|
|
|
}
|
2021-10-31 10:32:58 +01:00
|
|
|
}
|
|
|
|
''));
|
|
|
|
|
2022-03-12 22:51:48 +01:00
|
|
|
channelString = concatStringsSep cnl (concatLists
|
|
|
|
(flip mapAttrsToList cfg.networks (k: v:
|
|
|
|
(flip mapAttrsToList v.channels (c: cv: ''
|
|
|
|
{
|
|
|
|
chatnet = "${k}";
|
|
|
|
name = "${c}";
|
2022-04-08 06:36:13 +02:00
|
|
|
autojoin = "${lib.hm.booleans.yesNo cv.autoJoin}";
|
2022-03-12 22:51:48 +01:00
|
|
|
}
|
|
|
|
'')))));
|
2019-01-24 13:00:11 +01:00
|
|
|
|
|
|
|
channelType = types.submodule {
|
|
|
|
options = {
|
|
|
|
name = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
visible = false;
|
|
|
|
default = null;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Name of the channel.";
|
2019-01-24 13:00:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
autoJoin = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Whether to join this channel on connect.";
|
2019-01-24 13:00:11 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-10-31 10:32:58 +01:00
|
|
|
networkType = types.submodule ({ name, ... }: {
|
2019-01-24 13:00:11 +01:00
|
|
|
options = {
|
|
|
|
name = mkOption {
|
|
|
|
visible = false;
|
|
|
|
default = name;
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
nick = mkOption {
|
|
|
|
type = types.str;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Nickname in that network.";
|
2019-01-24 13:00:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
type = mkOption {
|
|
|
|
type = types.str;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Type of the network.";
|
2019-01-24 13:00:11 +01:00
|
|
|
default = "IRC";
|
|
|
|
};
|
|
|
|
|
|
|
|
autoCommands = mkOption {
|
|
|
|
type = types.listOf types.str;
|
2021-10-31 10:32:58 +01:00
|
|
|
default = [ ];
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "List of commands to execute on connect.";
|
2019-01-24 13:00:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
server = {
|
|
|
|
address = mkOption {
|
|
|
|
type = types.str;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Address of the chat server.";
|
2019-01-24 13:00:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
2019-08-19 20:37:48 +02:00
|
|
|
type = types.port;
|
2019-01-24 13:00:11 +01:00
|
|
|
default = 6667;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Port of the chat server.";
|
2019-01-24 13:00:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
ssl = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Whether SSL should be used.";
|
2019-01-24 13:00:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
verify = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Whether the SSL certificate should be verified.";
|
2019-01-24 13:00:11 +01:00
|
|
|
};
|
2021-06-06 23:31:25 +02:00
|
|
|
|
|
|
|
certificateFile = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2021-06-06 23:31:25 +02:00
|
|
|
Path to a file containing the certificate used for
|
|
|
|
client authentication to the server.
|
|
|
|
'';
|
|
|
|
};
|
2019-01-24 13:00:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
autoConnect = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Whether Irssi connects to the server on launch.";
|
2019-01-24 13:00:11 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
channels = mkOption {
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Channels for the given network.";
|
2019-01-24 13:00:11 +01:00
|
|
|
type = types.attrsOf channelType;
|
2021-10-31 10:32:58 +01:00
|
|
|
default = { };
|
2019-01-24 13:00:11 +01:00
|
|
|
};
|
2022-10-29 16:58:14 +02:00
|
|
|
|
|
|
|
saslExternal = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2022-10-29 16:58:14 +02:00
|
|
|
Enable SASL external authentication. This requires setting a path in
|
2023-07-01 01:30:13 +02:00
|
|
|
[](#opt-programs.irssi.networks._name_.server.ssl.certificateFile).
|
2022-10-29 16:58:14 +02:00
|
|
|
'';
|
|
|
|
};
|
2019-01-24 13:00:11 +01:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2021-10-31 10:32:58 +01:00
|
|
|
in {
|
2019-01-24 13:00:11 +01:00
|
|
|
|
|
|
|
options = {
|
|
|
|
programs.irssi = {
|
2023-07-02 01:45:18 +02:00
|
|
|
enable = mkEnableOption "the Irssi chat client";
|
2019-01-24 13:00:11 +01:00
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
default = "";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "These lines are appended to the Irssi configuration.";
|
2022-03-23 20:31:24 +01:00
|
|
|
type = types.lines;
|
2019-01-24 13:00:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
aliases = mkOption {
|
2021-10-31 10:32:58 +01:00
|
|
|
default = { };
|
|
|
|
example = {
|
|
|
|
J = "join";
|
|
|
|
BYE = "quit";
|
|
|
|
};
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "An attribute set that maps aliases to commands.";
|
2019-01-24 13:00:11 +01:00
|
|
|
type = types.attrsOf types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
networks = mkOption {
|
2021-10-31 10:32:58 +01:00
|
|
|
default = { };
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2019-01-24 13:00:11 +01:00
|
|
|
{
|
2022-12-03 05:20:00 +01:00
|
|
|
liberachat = {
|
2019-01-24 13:00:11 +01:00
|
|
|
nick = "hmuser";
|
|
|
|
server = {
|
2022-12-03 05:20:00 +01:00
|
|
|
address = "irc.libera.chat";
|
2019-01-24 13:00:11 +01:00
|
|
|
port = 6697;
|
|
|
|
autoConnect = true;
|
|
|
|
};
|
|
|
|
channels = {
|
|
|
|
nixos.autoJoin = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "An attribute set of chat networks.";
|
2019-01-24 13:00:11 +01:00
|
|
|
type = types.attrsOf networkType;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
home.packages = [ pkgs.irssi ];
|
|
|
|
|
|
|
|
home.file.".irssi/config".text = ''
|
|
|
|
settings = {
|
|
|
|
core = {
|
|
|
|
settings_autosave = "no";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
aliases = {
|
|
|
|
${assignFormat cfg.aliases}
|
|
|
|
};
|
|
|
|
|
|
|
|
chatnets = {
|
|
|
|
${chatnetString}
|
|
|
|
};
|
|
|
|
|
|
|
|
servers = (
|
|
|
|
${serversString}
|
|
|
|
);
|
|
|
|
|
|
|
|
channels = (
|
|
|
|
${channelString}
|
|
|
|
);
|
|
|
|
|
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|