summary refs log tree commit diff
path: root/nixos/modules/services/networking/dnscrypt-proxy2.nix
diff options
context:
space:
mode:
authorAtemu <atemu.main@gmail.com>2020-03-14 14:42:52 +0100
committerAtemu <atemu.main@gmail.com>2020-12-12 09:15:11 +0100
commite4c49db668f9142644677f6ae4a9ddc3979984b9 (patch)
treef671e8cb9a68e41bcf21edc03a13864f48f494a7 /nixos/modules/services/networking/dnscrypt-proxy2.nix
parentc8f26afbbf45fa28fd024bcbfc06a097aca0ea1c (diff)
downloadnixpkgs-e4c49db668f9142644677f6ae4a9ddc3979984b9.tar
nixpkgs-e4c49db668f9142644677f6ae4a9ddc3979984b9.tar.gz
nixpkgs-e4c49db668f9142644677f6ae4a9ddc3979984b9.tar.bz2
nixpkgs-e4c49db668f9142644677f6ae4a9ddc3979984b9.tar.lz
nixpkgs-e4c49db668f9142644677f6ae4a9ddc3979984b9.tar.xz
nixpkgs-e4c49db668f9142644677f6ae4a9ddc3979984b9.tar.zst
nixpkgs-e4c49db668f9142644677f6ae4a9ddc3979984b9.zip
nixos/dnscrypt-proxy2: base settings on example config
Dnscrypt-proxy needs some options to be set before it can do anything useful.

Currently, we only apply what the user configured which, by default, is nothing.

This leads to the dnscrypt-proxy2 service failing to start when you only set
`enable = true;` which is not a great user experience.

This patch makes the module take the example config from the upstream repo as a
base on top of which the user-specified settings are applied (it contains sane
defaults).

An option has been added to restore the old behaviour.
Diffstat (limited to 'nixos/modules/services/networking/dnscrypt-proxy2.nix')
-rw-r--r--nixos/modules/services/networking/dnscrypt-proxy2.nix18
1 files changed, 17 insertions, 1 deletions
diff --git a/nixos/modules/services/networking/dnscrypt-proxy2.nix b/nixos/modules/services/networking/dnscrypt-proxy2.nix
index dda61212216..ff8a2ab3077 100644
--- a/nixos/modules/services/networking/dnscrypt-proxy2.nix
+++ b/nixos/modules/services/networking/dnscrypt-proxy2.nix
@@ -27,6 +27,16 @@ in
       default = {};
     };
 
+    upstreamDefaults = mkOption {
+      description = ''
+        Whether to base the config declared in <literal>services.dnscrypt-proxy2.settings</literal> on the upstream example config (<link xlink:href="https://github.com/DNSCrypt/dnscrypt-proxy/blob/master/dnscrypt-proxy/example-dnscrypt-proxy.toml"/>)
+
+        Disable this if you want to declare your dnscrypt config from scratch.
+      '';
+      type = types.bool;
+      default = true;
+    };
+
     configFile = mkOption {
       description = ''
         Path to TOML config file. See: <link xlink:href="https://github.com/DNSCrypt/dnscrypt-proxy/blob/master/dnscrypt-proxy/example-dnscrypt-proxy.toml"/>
@@ -38,7 +48,13 @@ in
         json = builtins.toJSON cfg.settings;
         passAsFile = [ "json" ];
       } ''
-        ${pkgs.remarshal}/bin/json2toml < $jsonPath > $out
+        ${if cfg.upstreamDefaults then ''
+          ${pkgs.remarshal}/bin/toml2json ${pkgs.dnscrypt-proxy2.src}/dnscrypt-proxy/example-dnscrypt-proxy.toml > example.json
+          ${pkgs.jq}/bin/jq --slurp add example.json $jsonPath > config.json # merges the two
+        '' else ''
+          cp $jsonPath config.json
+        ''}
+        ${pkgs.remarshal}/bin/json2toml < config.json > $out
       '';
       defaultText = literalExample "TOML file generated from services.dnscrypt-proxy2.settings";
     };