Skip to content

Instantly share code, notes, and snippets.

Created April 12, 2020 03:10
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save gnprice/ab0d9a6d97bec5c9a0f3813b8f57c8c9 to your computer and use it in GitHub Desktop.
{ attr
# Scaffold to build just one package with modified stdenv scripts.
# Dependencies come unmodified from <nixpkgs>, including the stdenv's
# toolchain. This is useful for (a) iterating quickly on changes to
# stdenv scripts (like, and (b) more easily comparing the
# build log against a baseline, by keeping inputs' paths the same so
# that any changes caused by changes in the scripts' behavior stand out.
# Usage:
# $ nix-shell -p $(nix-build $(nix-instantiate sample.nix \
# --argstr attr netmask))
devpkgs = import ./. { };
nixpkgs = import <nixpkgs> { };
inherit (devpkgs) lib;
# Graft the scripts from one stdenv onto the toolchain from another.
graftStdenv = base: scripts: scripts.override {
inherit (base) initialPath cc shell extraNativeBuildInputs;
allowedRequisites =
if base ? allowedRequisites then
builtins.filter (p: !(lib.hasSuffix ".sh" p))
else null;
devStdenv = graftStdenv nixpkgs.stdenv devpkgs.stdenv;
(lib.getAttrFromPath (lib.splitString "." attr) nixpkgs).override (
old: {
stdenv = graftStdenv old.stdenv devpkgs.stdenv;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment