aboutsummaryrefslogtreecommitdiff
path: root/nixos/modules/system
diff options
context:
space:
mode:
authorNikolay Amiantov <ab@fmap.me>2019-07-15 20:18:49 +0300
committerNikolay Amiantov <ab@fmap.me>2019-07-15 20:25:39 +0300
commit01b90dce78ee3906def0fc8d800217a3f9f40aa7 (patch)
treee4641a57c7dea1639d817fc97f4d22918dbd4ba5 /nixos/modules/system
parent267c8d6b2fea05bc811c8e2c2f4529b1436eeb9a (diff)
resolvconf service: init
This is a refactor of how resolvconf is managed on NixOS. We split it into a separate service which is enabled internally depending on whether we want /etc/resolv.conf to be managed by it. Various services now take advantage of those configuration options. We also now use systemd instead of activation scripts to update resolv.conf. NetworkManager now uses the right option for rc-manager DNS automatically, so the configuration option shouldn't be exposed.
Diffstat (limited to 'nixos/modules/system')
-rw-r--r--nixos/modules/system/boot/resolved.nix43
-rw-r--r--nixos/modules/system/boot/stage-2.nix9
2 files changed, 36 insertions, 16 deletions
diff --git a/nixos/modules/system/boot/resolved.nix b/nixos/modules/system/boot/resolved.nix
index 5c66cf4a6e6..3ea96f8e464 100644
--- a/nixos/modules/system/boot/resolved.nix
+++ b/nixos/modules/system/boot/resolved.nix
@@ -3,6 +3,10 @@
with lib;
let
cfg = config.services.resolved;
+
+ dnsmasqResolve = config.services.dnsmasq.enable &&
+ config.services.dnsmasq.resolveLocalQueries;
+
in
{
@@ -126,6 +130,12 @@ in
config = mkIf cfg.enable {
+ assertions = [
+ { assertion = !config.networking.useHostResolvConf;
+ message = "Using host resolv.conf is not supported with systemd-resolved";
+ }
+ ];
+
systemd.additionalUpstreamSystemUnits = [
"systemd-resolved.service"
];
@@ -135,21 +145,30 @@ in
restartTriggers = [ config.environment.etc."systemd/resolved.conf".source ];
};
- environment.etc."systemd/resolved.conf".text = ''
- [Resolve]
- ${optionalString (config.networking.nameservers != [])
- "DNS=${concatStringsSep " " config.networking.nameservers}"}
- ${optionalString (cfg.fallbackDns != [])
- "FallbackDNS=${concatStringsSep " " cfg.fallbackDns}"}
- ${optionalString (cfg.domains != [])
- "Domains=${concatStringsSep " " cfg.domains}"}
- LLMNR=${cfg.llmnr}
- DNSSEC=${cfg.dnssec}
- ${config.services.resolved.extraConfig}
- '';
+ environment.etc = {
+ "systemd/resolved.conf".text = ''
+ [Resolve]
+ ${optionalString (config.networking.nameservers != [])
+ "DNS=${concatStringsSep " " config.networking.nameservers}"}
+ ${optionalString (cfg.fallbackDns != [])
+ "FallbackDNS=${concatStringsSep " " cfg.fallbackDns}"}
+ ${optionalString (cfg.domains != [])
+ "Domains=${concatStringsSep " " cfg.domains}"}
+ LLMNR=${cfg.llmnr}
+ DNSSEC=${cfg.dnssec}
+ ${config.services.resolved.extraConfig}
+ '';
+
+ # symlink the dynamic stub resolver of resolv.conf as recommended by upstream:
+ # https://www.freedesktop.org/software/systemd/man/systemd-resolved.html#/etc/resolv.conf
+ "resolv.conf".source = "/run/systemd/resolve/stub-resolv.conf";
+ } // optionalAttrs dnsmasqResolve {
+ "dnsmasq-resolv.conf".source = "/run/systemd/resolve/resolv.conf";
+ };
# If networkmanager is enabled, ask it to interface with resolved.
networking.networkmanager.dns = "systemd-resolved";
+
};
}
diff --git a/nixos/modules/system/boot/stage-2.nix b/nixos/modules/system/boot/stage-2.nix
index 55e6b19c67f..6b0b4722730 100644
--- a/nixos/modules/system/boot/stage-2.nix
+++ b/nixos/modules/system/boot/stage-2.nix
@@ -4,19 +4,20 @@ with lib;
let
+ useHostResolvConf = config.networking.resolvconf.enable && config.networking.useHostResolvConf;
+
bootStage2 = pkgs.substituteAll {
src = ./stage-2-init.sh;
shellDebug = "${pkgs.bashInteractive}/bin/bash";
shell = "${pkgs.bash}/bin/bash";
isExecutable = true;
inherit (config.nix) readOnlyStore;
- inherit (config.networking) useHostResolvConf;
+ inherit useHostResolvConf;
inherit (config.system.build) earlyMountScript;
- path = lib.makeBinPath [
+ path = lib.makeBinPath ([
pkgs.coreutils
pkgs.utillinux
- pkgs.openresolv
- ];
+ ] ++ lib.optional useHostResolvConf pkgs.openresolv);
fsPackagesPath = lib.makeBinPath config.system.fsPackages;
postBootCommands = pkgs.writeText "local-cmds"
''