How to test NixOS module?

I’d like to try out my changes to the NixOS module (nixos/crowdsec: use sensible defaults by TornaxO7 · Pull Request #446307 · NixOS/nixpkgs · GitHub) but I don’t want to replace the input in my flake to point to my fork because otherwise my pc would rebuild and compile a lot of packages.

Is there a way to test my changes of that module by just overwriting the services.crowdsec module?

I’ve tried to import my changes into my system but then I’m getting this (understandable) error:

error: The option `services.crowdsec.enable' in `/nix/store/sizirny50f893gx0gbivbqyys4fxghnq-source/nixos/modules/services/security/crowdsec.nix' is already declared in `/nix/store/bwb7ldiyx7shckg7rdkwwva6wlp4cs6g-source/systems/pc/crowdsec.nix'.

Is there a recommended approach to this?

You’re looking for disabledModules.

3 Likes

Does this commit help as an example? fix(boot): Fix sway start waiting for network · TLATER/dotfiles@8ced808 · GitHub

You can also use something like this stunt to patch your nixpkgs on the fly with selected PRs. I prefer this approach, because it does conceptually what you want (“test that PR”), without you needing to fiddle with module paths. I also had some issues with disabledModules where it was not clear what to disable exactly. Here’s my summary thread to the options you have:

Hey not sure if this is helpful or if you knew about it already, but you might be interested in nixosTest (undocumented, but just a wrapper??)/runNixOSTest. I just found out about it, and I’m using it to test out a module I wrote. It automatically creates a nixOS vm and goes through a set of Python tests.

Useful for module development, because you don’t have to test on your actual system, you can just do the development in a flake that spools up a vm for evaluation.