How to test changes to a nixos module?

#1

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?

0 Likes

#2

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

2 Likes

#3

I use https://github.com/Mic92/nixos-shell 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

#4

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

0 Likes

#5

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

1 Like

#6

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.

0 Likes