How to look up a Nix package's Nix store path from flake inputs
Published on , 710 words, 3 minutes to read

Sometimes God is dead and you need to figure out what the version of a package
in your Nix flake's inputs is. With flakes, you can figure this out using nix eval on a flake reference, but what the hecc is a flake reference?
Every URL has a "fragment", or the thing after the # that mainly tells the
browser where to scroll to. Nix flakes uses this to allow you to sub-index on
flakes by either name or URL. This allows you to address packages like tmux as:
nixpkgs#legacyPackages.x86_64-linux.tmux
Or my site's code as:
github:Xe/site#packages.x86_64-linux.default
Or even some arbitrary git repo:
git+https://tulpa.dev/cadey/printerfacts.git?ref=main#defaultPackage.x86_64-linux
$ nix flake show github:Xe/site
github:Xe/site/5a50cacef85c9e3b9695a2749359b27d0530f86a
├───devShell
│ ├───aarch64-linux: development environment 'nix-shell'
│ └───x86_64-linux: development environment 'nix-shell'
├───nixosModules
│ ├───aarch64-linux: NixOS module
│ └───x86_64-linux: NixOS module
└───packages
├───aarch64-linux
│ ├───bin: package 'xesite-2.4.0'
│ ├───config: package 'xesite-config-2.4.0'
│ ├───default: package 'xesite-2.4.0'
│ ├───posts: package 'xesite-posts-2.4.0'
│ └───static: package 'xesite-static-2.4.0'
└───x86_64-linux
├───bin: package 'xesite-2.4.0'
├───config: package 'xesite-config-2.4.0'
├───default: package 'xesite-2.4.0'
├───posts: package 'xesite-posts-2.4.0'
└───static: package 'xesite-static-2.4.0'
You can use the nix eval --raw command to figure out what the nix store path
of those packages either is or would be:
$ nix eval --raw nixpkgs#legacyPackages.x86_64-linux.tmux
/nix/store/3mn362yak70vq137wnryi7whgvq2cmn2-tmux-3.3a
$ nix eval --raw github:Xe/site#packages.x86_64-linux.default
/nix/store/v3lwgh6vk03yw3aq3j398g613ff3gja0-xesite-2.4.0
$ nix eval --raw git+https://tulpa.dev/cadey/printerfacts.git'?'ref=main#defaultPackage.x86_64-linux
/nix/store/7df21bqkrx2csazc2s8ji8chaabbpqhs-printerfacts-0.3.1
However, this operates on the latest version by default. It won't operate on the
current version in your Nix flake. If you need to find it out from the current
flake, pass the --inputs-from flag with the current directory .:
$ nix eval --inputs-from . --raw nixpkgs#legacyPackages.x86_64-linux.tmux
/nix/store/5sz57bwrlwhv1l8h4c4sq1bl1fhmcwfw-tmux-3.3a
This will use the nixpkgs defined in your current directory's flake.lock
file. You can then share that store path with people to share in your tale of
woe as to why a service is crashing when you try and update it.
$ nix flake show github:Xe/site/5a50cacef85c9e3b9695a2749359b27d0530f86a
github:Xe/site/5a50cacef85c9e3b9695a2749359b27d0530f86a
├───devShell
│ ├───aarch64-linux: development environment 'nix-shell'
│ └───x86_64-linux: development environment 'nix-shell'
├───nixosModules
│ ├───aarch64-linux: NixOS module
│ └───x86_64-linux: NixOS module
└───packages
├───aarch64-linux
│ ├───bin: package 'xesite-2.4.0'
│ ├───config: package 'xesite-config-2.4.0'
│ ├───default: package 'xesite-2.4.0'
│ ├───posts: package 'xesite-posts-2.4.0'
│ └───static: package 'xesite-static-2.4.0'
└───x86_64-linux
├───bin: package 'xesite-2.4.0'
├───config: package 'xesite-config-2.4.0'
├───default: package 'xesite-2.4.0'
├───posts: package 'xesite-posts-2.4.0'
└───static: package 'xesite-static-2.4.0'
Facts and circumstances may have changed since publication. Please contact me before jumping to conclusions if something seems wrong or unclear.
Tags: nix, nixos, flakes