From 45dd7ec87849ff3dc1c2c14b2a910597671d9aeb Mon Sep 17 00:00:00 2001 From: figsoda Date: Wed, 22 Jul 2026 15:29:56 -0400 Subject: [PATCH] avoid copying nixpkgs to the store --- README.md | 4 ++-- src/__pathToString.nix | 15 +++++++++++++++ src/callPackage.nix | 2 +- src/crate2nix.nix | 2 +- 4 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 src/__pathToString.nix diff --git a/README.md b/README.md index b847037..9f1f965 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,7 @@ drowse.instantiate (finalAttrs: { version = "${finalAttrs.version}"; } ''; - env.NIX_PATH = "nixpkgs=${path}"; + env.NIX_PATH = "nixpkgs=${nixpkgs}"; dontUnpack = true; }) ``` @@ -147,7 +147,7 @@ drowse.mkDynamicDerivation { version = "0.3.3"; nativeBuildInputs = [ nix ]; - env.NIX_PATH = "nixpkgs=${path}"; + env.NIX_PATH = "nixpkgs=${nixpkgs}"; buildCommand = '' drv=$(nix-instantiate --expr "(import { }).nix-init") diff --git a/src/__pathToString.nix b/src/__pathToString.nix new file mode 100644 index 0000000..102b74f --- /dev/null +++ b/src/__pathToString.nix @@ -0,0 +1,15 @@ +# avoid copying stuff to the store when possible + +{ lib }: + +path: + +if !lib.isDerivation path && lib.isStorePath path then + let + str = toString path; + in + builtins.appendContext str { + ${str}.path = true; + } +else + "${path}" diff --git a/src/callPackage.nix b/src/callPackage.nix index 14187b0..bc32f64 100644 --- a/src/callPackage.nix +++ b/src/callPackage.nix @@ -40,7 +40,7 @@ lib.extendMkDerivation { ''; env = { - NIX_PATH = "nixpkgs=${path}"; + NIX_PATH = "nixpkgs=${super.pathToString path}"; } // env; diff --git a/src/crate2nix.nix b/src/crate2nix.nix index 2528960..f2097a7 100644 --- a/src/crate2nix.nix +++ b/src/crate2nix.nix @@ -73,7 +73,7 @@ lib.extendMkDerivation { ''; env = { - NIX_PATH = "nixpkgs=${path}"; + NIX_PATH = "nixpkgs=${super.pathToString path}"; } // env;