-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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
NixOS config option to disable networking entirely #63541
base: master
Are you sure you want to change the base?
Conversation
config.environment.etc."nsswitch.conf".source | ||
config.environment.etc."nscd.conf".source | ||
]; | ||
] ++ optional config.networking.enable config.environment.etc.hosts.source; |
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.
why is this change required?
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.
Fair question, I should probably have called that out. It's because if networking is disabled, /etc/hosts
doesn't get created at all, and config.environment.etc.hosts
is undefined. But nscd is still usable without network so it shouldn't get automatically disabled entirely.
Thanks for reviewing!
@GrahamcOfBorg test networking.scripted.loopback networking.scripted.static networking.scripted.dhcpSimple networking.networkd.loopback networking.networkd.static networking.networkd.dhcpSimple |
This could actually be converted into a system-wide check for broken targets. |
Sure, I suppose so! I'm not sure whether it should be an assertion in general though. That commit helped me find services which were implied by something in my configuration but didn't make sense without a network, but maybe it's over-zealous. Maybe in general it should work like this:
Does that seem right? If you'd like I can drop that commit from this PR and try putting the more general version together. |
That sounds about right (maybe even warnings won't be convenient), but anyway let's not do this now, this was more of an "idea of future improvement". |
@jameysharp You have a conflict there (I suppose introduced by my resolvconf merge). |
These are the only networking-related units that are in the list of upstreamSystemUnits, which prevents users from configuring them out. By analogy with network-related services like networkd, resolved, and timesyncd, let's keep the networking targets with the settings that configure them.
Apparently something else I'm working on made it a problem for config declarations in this module to depend on evaluating utils.nix. I don't understand where the evaluation cycle is, but in this case it's shorter to reference `utils.` explicitly once than it is to say `with utils;`, so I'm not bothering to think about it very hard.
Ah, I added things right next to where you removed things, and merge didn't know what to do... I've rebased it and fixed the conflicts. I'm going to go re-run my original ad-hoc tests now but I wanted to get the bot started on this in parallel, so: @GrahamcOfBorg test networking.scripted.loopback networking.scripted.static networking.scripted.dhcpSimple networking.networkd.loopback networking.networkd.static networking.networkd.dhcpSimple |
I... don't think the bot actually ran these tests? Maybe because it was still running the initial checks from when I pushed the rebased commits? @GrahamcOfBorg test networking.scripted.loopback networking.scripted.static networking.scripted.dhcpSimple networking.networkd.loopback networking.networkd.static networking.networkd.dhcpSimple |
On a system with nss-myhostname configured, as it is by default on NixOS, /etc/hosts is not necessary for most people. Although NixOS currently creates it unconditionally, this patch allows for setting `environment.etc.hosts.enable = false`, and also clears the way for NixOS to someday not create the file in the first place.
I want to be able to turn off all services which require a network. Some of them had existing configuration options, but several core modules did not, so it wasn't possible to turn networking off completely.
e9e36fa
to
66a9d20
Compare
I guess the bot is ignoring me. After trying to figure out how the new resolvconf module should interact with this setting, I'm having second thoughts about some of this. I've changed the The big issue is that settings like How should that work instead? We should be setting the config option itself based on the value of
This pattern should probably be packaged up in Another question is, should every module that accesses anything in the Finally of course there's @abbradar's observation that the check for unsatisfiable systemd units could be a global thing rather than special for networking. I've dropped my patch for that from this pull request because I think it should get more thought. |
@jameysharp you should request ofborg rights, see examples https://github.com/NixOS/ofborg/pulls?q=is%3Apr+is%3Aclosed
I don't think it is a thing to bother. If someone defines
Probably yes, but luckily this can be done incrementally after this is merged. |
@jameysharp I think if you patch all services that somehow require networking you'd be playing whack-a-mole and it's easy to make a mistake and disable a module which can actually be useful without networking for some obscure use case. Instead I'd:
Other networking services like Finally, one shouldn't use EDIT: Also, services like |
upstreamNetworkUnits = [ | ||
"network.target" | ||
"network-pre.target" | ||
"network-online.target" |
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.
Would the absent of these targets not break many services? Since there are just text files do we really gain a lot by leaving them out?
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.
In order: The absence of these targets should break exactly those services which this new option is meant to disable; and leaving them out doesn't have anything to do with closure size, since they're shipped in systemd's examples/
directory regardless. Does that help?
@danbst Thanks for the ping, I got distracted. I think before this is merged I probably ought to take yours and @abbradar's advice on which modules should respect the new option, at least to the extent of dropping the I'd also like to fix After that I think anything else would be fine to defer to later work. Does that seem reasonable? |
Thank you for your contributions.
|
I marked this as stale due to inactivity. → More info |
Motivation for this change
I've had some success at building single-purpose read-only root filesystem images by heavily customizing NixOS configuration options and package overrides. (I'd like to see NixOS supplant Yocto 😈)
But one of the things I couldn't disable was support for networking. I could turn off most individual services, like a DHCP client, but there was still some core stuff wasting space and boot time in my images. Most NixOS users will leave networking enabled, but for specialized applications it's really helpful to just turn it off entirely.
Things done
Even after reading the manual I don't understand how to run the tests. I ran:
I don't know what it would look like if it failed, but I got 12
result*
symlinks at the end, and spot-checking logs looks okay I guess?sandbox
innix.conf
on non-NixOS)nix-shell -p nix-review --run "nix-review wip"
./result/bin/
)nix path-info -S
before and after)