nix-community / srvos

NixOS profiles for servers [maintainer=@numtide]
https://nix-community.github.io/srvos
MIT License
515 stars 27 forks source link

Thin nixosSystems #122

Open zimbatm opened 1 year ago

zimbatm commented 1 year ago

Is your feature request related to a problem? Please describe.

When calling nixpkgs.lib.nixosSystems, all the NixOS modules of the repo are getting loaded, making the evaluation quite expensive.

Describe the solution you'd like

Provide a compatible function that only loads a subset of the nixpkgs NixOS modules.

Describe alternatives you've considered

Additional context

soupglasses commented 1 year ago

Do you know where nixpkgs.lib.nixosSystems causes the full loads? Would very likely help narrow down what needs modified.

phaer commented 1 year ago

Do you know where nixpkgs.lib.nixosSystems causes the full loads? Would very likely help narrow down what needs modified.

I believe that starts with baseModules ? import ../modules/module-list.nix in https://github.com/NixOS/nixpkgs/blob/9d757ec498666cc1dcc6f2be26db4fd3e1e9ab37/nixos/lib/eval-config.nix#L22

There's https://github.com/NixOS/nixpkgs/blob/master/nixos/lib/eval-config-minimal.nix which does not evaluate all the modules by default, but I haven't succeeded in building an actual nixosSystem with that as the modules are currently rather tightly coupled.

E.g. I want systemd-resolved for my system, but that module currently checks if config.network-manager.enable is true and just fails to evaluate if that option isn't even defined (because I do not need network-manager and therefore did not load the module).

That alone would be easy to solve, but as I have no idea how many similar evaluation errors would follow, I did not continue to investigate further. Happy to work on this together during NixCon or Oceansprint if interested people are there! :)

One idea would be to start with tooling that calculates the "dependency tree" of modules, not in terms of imports, but in terms of references to config.${name} in order to get an idea of what needs to be done and where the quickest wins can be found.

arianvp commented 4 months ago

I've been on a similar quest:

https://github.com/arianvp/lolmin/blob/main/flake.nix

All the modules that I moved out of nixpkgs into my own repo are problematic ones. Which I then kept deleting lines from until it stopped complaining about dependencies.

pam.nix basically pulls in the world. It's a really problematic module.

network-interfaces.nix pulls in basically every network manager and tool in existance whilst you really only need networking.hostName

wrappers.nix pulls in sudo-rs and apparmor and co.

systemd-initrd pulls in the old initrd module journald pulls in rsyslogd and syslog-ng

Anyhow. Eval went from 6s to 3s which is quite nice. But it shows NixOS needs a lot of refactoring for it to be practically possible to reduce the module list.