From 275f955db979e069fbe7a1fd7cfcb5ec030a2096 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Sun, 31 Oct 2021 10:32:58 +0100 Subject: [PATCH] irssi: format using nixfmt --- format | 7 +-- modules/programs/irssi.nix | 97 +++++++++++++++++++------------------- 2 files changed, 50 insertions(+), 54 deletions(-) diff --git a/format b/format index 5b8664578..0fa620c1a 100755 --- a/format +++ b/format @@ -12,12 +12,9 @@ case $1 in ;; esac -# The first block of excludes are files where nixfmt does a poor job, -# IMHO. The second block of excludes are files touched by open pull -# requests and we want to avoid merge conflicts. +# The excludes are for files touched by open pull requests and we want +# to avoid merge conflicts. find . -name '*.nix' \ - ! -path ./modules/programs/irssi.nix \ - \ ! -path ./home-manager/home-manager.nix \ ! -path ./modules/default.nix \ ! -path ./modules/files.nix \ diff --git a/modules/programs/irssi.nix b/modules/programs/irssi.nix index cb82fd411..a8f8a22ff 100644 --- a/modules/programs/irssi.nix +++ b/modules/programs/irssi.nix @@ -7,53 +7,51 @@ let cfg = config.programs.irssi; boolStr = b: if b then "yes" else "no"; - quoteStr = s: escape ["\""] s; + quoteStr = s: escape [ ''"'' ] s; + + # Comma followed by newline. + cnl = '' + , + ''; assignFormat = set: concatStringsSep "\n" - (mapAttrsToList (k: v: " ${k} = \"${quoteStr v}\";") set); + (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}"; - }; - '')); + chatnetString = concatStringsSep "\n" (flip mapAttrsToList cfg.networks + (k: v: '' + ${k} = { + type = "${v.type}"; + nick = "${quoteStr v.nick}"; + autosendcmd = "${concatMapStringsSep ";" quoteStr v.autoCommands}"; + }; + '')); - serversString = - concatStringsSep ",\n" - (flip mapAttrsToList cfg.networks - (k: v: '' - { - chatnet = "${k}"; - address = "${v.server.address}"; - port = "${toString v.server.port}"; - use_ssl = "${boolStr v.server.ssl.enable}"; - ssl_verify = "${boolStr v.server.ssl.verify}"; - autoconnect = "${boolStr v.server.autoConnect}"; - ${lib.optionalString (v.server.ssl.certificateFile != null) '' - ssl_cert = "${v.server.ssl.certificateFile}"; - ''} + serversString = concatStringsSep cnl (flip mapAttrsToList cfg.networks + (k: v: '' + { + chatnet = "${k}"; + address = "${v.server.address}"; + port = "${toString v.server.port}"; + use_ssl = "${boolStr v.server.ssl.enable}"; + ssl_verify = "${boolStr v.server.ssl.verify}"; + autoconnect = "${boolStr v.server.autoConnect}"; + ${ + lib.optionalString (v.server.ssl.certificateFile != null) '' + ssl_cert = "${v.server.ssl.certificateFile}"; + '' } - '')); + } + '')); - channelString = - concatStringsSep ",\n" - (flip mapAttrsToList cfg.networks - (k: v: - concatStringsSep ",\n" - (flip mapAttrsToList v.channels - (c: cv: '' - { - chatnet = "${k}"; - name = "${c}"; - autojoin = "${boolStr cv.autoJoin}"; - } - '')))); + channelString = concatStringsSep cnl (flip mapAttrsToList cfg.networks (k: v: + concatStringsSep cnl (flip mapAttrsToList v.channels (c: cv: '' + { + chatnet = "${k}"; + name = "${c}"; + autojoin = "${boolStr cv.autoJoin}"; + } + '')))); channelType = types.submodule { options = { @@ -72,7 +70,7 @@ let }; }; - networkType = types.submodule ({ name, ...}: { + networkType = types.submodule ({ name, ... }: { options = { name = mkOption { visible = false; @@ -93,7 +91,7 @@ let autoCommands = mkOption { type = types.listOf types.str; - default = []; + default = [ ]; description = "List of commands to execute on connect."; }; @@ -142,14 +140,12 @@ let channels = mkOption { description = "Channels for the given network."; type = types.attrsOf channelType; - default = {}; + default = { }; }; }; }); -in - -{ +in { options = { programs.irssi = { @@ -162,14 +158,17 @@ in }; aliases = mkOption { - default = {}; - example = { J = "join"; BYE = "quit";}; + default = { }; + example = { + J = "join"; + BYE = "quit"; + }; description = "An attribute set that maps aliases to commands."; type = types.attrsOf types.str; }; networks = mkOption { - default = {}; + default = { }; example = literalExpression '' { freenode = {