-
-
Notifications
You must be signed in to change notification settings - Fork 14.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove networking.hostConf option #74032
Conversation
@@ -41,19 +41,6 @@ in | |||
''; | |||
}; | |||
|
|||
networking.hostConf = lib.mkOption { | |||
type = types.lines; | |||
default = "multi on"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we add an /etc/host.conf
with this value by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Will update the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is host.conf
honoured in the nsswitch.conf
world?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICT yes as long as you use glibc's resolver directly. It might by another story when using dnsmasq or systemd-resolvd .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should happen inside the file
part of nsswitch.conf
, so before and regardless of which resolver is used to do DNS lookups.
For context, this was introduced during #19148, and seems to be the default on ArchLinux.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@flokli I've studied the man pages but got still no clue about how this should be expressed in nsswitch.conf. Could you provide an example?
6e97fb5
to
73c159d
Compare
nixos/modules/config/networking.nix
Outdated
@@ -185,8 +172,7 @@ in | |||
${cfg.extraHosts} | |||
''; | |||
|
|||
# /etc/host.conf: resolver configuration file | |||
"host.conf".text = cfg.hostConf; | |||
"host.conf".text = mkDefault "multi on\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a reference to #19148 here.
Sure. Gonna rework this stuff and test it. |
@ckauhaus ping ;-) |
@flokli on my way, sorry |
This PR is part of the networking.* namespace cleanup. We feel that networking.hostConf is rarely used and provides little value compared to using environment.etc."host.conf" directly. Provide sensible default: multi on
73c159d
to
918c2ca
Compare
Added a test. This is my first Python test, so feel free to comment. |
nixos/tests/resolv.nix
Outdated
}; | ||
|
||
testScript = let | ||
getaddrinfo_py = pkgs.writeScript "getaddrinfo.py" '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we need our own getaddrinfo_py
script here - Couldn't we just run getent ahosts $hostname
in the testScript
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll give it a shot.
nixos/tests/resolv.nix
Outdated
|
||
in | ||
'' | ||
def compare(test, should, is_): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be a pretty generic tooling, which we might want to make available in the whole test driver, instead of just here. I'd probably leave it out of scope for this PR, though.
@tfc, WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The general idea is great, but i am not sure how that should look like, yet. Also, it should maybe not be part of the driver itself but a (possibly by default included) library that can be used by users - maybe an already existing one?
However, that would best be tackled after we split up the driver into individual library parts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's have it 3 times in individual tests and then extract it into a lib.
nixos/tests/resolv.nix
Outdated
) | ||
) | ||
|
||
assert all(res) is True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd propose to just wrap the individual test in subtests, we automatically ensure they all need to succeed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true.
Although it works fine in this test format, breaking the first test assumption often makes the next assumption pointless.
I would for example not even test for the dual stack condition if one of ipv4 or ipv6 doesn't even work. That's where the test should stop doing anything and dumping me the reason it failed onto the terminal.
The whole test would better fit the estabished workflow if it looked like this:
start_all()
resolv.wait_for_unit("nscd")
ipv4 = "192.0.2.1 192.0.2.2"
ipv6 = "2001:db8::2:1 2001:db8::2:2"
with subtest("IPv4 resolves"):
assert ipv4 in resolv.succeed("${getaddrinfo} host-ipv4.example.net")
with subtest("IPv6 resolves"):
assert ipv6 in resolv.succeed("${getaddrinfo} host-ipv6.example.net")
with subtest("Dual stack resolves"):
assert ipv4 + " " + ipv6 in resolv.succeed("${getaddrinfo} host-dual.example.net")
nixos/tests/resolv.nix
Outdated
) | ||
) | ||
|
||
assert all(res) is True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true.
Although it works fine in this test format, breaking the first test assumption often makes the next assumption pointless.
I would for example not even test for the dual stack condition if one of ipv4 or ipv6 doesn't even work. That's where the test should stop doing anything and dumping me the reason it failed onto the terminal.
The whole test would better fit the estabished workflow if it looked like this:
start_all()
resolv.wait_for_unit("nscd")
ipv4 = "192.0.2.1 192.0.2.2"
ipv6 = "2001:db8::2:1 2001:db8::2:2"
with subtest("IPv4 resolves"):
assert ipv4 in resolv.succeed("${getaddrinfo} host-ipv4.example.net")
with subtest("IPv6 resolves"):
assert ipv6 in resolv.succeed("${getaddrinfo} host-ipv6.example.net")
with subtest("Dual stack resolves"):
assert ipv4 + " " + ipv6 in resolv.succeed("${getaddrinfo} host-dual.example.net")
nixos/tests/resolv.nix
Outdated
|
||
result = set() | ||
for gai in socket.getaddrinfo(sys.argv[1], 0): | ||
result.add(gai[4][0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this generator approach:
result = {gai[4][0] for gai in socket.getaddrinfo(sys.argv[1], 0)}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rewrote test script based on your first suggestion. Please comment. If this version is fine, I'll squash the PR.
I'll rewrite the test next week. @flokli To get back to the main matter: how do I get this setting into nsswitch.conf? I wasn't able to figure it out yet. |
Sorry, missed replying to #74032 (comment)
The nsswitch file is fine as it is in NixOS now (we have a `file` module in there, meaning `/etc/hosts` will be used for lookups and glibc will honor a given `/etc/host.conf`.
I still think we should change the test to invoke `getent ahosts $hostname` instead of providing our own python test script.
|
LGTM! |
Motivation for this change
This PR is part of the networking.* namespace cleanup. We feel that
networking.hostConf is rarely used and provides little value compared to
using environment.etc."host.conf" directly.
Things done
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nix-review --run "nix-review wip"
./result/bin/
)nix path-info -S
before and after)