Instant startup time for nix-shell
229
stars
182
commits
Rust
primary language
Nov 24, 2024
updated
cached-nix-shell is a caching layer for nix-shell featuring instant startup time on subsequent runs.
It supports NixOS and Linux.
Install the release version from Nixpkgs:
nix-env -iA nixpkgs.cached-nix-shell
Or, install the latest development version from GitHub:
nix-env -if https://github.com/xzfc/cached-nix-shell/tarball/master
Just replace nix-shell with cached-nix-shell in the shebang line:
#! /usr/bin/env cached-nix-shell
#! nix-shell -i python3 -p python
print("Hello, World!")
Alternatively, call cached-nix-shell directly:
$ cached-nix-shell ./hello.py
$ cached-nix-shell -p python3 --run 'python --version'
Or use the --wrap option for programs that call nix-shell internally.
$ cached-nix-shell --wrap stack build
$ time ./hello.py # first run; no cache used
cached-nix-shell: updating cache
Hello, World!
./hello.py 0.33s user 0.06s system 91% cpu 0.435 total
$ time ./hello.py
Hello, World!
./hello.py 0.02s user 0.01s system 97% cpu 0.029 total
cached-nix-shell stores environment variables set up by nix-shell and reuses them on subsequent runs.
It traces which files are read by nix during an evaluation, and performs a proper cache invalidation if any of the used files are changed.
The cache is stored in ~/.cache/cached-nix-shell/.
The following situations are covered:
builtins.readFile is usedbuiltins.readDir is usedimport ./file.nix is used/etc/nix/nix.conf or ~/.config/nix/nix.conf$NIX_PATH environment variableThe following situations aren't handled by cached-nix-shell and may lead to staled cache:
builtins.fetchurl or other network builtins are used (e.g. in nixpkgs-mozilla)https://discourse.nixos.org/t/speeding-up-nix-shell-shebang/4048
There are related projects focused on using nix-shell for project developing:
nix-shell replacement for project development
nd shell commandRust
56.7%
Shell
28.9%
C
11.6%
Makefile
1.6%
Nix
1.2%
Instant startup time for nix-shell
229
stars
182
commits
Rust
primary language
Nov 24, 2024
updated
cached-nix-shell is a caching layer for nix-shell featuring instant startup time on subsequent runs.
It supports NixOS and Linux.
Install the release version from Nixpkgs:
nix-env -iA nixpkgs.cached-nix-shell
Or, install the latest development version from GitHub:
nix-env -if https://github.com/xzfc/cached-nix-shell/tarball/master
Just replace nix-shell with cached-nix-shell in the shebang line:
#! /usr/bin/env cached-nix-shell
#! nix-shell -i python3 -p python
print("Hello, World!")
Alternatively, call cached-nix-shell directly:
$ cached-nix-shell ./hello.py
$ cached-nix-shell -p python3 --run 'python --version'
Or use the --wrap option for programs that call nix-shell internally.
$ cached-nix-shell --wrap stack build
$ time ./hello.py # first run; no cache used
cached-nix-shell: updating cache
Hello, World!
./hello.py 0.33s user 0.06s system 91% cpu 0.435 total
$ time ./hello.py
Hello, World!
./hello.py 0.02s user 0.01s system 97% cpu 0.029 total
cached-nix-shell stores environment variables set up by nix-shell and reuses them on subsequent runs.
It traces which files are read by nix during an evaluation, and performs a proper cache invalidation if any of the used files are changed.
The cache is stored in ~/.cache/cached-nix-shell/.
The following situations are covered:
builtins.readFile is usedbuiltins.readDir is usedimport ./file.nix is used/etc/nix/nix.conf or ~/.config/nix/nix.conf$NIX_PATH environment variableThe following situations aren't handled by cached-nix-shell and may lead to staled cache:
builtins.fetchurl or other network builtins are used (e.g. in nixpkgs-mozilla)https://discourse.nixos.org/t/speeding-up-nix-shell-shebang/4048
There are related projects focused on using nix-shell for project developing:
nix-shell replacement for project development
nd shell commandRust
56.7%
Shell
28.9%
C
11.6%
Makefile
1.6%
Nix
1.2%