Development workflow for a project already in Nixpkgs

Before I moved to NixOS, my workflow for hacking on an existing project would look something like this:

  1. Clone a repository
  2. Install any build tools the README tells me I need and hope I don’t have tooling version issues
  3. Run the build and hope it works
  4. Edit files, run incremental builds, do VCS archaeology, and generally iterate on my working tree until the program does what I want

Now I’m on NixOS, and I would expect to get a lot of help with steps 2 and 3 from Nix, particularly with projects that are already in Nixpkgs. I want there to be a nice way for me to use nix-shell to replicate the environment that Nixpkgs uses to build the project, but running the build on my local working copy instead of some virgin tarball pulled from the internet.

So here’s my attempt:

  1. Clone a repository
  2. Create a shell.nix file in my working copy with contents with import <nixpkgs> {}; attr-name-for-this-package
  3. nix-shell

… Okay, that seems to have created a new copy of the un-hacked-up source files in a local directory named source. And then running genericBuild builds the files in that directory. Makes sense, but not what I want.

  1. Create a shell.nix file in my working copy with contents with import <nixpkgs> {}; attr-name-for-this-package.overrideAttrs (oldAttrs: { src = []; })
  2. nix-shell
  3. export src=$PWD
  4. genericBuild

… Nope, that kicks me out of nix-shell with do not know how to unpack source archive <my current directory>. Okay. We don’t need to unpack anything, so can we omit the unpack phase?

  1. phases="patchPhase configurePhase buildPhase" genericBuild
  2. Edit files
  3. Get an incremental rebuild with phases="buildPhase" genericBuild

This seems to work!

Is this how developers on NixOS do it? Seems fragile; have I missed any important steps here? Is this likely to stop working in the future or on some other project? Is there a more robust way to do any of the above steps, or to achieve the goal via some other means?

Usually I use nix-shell "<nixpkgs>" -A packageName to get PATH, LIBRARY_PATH, etc. populated and just run the required build-commands interactively (./configure, make or cmake, …). I don’t bother with using the phases that get defined by nix.

I haven’t yet used it, but for flakes you should be able to use nix develop nixpkgs#package to achieve the same.


Thank you! I clearly didn’t read the nix-shell man page closely enough; from some wiki page or blog post or something I was sure I needed a shell.nix file to do this, but that invocation pattern does exactly what I want and it’s plain as day in the docs.