networkmanager: use PATH to search for binaries instead of hard-coding store paths #350199
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
this PR is a set of changes to NetworkManager with the general goal of reducing closure size. The default size of NetworkManager's closure is currently 500 MB, half of that closure being openconnect which pulls in all of GTK3, including X and wayland libs.
The main reason for the closure size is the general behavior of NetworkManager and its libs to search for needed binaries in standard FHS paths.
This was already remarked upon when the package was originally built many years ago.
These needed binaries include:
openconnect
iptables
nftables
dnsmasq
dhcpcd
The approach of this PR is to patch NetworkManager so needed binaries are searched for in the
$PATH
of the running binary instead of some pre-defined and hard-coded dependency paths. It adds anm_utils_find_in_path_env
function tonm_utils.h
which searches for binaries in the path. Additionally, the firewall-helper functions innm-firewall-utils.c
were modified to allow runtime-detection ofnftables
oriptables
binaries.To make this work, the NetworkManager NixOS module also needed to be touched to add missing paths to the systemd service's
$PATH
variable and to the general environment's system packages. The reason for the global addition is that thenmcli
ornmtui
tools pull in the NetworkManager library and use those functions to search for binaries. If you then, for example, add an openconnect VPN and try to connect, they will search for theopenconnect
binary in their PATH as well.Alternatively, we could consider using a wrapper instead and add those paths directly.
With the given changes, the closure size is halved to about 250 MB. By disabling modemmanager, another 25MB can be saved. One additional, smaller change, is the ability to build the
NetworkManager
package withoutmodemmanager
. This would fit nicely with #316824.I've also extended existing tests for NetworkManager to test that the given changes work correctly (meaning the needed binaries are found).
Some additional work is still required on this PR but I'm very interested in feedback towards this approach before continuing to work on this. Some of the required work is:
NetworkManager-ensure-profiles
service) to improve compatibility with this approach.openconnect
and other plugins continue to work properly.Our main use-case for this change is that we use NetworkManager in a constrained environment without a graphical user interface. Currently, we rebuild NM to be more minimal but with this approach we could start using the upstream NM again.
In a future PR, I'd would also be interested in modularizing the nm-module further to allow us to disable more features generally, such as openconnect.
Thanks!
Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.