Advice for configuring dependencies for nix users for OSS project contribution

Howdy folks.
I would like to know the best way to declare dependencies for an OSS project so nix users can contribute seamlessly.
I’ve noticed various projects include a default.nix file that developers can load with nix-shell.
I took that approach for tectonic:

# invoke with latest sources
# nix-shell -I nixpkgs= dist/nixos/default.nix
with import <nixpkgs> {};

pkgs.mkShell {
  buildInputs = [

I also see that tectonic has been packaged in nixpkgs. To avoid duplication it seems best to rely upon nixpkg’s upstream definition as canonical.

How would I consume nixpkg’s package definition easily from within the project so I do not duplicate the needed dependencies?

1 Like
nix-shell -A tectonic

… but the thing is that devs often want to modify the expression, but I suppose you could write a shell.nix like this

with import <nixpkgs> {};

tectonic.overrideAttrs (a: {
  # ...
1 Like

Hmm, nix-shell -A tectonic fails for me:

» nix-shell -A tectonic
error: attribute 'tectonic' in selection path 'tectonic' not found

I’m on macOS using nix 2.2.
Putting the override into a snippet and invoking nix-shell does work; thanks!

Well, normal attribute names need to be prepended by the name you gave to your channel, on macOS probably nixpkgs.tectonic then.

I didn’t realize I need to pass the specific nixpkgs as the first argument to nix-shell:

# use the default, bundles older version of rust
$ nix-shell '<nixpkgs>' -A tectonic
# target the latest version of nixpkgs
$ nix-shell -A tectonic

Yay for the examples section in the manual!
I’m sure there are plenty of nuances here I gloss over but the basic nix-shell -A tectonic is exactly what I needed for documenting how to build the project when consuming dependencies with nix.