Skip to content

Instantly share code, notes, and snippets.

@Profpatsch
Created April 7, 2019 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Profpatsch/bebada9cb0baf418939e3b1522eb0ad6 to your computer and use it in GitHub Desktop.
Save Profpatsch/bebada9cb0baf418939e3b1522eb0ad6 to your computer and use it in GitHub Desktop.
with import <nixpkgs> {};
let nixBin = "${pkgs.nix}/bin"; in
runCommand "foo" {}
''
set -e
datadir="${pkgs.nix}/share"
export TEST_ROOT=$(pwd)/test-tmp
export NIX_BUILD_HOOK=
export NIX_CONF_DIR=$TEST_ROOT/etc
export NIX_DB_DIR=$TEST_ROOT/db
export NIX_LOCALSTATE_DIR=$TEST_ROOT/var
export NIX_LOG_DIR=$TEST_ROOT/var/log/nix
export NIX_MANIFESTS_DIR=$TEST_ROOT/var/nix/manifests
export NIX_STATE_DIR=$TEST_ROOT/var/nix
export NIX_STORE_DIR=$TEST_ROOT/store
export PAGER=cat
cacheDir=$TEST_ROOT/binary-cache
${nix}/bin/nix-store --init
cat > drv.nix <<EOF
derivation {
name = "foo";
system = ${pkgs.lib.strings.escapeNixString system};
# /bin/sh is magically accessible to nix,
# it is added to the build sandbox (with all runtime deps).
builder = "/bin/sh";
args = [ "-c" "echo $love && echo foo > \$out" ];
}
EOF
${nixBin}/nix-instantiate drv.nix > drv
output=$(${nixBin}/nix-store --realize $(<drv))
touch $out
''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment