From 6032eb03d55fed4f062365169f4734ca2994cbda Mon Sep 17 00:00:00 2001
From: Tom Prince <tom.prince@private.storage>
Date: Mon, 13 Sep 2021 18:33:02 -0600
Subject: [PATCH] Avoid copying nixpkgs to the store a second time in
 nix-shell.

---
 shell.nix | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/shell.nix b/shell.nix
index ce1add06..fe76c1e7 100644
--- a/shell.nix
+++ b/shell.nix
@@ -3,8 +3,17 @@ let
 in
 { pkgs ? release2105 }:
 pkgs.mkShell {
+  # When a path (such as `pkgs.path`) is interpolated into a string then nix
+  # first adds that path to the store, and then interpolates the store path
+  # into the string.  We use `builtins.toString` to convert the path to a
+  # string without copying it to the store before interpolating. Either the
+  # path is already in the store (e.g. when `pkgs` is `release2105`) so we
+  # avoid making a second copy with a longer name, or the user passed in local
+  # path (e.g. a checkout of nixpkgs) and we point at it directly, rather than
+  # a snapshot of it.
+  # See https://github.com/NixOS/nix/issues/200 and https://github.com/NixOS/nix/issues/1728
   shellHook = ''
-    export NIX_PATH="nixpkgs=${pkgs.path}";
+    export NIX_PATH="nixpkgs=${builtins.toString pkgs.path}";
   '';
   buildInputs = [
     pkgs.morph
-- 
GitLab