How to test changes to a nixos module?


I forked nixpkgs and created a branch on which I made a change to a nixos module (nixos/modules/programs/less).

I’d like to test it out before making a PR, but I’m not sure how to do so. Is there a way to temporarily point my nixos configuration at my forked copy of nixpkgs?



Passing -I nixpkgs=/path/to/your/nixpkgs to nixos-rebuild will make it use /path/to/your/nixpkgs on a one-off basis.



I use for testing NixOS modules. It spawns a lightweight VM using a small configuration file. You probably need to set your NIX_PATH nixpkgs attribute when calling it.

NIX_PATH=nixpkgs=/path/to/nixpkgs nixos-shell
1 Like


I don’t know if this is recommendet but I sometimes do nix-env -f /path/to/nixpkgs -i packagename.



This is useful for testing packages, but not nixos modules. You may also want to use -A with it as well:
Either way, thanks for sharing :slight_smile:

1 Like


Thanks, passing -I nixpkgs=/path/to/your/nixpkgs to nixos-rebuild seems like the most straightforward approach, and it worked like a charm. I really appreciate the help.