at 23.11-pre 1.9 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4let 5 pkg = pkgs.nixops-dns; 6 cfg = config.services.nixops-dns; 7in 8 9{ 10 options = { 11 services.nixops-dns = { 12 enable = mkOption { 13 type = types.bool; 14 default = false; 15 description = lib.mdDoc '' 16 Whether to enable the nixops-dns resolution 17 of NixOps virtual machines via dnsmasq and fake domain name. 18 ''; 19 }; 20 21 user = mkOption { 22 type = types.str; 23 description = lib.mdDoc '' 24 The user the nixops-dns daemon should run as. 25 This should be the user, which is also used for nixops and 26 have the .nixops directory in its home. 27 ''; 28 }; 29 30 domain = mkOption { 31 type = types.str; 32 description = lib.mdDoc '' 33 Fake domain name to resolve to NixOps virtual machines. 34 35 For example "ops" will resolve "vm.ops". 36 ''; 37 default = "ops"; 38 }; 39 40 dnsmasq = mkOption { 41 type = types.bool; 42 default = true; 43 description = lib.mdDoc '' 44 Enable dnsmasq forwarding to nixops-dns. This allows to use 45 nixops-dns for `services.nixops-dns.domain` resolution 46 while forwarding the rest of the queries to original resolvers. 47 ''; 48 }; 49 50 }; 51 }; 52 53 config = mkIf cfg.enable { 54 systemd.services.nixops-dns = { 55 description = "nixops-dns: DNS server for resolving NixOps machines"; 56 wantedBy = [ "multi-user.target" ]; 57 58 serviceConfig = { 59 Type = "simple"; 60 User = cfg.user; 61 ExecStart="${pkg}/bin/nixops-dns --domain=.${cfg.domain}"; 62 }; 63 }; 64 65 services.dnsmasq = mkIf cfg.dnsmasq { 66 enable = true; 67 resolveLocalQueries = true; 68 servers = [ 69 "/${cfg.domain}/127.0.0.1#5300" 70 ]; 71 extraConfig = '' 72 bind-interfaces 73 listen-address=127.0.0.1 74 ''; 75 }; 76 77 }; 78}