Before I moved to NixOS, my workflow for hacking on an existing project would look something like this:
- Clone a repository
- Install any build tools the README tells me I need and hope I don’t have tooling version issues
- Run the build and hope it works
- 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:
- Clone a repository
- Create a
shell.nix
file in my working copy with contentswith import <nixpkgs> {}; attr-name-for-this-package
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.
- Create a
shell.nix
file in my working copy with contentswith import <nixpkgs> {}; attr-name-for-this-package.overrideAttrs (oldAttrs: { src = []; })
nix-shell
export src=$PWD
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?
phases="patchPhase configurePhase buildPhase" genericBuild
- Edit files
- 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?