Skip to content

Instantly share code, notes, and snippets.

@zimbatm
Last active January 31, 2019 11:16
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zimbatm/ecd682d9175275c09ed9764e790b753e to your computer and use it in GitHub Desktop.
Save zimbatm/ecd682d9175275c09ed9764e790b753e to your computer and use it in GitHub Desktop.
Usage: callPackage [path] [...nix-build args]
#!/usr/bin/env bash
#
# Usage: callPackage [src] [...nix-build args]
#
# A version of nix-build that uses nixpkgs.callPackage to fill in the
# arguments.
#
# * [src] can be a path or a URL. Defaults to .
#
# Example:
#
# callPackage https://github.com/direnv/direnv/archive/master.tar.gz
#
# Let's say you are hacking on pkgs/applications/misc/hello/default.nix
# The problem is that default.nix takes a number of arguments and thus cannot
# be called with nix-build directly. So first you have to edit
# pkgs/top-level/all-packages.nix and figure out which attribute the package
# maps to, then call `nix-build -A hello` on the repo root.
#
# Instead, use `callPackage pkgs/applications/misc/hello/default.nix`. You
# might already be in the `pkgs/applications/misc/hello` folder in which case
# `callPackage` is enough.
set -uo pipefail
src=${1:-}
shift
exec nix-build \
--no-out-link \
-I "src=$src" \
--expr '(import <nixpkgs> {}).callPackage <src> {}' \
"$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment