How to develop a service from an older local nixpkgs

I am interested in contributing to nixpkgs. In particular, I’m wanting to contribute to a PR that implements Drupal as a NixOS service. (nixos/drupal: init by drupol · Pull Request #323802 · NixOS/nixpkgs · GitHub). I’ve reached out to the maintainer and they’re cool with me making some changes on this PR since they don’t really have the bandwidth at the moment.

My goal is to update the drupal version, fix some bugs, implement a few small features if I’m able, and (hopefully) get it accepted.

The syntax for running the service is pretty similar to how wordpress does it.

services.drupal.sites."localhost" = {};

That said, I’m struggling to figure out how to set up a dev environment to run this service on my nixos (24.11) machine so I can start making changes to nixpkgs.

So far, I’ve cloned the PR branch and I can write simple configs that consume that local nixpkgs like nixpkgs = import /home/myhome/nixpkgs; or nixpkgs.url = "path:/home/myhome/nixpkgs";. I can also install the drupal package using nix-shell -I, but the package is just the unzipped Drupal archive from drupal.org. It doesn’t start up a server or a database, nor does it install PHP.

The PR was built against an old version of nixpkgs (from like last year), so I don’t want to point my system configuration.nix at the local nixpkgs and then just fire off a nixos-rebuild --switch because I think that would probably break something. I suspect making a flake would work, but I’m not totally confident with the structure yet to just spin one up from scratch.

Any advice from package builders and maintainers on how to set this up?

tl;dr
How do I run a service defined in a local version of nixpkgs that is about 6-8 months behind my system’s nixpkgs?

use nixos-rebuild build-vm and test everything inside the vm?

2 Likes

Or rebase the PR and use that as the nixpkgs source.

Or use (import <nixpkgs> {}).applyPatches { ... } to only apply the PR diff (I think that’s the syntax).

1 Like

This worked for me. Here’s what I did.

I created a new minimal system config using nixos-generage-config --dir=/my/vm/config/path.
Then I altered the configuration.nix file as needed. In particular, I added a xfce session so I could debug my vm’s file system with a DE instead of just via CLI.

Then I ran
nixos-rebuild build-vm -I nixpkgs=/path/to/custom/nixpkgs -I nix_path=/path/to/custom/nixpkgs/nixos -I nixos-config=/path/to/vm/configuration.nix

That built a result folder and then I could just run ./result/bin/run-nixos-vm and log into the virtual machine where I can see the derivations I was expecting to see in /nix/store

1 Like

I’ll probably end up doing this just so the merge is clean if/when I submit my changes to nixpkgs, but I think it’s nice to have a healthy separation of concerns with my system config and this test config.