It's fairly well documented how to replace a NixOS service in the stable channel with one from the unstable channel.
What if you need to build from an upstream branch that's not in either of stable or unstable channels? This is how I go about it, including building a VM in which to test the result.
I specifically wanted to test the new hydra-notify
service, so to test that,
I need to replace the existing Hydra module in nixpkgs with the one from
upstream source. Start by checking out the hydra source:
$ git clone https://github.com/NixOS/hydra.git
We Can configure Nix to replace the nixpkgs version of Hydra with a build from hydra/master.
You can see a completed example in hydra_notify.nix but the key points are that we need to disable Hydra in the standard Nix packages:
disabledModules = [ "services/continuous-integration/hydra/default.nix" ];
as well as import the module definition from the Hydra source we downloaded:
imports =
[
"/path/to/source/hydra/hydra-module.nix"
];
and we need to switch services.hydra
to services.hydra-dev
in two
locations:
networking.firewall.allowedTCPPorts = [ config.services.hydra-dev.port 80 443 ];
services.hydra-dev = {
...
};
With these three changes, we have swapped out the Hydra in nixpkgs for one to
be built from the upstream source in hydra_notify.nix
.
Next we need to build a configuration for our VM that uses the replaced Hydra
module declared in hydra_notify.nix
. This is
hydra_vm.nix,
which is a simple NixOS configuration, which importantly includes our replaced
Hydra module:
imports =
[
./hydra_notify.nix
];
to give this a run yourself, checkout
nixos-examples
and change to the services/hydra_upstream
directory:
$ git clone https://code.mcwhirter.io/craige/nixos-examples.git
$ cd nixos-examples/services/hydra_upstream
After updating the path to Hydra's source, We can then build the VM with:
$ nix-build '<nixpkgs/nixos>' -A vm --arg configuration ./hydra_vm.nix
Before launching the VM, I like to make sure that it is provided with enough RAM and both hydra's web UI and SSH are available by exporting the below Qemu options:
$ export QEMU_OPTS="-m 4192"
$ export QEMU_NET_OPTS="hostfwd=tcp::10443-:443,hostfwd=tcp::10022-:22"
So now we're ready to launch the VM:
./result/bin/run-hydra-notications-vm
Once it has booted, you should be able to ssh nixos@localhost -p 10022
and
hit the Hydra web UI at localhost:10443
.
Once you've logged into the VM you can run systemctl status hydra-notify
to
check that you're running upstream Hydra.