Skip to content

Instantly share code, notes, and snippets.

@Frontear
Last active October 8, 2025 14:01
Show Gist options
  • Select an option

  • Save Frontear/bfd0ea48461229fbd191ffe15412ebfc to your computer and use it in GitHub Desktop.

Select an option

Save Frontear/bfd0ea48461229fbd191ffe15412ebfc to your computer and use it in GitHub Desktop.
Some of the erroneous behavior of Nix

String interpolating a relative or absolute path value will cause Nix to copy the contents at that path to the store before constructing the string. (NixOS/nix#9428)

  • This has I/O implications for evaluation times, especially for large files/directories
  • This will error out if the path does not exist or if the user lacks permissions to view it
  • In a flake-controlled project (which is already copied as part of evaluation), this creates duplicate store objects

Solutions:

  • Avoid string interpolating path values. Use builtins.toString if you need the values to be a string.
  • Avoid using path values in general, and prefer using a generic string ("/var/empty" instead of /var/empty)
nix-repl> "${/var/empty}"
"/nix/store/<hash>-empty"

nix-repl> toString /var/empty
"/var/empty"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment