diff options
author | Matthew Bauer <mjbauer95@gmail.com> | 2020-03-16 14:34:03 -0400 |
---|---|---|
committer | Matthew Bauer <mjbauer95@gmail.com> | 2020-03-16 14:34:03 -0400 |
commit | 67b0ddf3f30d975bd41bc2ac1cc871436ed1af0e (patch) | |
tree | eddc87a600bfd5cf9f6f6ff15f8e735664eae1e1 /nixos/modules/config | |
parent | e9c2957c1465838c27c7a67e56a6ade95033eefd (diff) | |
parent | b8cff61c330400e39dbac22b8993fe58fb35ec13 (diff) | |
download | nixlib-67b0ddf3f30d975bd41bc2ac1cc871436ed1af0e.tar nixlib-67b0ddf3f30d975bd41bc2ac1cc871436ed1af0e.tar.gz nixlib-67b0ddf3f30d975bd41bc2ac1cc871436ed1af0e.tar.bz2 nixlib-67b0ddf3f30d975bd41bc2ac1cc871436ed1af0e.tar.lz nixlib-67b0ddf3f30d975bd41bc2ac1cc871436ed1af0e.tar.xz nixlib-67b0ddf3f30d975bd41bc2ac1cc871436ed1af0e.tar.zst nixlib-67b0ddf3f30d975bd41bc2ac1cc871436ed1af0e.zip |
Merge remote-tracking branch 'origin/staging' into mb-cross-fixes-march-2020
Diffstat (limited to 'nixos/modules/config')
-rw-r--r-- | nixos/modules/config/networking.nix | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/nixos/modules/config/networking.nix b/nixos/modules/config/networking.nix index 81427bb8ee64..dd36696b94d2 100644 --- a/nixos/modules/config/networking.nix +++ b/nixos/modules/config/networking.nix @@ -35,12 +35,22 @@ in ''; }; + networking.hostFiles = lib.mkOption { + type = types.listOf types.path; + defaultText = lib.literalExample "Hosts from `networking.hosts` and `networking.extraHosts`"; + example = lib.literalExample ''[ "''${pkgs.my-blocklist-package}/share/my-blocklist/hosts" ]''; + description = '' + Files that should be concatenated together to form <filename>/etc/hosts</filename>. + ''; + }; + networking.extraHosts = lib.mkOption { type = types.lines; default = ""; example = "192.168.0.1 lanlocalhost"; description = '' Additional verbatim entries to be appended to <filename>/etc/hosts</filename>. + For adding hosts from derivation results, use <option>networking.hostFiles</option> instead. ''; }; @@ -159,6 +169,15 @@ in "::1" = [ "localhost" ]; }; + networking.hostFiles = let + stringHosts = + let + oneToString = set: ip: ip + " " + concatStringsSep " " set.${ip} + "\n"; + allToString = set: concatMapStrings (oneToString set) (attrNames set); + in pkgs.writeText "string-hosts" (allToString (filterAttrs (_: v: v != []) cfg.hosts)); + extraHosts = pkgs.writeText "extra-hosts" cfg.extraHosts; + in mkBefore [ stringHosts extraHosts ]; + environment.etc = { # /etc/services: TCP/UDP port assignments. services.source = pkgs.iana-etc + "/etc/services"; @@ -167,12 +186,8 @@ in protocols.source = pkgs.iana-etc + "/etc/protocols"; # /etc/hosts: Hostname-to-IP mappings. - hosts.text = let - oneToString = set: ip: ip + " " + concatStringsSep " " set.${ip}; - allToString = set: concatMapStringsSep "\n" (oneToString set) (attrNames set); - in '' - ${allToString (filterAttrs (_: v: v != []) cfg.hosts)} - ${cfg.extraHosts} + hosts.source = pkgs.runCommandNoCC "hosts" {} '' + cat ${escapeShellArgs cfg.hostFiles} > $out ''; # /etc/host.conf: resolver configuration file |