{"id":13798793,"url":"https://github.com/xzfc/cached-nix-shell","last_synced_at":"2025-04-08T09:07:56.134Z","repository":{"id":62438730,"uuid":"209327963","full_name":"xzfc/cached-nix-shell","owner":"xzfc","description":"Instant startup time for nix-shell","archived":false,"fork":false,"pushed_at":"2024-11-24T23:00:19.000Z","size":278,"stargazers_count":217,"open_issues_count":8,"forks_count":17,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-01T07:49:52.162Z","etag":null,"topics":["nix","nix-shell"],"latest_commit_sha":null,"homepage":"https://xzfc.github.io/cached-nix-shell/cached-nix-shell.1","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xzfc.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.MIT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-18T14:23:00.000Z","updated_at":"2025-03-18T21:49:02.000Z","dependencies_parsed_at":"2024-01-29T07:28:07.355Z","dependency_job_id":"504a54da-84a6-474d-ae4d-31a1cb8ee0c4","html_url":"https://github.com/xzfc/cached-nix-shell","commit_stats":{"total_commits":176,"total_committers":8,"mean_commits":22.0,"dds":"0.051136363636363646","last_synced_commit":"62e282be819646e3cdcd458af3f222e8f09e62ca"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xzfc%2Fcached-nix-shell","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xzfc%2Fcached-nix-shell/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xzfc%2Fcached-nix-shell/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xzfc%2Fcached-nix-shell/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xzfc","download_url":"https://codeload.github.com/xzfc/cached-nix-shell/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247809962,"owners_count":20999816,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nix","nix-shell"],"created_at":"2024-08-04T00:00:53.695Z","updated_at":"2025-04-08T09:07:56.114Z","avatar_url":"https://github.com/xzfc.png","language":"Rust","funding_links":[],"categories":["Rust","Development"],"sub_categories":["Discovery"],"readme":"# cached-nix-shell\n[![Build Status](https://img.shields.io/github/actions/workflow/status/xzfc/cached-nix-shell/test.yml?branch=master\u0026logo=github)](https://github.com/xzfc/cached-nix-shell/actions/workflows/test.yml?query=branch%3Amaster)\n![License](https://img.shields.io/badge/license-Unlicense%20OR%20MIT-blue)\n[![Nixpkgs unstable package](https://repology.org/badge/version-for-repo/nix_unstable/cached-nix-shell.svg)](https://nixos.org/nixos/packages.html?attr=cached-nix-shell\u0026channel=nixpkgs-unstable\u0026query=cached-nix-shell)\n[![Man page](https://img.shields.io/badge/man-cached--nix--shell%281%29-blue)](https://xzfc.github.io/cached-nix-shell/cached-nix-shell.1)\n\n`cached-nix-shell` is a caching layer for `nix-shell` featuring instant startup time on subsequent runs.\n\nIt supports NixOS and Linux.\n\n## Installation\n\nInstall the release version from Nixpkgs:\n```sh\nnix-env -iA nixpkgs.cached-nix-shell\n```\n\nOr, install the latest development version from GitHub:\n```sh\nnix-env -if https://github.com/xzfc/cached-nix-shell/tarball/master\n```\n\n## Usage\n\nJust replace `nix-shell` with `cached-nix-shell` in the shebang line:\n\n```python\n#! /usr/bin/env cached-nix-shell\n#! nix-shell -i python3 -p python\nprint(\"Hello, World!\")\n```\n\nAlternatively, call `cached-nix-shell` directly:\n\n```sh\n$ cached-nix-shell ./hello.py\n$ cached-nix-shell -p python3 --run 'python --version'\n```\n\nOr use the `--wrap` option for programs that call `nix-shell` internally.\n\n```sh\n$ cached-nix-shell --wrap stack build\n```\n\n## Performance\n\n```\n$ time ./hello.py # first run; no cache used\ncached-nix-shell: updating cache\nHello, World!\n./hello.py  0.33s user 0.06s system 91% cpu 0.435 total\n$ time ./hello.py\nHello, World!\n./hello.py  0.02s user 0.01s system 97% cpu 0.029 total\n```\n\n## Caching and cache invalidation\n\n`cached-nix-shell` stores environment variables set up by `nix-shell` and reuses them on subsequent runs.\nIt [traces](./nix-trace) which files are read by `nix` during an evaluation, and performs a proper cache invalidation if any of the used files are changed.\nThe cache is stored in `~/.cache/cached-nix-shell/`.\n\nThe following situations are covered:\n\n* `builtins.readFile` is used\n* `builtins.readDir` is used\n* `import ./file.nix` is used\n* updating `/etc/nix/nix.conf` or `~/.config/nix/nix.conf`\n* updating nix channels\n* updating `$NIX_PATH` environment variable\n\nThe following situations aren't handled by `cached-nix-shell` and may lead to staled cache:\n\n* `builtins.fetchurl` or other network builtins are used (e.g. in [nixpkgs-mozilla])\n\n[nixpkgs-mozilla]: https://github.com/mozilla/nixpkgs-mozilla\n\n## Related\n\n* https://discourse.nixos.org/t/speeding-up-nix-shell-shebang/4048\n* There are related projects focused on using `nix-shell` for project developing:\n  * [direnv](https://direnv.net/) with [use_nix](https://github.com/direnv/direnv/wiki/Nix)\n  * [Cached and Persistent Nix shell with direnv integration](https://gist.github.com/mbbx6spp/731076cb8fc620b064b8e5b28fb1c796)\n  * [lorri](https://github.com/nix-community/lorri), a `nix-shell` replacement for project development\n    * [lorri #167](https://github.com/target/lorri/issues/167)\n  * [nix-develop](https://gitlab.com/mightybyte/nix-develop), universal build tool featuring cached `nd shell` command\n\n* [https://github.com/rycee/home-manager/issues/447](https://github.com/rycee/home-manager/issues/447)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxzfc%2Fcached-nix-shell","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxzfc%2Fcached-nix-shell","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxzfc%2Fcached-nix-shell/lists"}