You’re right, there’s some documentation about contributing to nixpkgs in general, but it’s not really helpful for your case.
The basics are quite simple:
$ git clone https://github.com/NixOS/nixpkgs
$ cd nixpkgs/nixos
$ nix build -f default.nix system
This basically builds your current NixOS configuration with all the packages and modules from the repository you just cloned. It should create a symlink to the built system called result
in the current directory, which you can then explore to ensure that the files were generated as you expect.
It doesn’t enable the system in any way, though. For that, you would need to call ./result/bin/switch-to-configuration
. This is basically what nixos-rebuild switch
does after it built your system config as well.
However, you can also replace system
in the nix build
call above by vm
. That way, you build a vm that you can then run with qemu
to test the result completely separately from you running system.
Once you built and activated/launched your config, you just test the module by checking whether the service is up and whether it was configured as you expect.
If you need to make a lot of iterations, it might make sense to create a tiny configuration and build that instead. So create a file test-config.nix
with this content:
{ pkgs, lib, config, ... }: {
config.services.minecraft-server = {
enable = true;
# add more options as needed for your testing
};
}
And build it like so:
$ NIXOS_CONFIG=$PWD/test-config.nix nix build -f default.nix system
For some things, like generating files and figuring out how exactly some functions work, it might also make sense to use nix repl
:
$ nix repl flake:nixpkgs
warning: future versions of Nix will require using `--file` to load a file
Welcome to Nix 2.15.1. Type :? for help.
Loading installable ''...
Added 19592 variables.
nix-repl> lib.concatLines [ "x = 2;" "y = 3;" "z=x+y;" ]
"x = 2;\ny = 3;\nz=x+y;\n"
This is much quicker than changing files an rebuilding every time. To find out what functions are available, I recommend searching on noogle.
Additionally, you may want to look at the code of other NixOS modules that offer similar functionality as what you want to implement to see how certain things (like adding an additional option) are done.
Hope this helps you get started!