summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorDaiderd Jordan <daiderd@gmail.com>2020-05-03 18:57:17 +0200
committerGitHub <noreply@github.com>2020-05-03 18:57:17 +0200
commitf885aff4c9efca0dcb553fec9a5029f4995adb30 (patch)
tree85b6c63c52626172f30ebc30aa88ab35eaeebbab /modules
parent2752bf1421b55b35d7217d2c3d4a458a4bca30ba (diff)
parent784b688dd92ae303dadee69e2063cfb7c4a29d9c (diff)
Merge pull request #195 from hauleth/ft/add-dnsmasq-service
Add DNSmasq service
Diffstat (limited to 'modules')
-rw-r--r--modules/module-list.nix1
-rw-r--r--modules/services/dnsmasq.nix70
2 files changed, 71 insertions, 0 deletions
diff --git a/modules/module-list.nix b/modules/module-list.nix
index cb38af0..ae5cf69 100644
--- a/modules/module-list.nix
+++ b/modules/module-list.nix
@@ -38,6 +38,7 @@
./services/autossh.nix
./services/buildkite-agent.nix
./services/chunkwm.nix
+ ./services/dnsmasq.nix
./services/emacs.nix
./services/khd
./services/kwm
diff --git a/modules/services/dnsmasq.nix b/modules/services/dnsmasq.nix
new file mode 100644
index 0000000..9a8cf11
--- /dev/null
+++ b/modules/services/dnsmasq.nix
@@ -0,0 +1,70 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+ cfg = config.services.dnsmasq;
+ mapA = f: attrs: with builtins; attrValues (mapAttrs f attrs);
+in
+
+{
+ options = {
+ services.dnsmasq.enable = mkOption {
+ type = types.bool;
+ default = false;
+ description = "Whether to enable DNSmasq.";
+ };
+
+ services.dnsmasq.package = mkOption {
+ type = types.path;
+ default = pkgs.dnsmasq;
+ defaultText = "pkgs.dnsmasq";
+ description = "This option specifies the dnsmasq package to use.";
+ };
+
+ services.dnsmasq.bind = mkOption {
+ type = types.str;
+ default = "127.0.0.1";
+ description = "This option specifies the interface on which DNSmasq will listen.";
+ };
+
+ services.dnsmasq.port = mkOption {
+ type = types.int;
+ default = 53;
+ description = "This option specifies port on which DNSmasq will listen.";
+ };
+
+ services.dnsmasq.addresses = mkOption {
+ type = types.attrs;
+ default = {};
+ description = "List of domains that will be redirected by the DNSmasq.";
+ example = literalExample ''
+ { localhost = "127.0.0.1"; }
+ '';
+ };
+ };
+
+ config = mkIf cfg.enable {
+ environment.systemPackages = [ cfg.package ];
+
+ launchd.daemons.dnsmasq = {
+ serviceConfig.ProgramArguments = [
+ "${cfg.package}/bin/dnsmasq"
+ "--listen-address=${cfg.bind}"
+ "--port=${toString cfg.port}"
+ "--keep-in-foreground"
+ ] ++ (mapA (domain: addr: "--address=/${domain}/${addr}") cfg.addresses);
+
+ serviceConfig.KeepAlive = true;
+ serviceConfig.RunAtLoad = true;
+ };
+
+ environment.etc = builtins.listToAttrs (builtins.map (domain: {
+ name = "resolver/${domain}";
+ value = {
+ enable = true;
+ text = "nameserver ${cfg.bind}.${toString cfg.port}";
+ };
+ }) (builtins.attrNames cfg.addresses));
+ };
+}