From b6f7b9dda8cd2e4b1c5b006ad5866d3ef7e62310 Mon Sep 17 00:00:00 2001 From: Collin Williams <96917990+bluedragon1221@users.noreply.github.com> Date: Sat, 19 Sep 2026 21:13:32 -0500 Subject: inserting link:css via javascript was a bad idea --- devshell.html | 98 +++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 59 insertions(+), 39 deletions(-) (limited to 'devshell.html') diff --git a/devshell.html b/devshell.html index 59b36af..899e862 100644 --- a/devshell.html +++ b/devshell.html @@ -1,32 +1,51 @@ + + + + + A solution to slow nix-shells - - -
-
+
+
+
+ +
+

A solution to slow nix-shells

+ +
+
+
+

- Tired of waiting for nix-shell to re-download github:NixOS/nixpkgs after you nix-collect-garbage (or just randomly sometimes)? + Tired of waiting for nix-shell to re-download github:NixOS/nixpkgs after you nix-collect-garbage (or just randomly sometimes)? Me too! That's why I went down this rabit hole of making an instant nix shell.

-
+

Table of Contents

+ +

What's wrong with nix-shell?

First, let's clarify what I mean by a nix shell. I'm simply referring to the idea of hiding the packages that you use for development behind a command, and managing those packages using nix. - Most people are familiar with this through the nix-shell or nix shell commands. + Most people are familiar with this through the nix-shell or nix shell commands. (For non-nix people, yes those are in fact two very different things)

- My issue with how nix shell is that it has to redownload your packages if they're not in the nix store (one cause of this would be if you recently ran nix-collect-garbage), and it has to re-evaluate the correct environment variables and packages every time you launch the shell. - These two things together mean that every time you run nix shell, you'll be waiting before you can access those packages. + My issue with how nix shell is that it has to redownload your packages if they're not in the nix store (one cause of this would be if you recently ran nix-collect-garbage), and it has to re-evaluate the correct environment variables and packages every time you launch the shell. + These two things together mean that every time you run nix shell, you'll be waiting before you can access those packages. And, personally, I'd rather spend my time waiting for my code to compile, not waiting to have access to my compiler.

@@ -35,21 +54,21 @@ There's a lot of existing solutions to this problem, but none of them do exactly what I want.

- I used to be a big fan of cached-nix-shell. + I used to be a big fan of cached-nix-shell. It's cool because it (as the name suggests) caches your nix shell, so the next time you start it up, the launch time is instant (it removes the second factor of waiting mentioned in the previous section). But for some reason it breaks for certain packages that rely on paths that might not exist anymore. - For example, I had issues with rustc not working when launched through cached-nix-shell if it was using a cached version. + For example, I had issues with rustc not working when launched through cached-nix-shell if it was using a cached version.

- Another solution that I think too many people fall for is to just install the packages into your system $PATH with environment.systemPackages. + Another solution that I think too many people fall for is to just install the packages into your system $PATH with environment.systemPackages. One of the great things about NixOS is that you don't have to resort to this! - On Arch, if you install a package with pacman, it has to go into your system $PATH. + On Arch, if you install a package with pacman, it has to go into your system $PATH. But on NixOS, we don't have to bloat the system path with our developer dependencies. - This is exactly why nix-shell exists in the first place! + This is exactly why nix-shell exists in the first place!

- The most hardcore-nix-nerd option here is to manually mark your nix-shell as a GC root. - This tells nix-collect-garbage to not remove the path or anything that it depends on, preserving your nix-shells through garbage collection. + The most hardcore-nix-nerd option here is to manually mark your devshell as a GC root. + This tells nix-collect-garbage to not remove the path or anything that it depends on, preserving your devshells through garbage collection. Maybe some day I'll write my own tool that wraps this functionality to provide GC-protected nix shells, but honestly that just sounds like too much work. (for more information about how Garbage Collection works on Nix, check out the Nix Pill about the Garbage Collector)

@@ -64,34 +83,34 @@ In your NixOS config, using home-manager or hjem or whatever, just build a package that launches your shell but with some extra programs.

-
{pkgs, ...}: let
-  rust-shell = let
-    rustProfile = pkgs.buildEnv {
-      name = "rust-profile";
-      paths = with pkgs; [rustc cargo rust-analyzer];
+			
{pkgs, ...}: let
+  rust-shell = let
+    rustProfile = pkgs.buildEnv {
+      name = "rust-profile";
+      paths = with pkgs; [rustc cargo rust-analyzer gcc];
     };
-  in
-    pkgs.writeShellScriptBin "rust-shell" ''
-      export PATH="${rustProfile}/bin:$PATH"
+  in
+    pkgs.writeShellScriptBin "rust-shell" ''
+      export PATH="${rustProfile}/bin:$PATH"
       exec $SHELL
-    '';
+    '';
 
-  py-shell = let
-    pythonProfile = pkgs.python314.withPackages (ps:
-      with ps; [
-        numpy
-        matplotlib
-        pandas
-        jupyter
-        ipython
+  py-shell = let
+    pythonProfile = pkgs.python314.withPackages (ps:
+      with ps; [
+        numpy
+        matplotlib
+        pandas
+        jupyter
+        ipython
       ]);
-  in
-    pkgs.writeShellScriptBin "py-shell" ''
-      export PATH="${pythonProfile}/bin:$PATH"
+  in
+    pkgs.writeShellScriptBin "py-shell" ''
+      export PATH="${pythonProfile}/bin:$PATH"
       exec $SHELL
-    '';
-in {
-  packages = [rust-shell py-shell];
+    '';
+in {
+  packages = [rust-shell py-shell];
 }

Thoughts

@@ -121,6 +140,7 @@ in { In my examples, the Rust one isn't that bad, but the Python one pulls in hundreds of python dependencies into the system closure. This can make rebuilds longer (when the packages need to update) and take up more space on your computer.

+

Even with these trade-offs, I'm willing to pay the price to have instantaneous access to my developer dependencies!

-- cgit v1.3.1