summary refs log tree commit diff
path: root/nixos/modules/services/networking/shout.nix
diff options
context:
space:
mode:
authorValérian Galliat <val@codejam.info>2016-04-09 17:18:23 -0400
committerValérian Galliat <val@codejam.info>2016-04-10 10:49:32 -0400
commitb0d1eb457974bc42637d4b24b67a874cddc384aa (patch)
tree1e0a73f72ba4487fd45c947ca3f44a3048e49530 /nixos/modules/services/networking/shout.nix
parentaec8daed8685c885f2e8c2701c4a013c607d163d (diff)
downloadnixlib-b0d1eb457974bc42637d4b24b67a874cddc384aa.tar
nixlib-b0d1eb457974bc42637d4b24b67a874cddc384aa.tar.gz
nixlib-b0d1eb457974bc42637d4b24b67a874cddc384aa.tar.bz2
nixlib-b0d1eb457974bc42637d4b24b67a874cddc384aa.tar.lz
nixlib-b0d1eb457974bc42637d4b24b67a874cddc384aa.tar.xz
nixlib-b0d1eb457974bc42637d4b24b67a874cddc384aa.tar.zst
nixlib-b0d1eb457974bc42637d4b24b67a874cddc384aa.zip
Shout: configure with attrs
Diffstat (limited to 'nixos/modules/services/networking/shout.nix')
-rw-r--r--nixos/modules/services/networking/shout.nix50
1 files changed, 42 insertions, 8 deletions
diff --git a/nixos/modules/services/networking/shout.nix b/nixos/modules/services/networking/shout.nix
index f069fe7bec96..761ecbcd173d 100644
--- a/nixos/modules/services/networking/shout.nix
+++ b/nixos/modules/services/networking/shout.nix
@@ -6,6 +6,21 @@ let
   cfg = config.services.shout;
   shoutHome = "/var/lib/shout";
 
+  defaultConfig = pkgs.runCommand "config.js" {} ''
+    EDITOR=true ${pkgs.shout}/bin/shout config --home $PWD
+    mv config.js $out
+  '';
+
+  configFile = if (cfg.configFile != null) then cfg.configFile else ''
+    var _ = require('${pkgs.shout}/lib/node_modules/shout/node_modules/lodash')
+
+    module.exports = _.merge(
+      {},
+      require('${defaultConfig}'),
+      ${builtins.toJSON cfg.config}
+    )
+  '';
+
 in {
   options.services.shout = {
     enable = mkEnableOption "Shout web IRC client";
@@ -33,10 +48,33 @@ in {
 
     configFile = mkOption {
       type = types.nullOr types.lines;
-      default = null;
+      default = configFile;
+      description = ''
+        Contents of Shout's <filename>config.js</filename> file.
+
+        Used for backward compatibility, recommended way is now to use
+        the <literal>config</literal> option.
+
+        Documentation: http://shout-irc.com/docs/server/configuration.html
+      '';
+    };
+
+    config = mkOption {
+      default = {};
+      type = types.attrs;
+      example = {
+        displayNetwork = false;
+        defaults = {
+          name = "Your Network";
+          host = "localhost";
+          port = 6697;
+        };
+      };
       description = ''
-        Contents of Shout's <filename>config.js</filename> file. If left empty,
-        Shout will generate from its defaults at first startup.
+        Shout <filename>config.js</filename> contents as attribute set (will be
+        converted to JSON to generate the configuration file).
+
+        The options defined here will be merged to the default configuration file.
 
         Documentation: http://shout-irc.com/docs/server/configuration.html
       '';
@@ -57,11 +95,7 @@ in {
       wantedBy = [ "multi-user.target" ];
       wants = [ "network-online.target" ];
       after = [ "network-online.target" ];
-      preStart = if isNull cfg.configFile then ""
-                 else ''
-                   ln -sf ${pkgs.writeText "config.js" cfg.configFile} \
-                          ${shoutHome}/config.js
-                 '';
+      preStart = "ln -sf ${pkgs.writeText "config.js" configFile} ${shoutHome}/config.js";
       script = concatStringsSep " " [
         "${pkgs.shout}/bin/shout"
         (if cfg.private then "--private" else "--public")