More tests
Test 1 (throws `expected a string but got a thunk`)
$ git status
On branch main
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: asdfasdf.nix
new file: flake.nix
new file: shell.nix
$ cat flake.nix
{
description = "my project description";
inputs.flake-utils.url = import ./asdfasdf.nix;
outputs =
{ self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem
(system:
let pkgs = nixpkgs.legacyPackages.${system}; in
{
devShells.default = import ./shell.nix { inherit pkgs; };
}
);
}
$ cat asdfasdf.nix
"github:numtide/flake-utils"
$ nix develop .
warning: Git tree '/home/srghma/projects/hello' is dirty
error: expected a string but got a thunk at /nix/store/ny5h4254c0x95xv6nniqq89q83vpw0a7-source/flake.nix:24:1
(use '--show-trace' to show detailed location information)
Test 2 (throws errors, unless all used nix files are in repo and git added)
flake.nix
{
inputs.flake-utils.url = "github:numtide/flake-utils";
# WILL THROW WITH ERROR
#
# ✘ ~/projects/hello main ±✚ nix develop .
# warning: Git tree '/home/srghma/projects/hello' is dirty
# error: anonymous function at /nix/store/pphykv9fdgj8vb6zsd1vn1mam1am0y8y-source/asdfasdf.nix:1:1 called without required argument 'nixpkgs'
#
# at /nix/store/pphykv9fdgj8vb6zsd1vn1mam1am0y8y-source/flake.nix:3:19:
#
# 2| inputs.flake-utils.url = "github:numtide/flake-utils";
# 3| outputs = args: import ./asdfasdf.nix args;
# | ^
# 4| }
#
# outputs = args: import ./asdfasdf.nix args;
# WORKS (but all files should be `git add`ed)
#
# If they are not added, then
#
# ✘ ~/projects/hello main ✚ nix develop .
# warning: Git tree '/home/srghma/projects/hello' is dirty
# warning: creating lock file '/home/srghma/projects/hello/flake.lock'
# warning: Git tree '/home/srghma/projects/hello' is dirty
# error: getting status of '/nix/store/20w3fp4x5v37z8waql91vvq77rmbpw5n-source/asdfasdf.nix': No such file or directory
# (use '--show-trace' to show detailed location information)
#
# ✘ ~/projects/hello main ✚ ga asdfasdf.nix
#
# ~/projects/hello main ±✚ nix develop .
# warning: Git tree '/home/srghma/projects/hello' is dirty
# error: getting status of '/nix/store/wcdk1h7x83km048qmnxqys2ghaiisa3g-source/shell.nix': No such file or directory
# (use '--show-trace' to show detailed location information)
outputs = { self, nixpkgs, flake-utils }@args: import ./asdfasdf.nix args;
# THROWS ERROR
#
# ✘ ~/projects/hello main ✚ nix develop .
# warning: Git tree '/home/srghma/projects/hello' is dirty
# warning: creating lock file '/home/srghma/projects/hello/flake.lock'
# warning: Git tree '/home/srghma/projects/hello' is dirty
# error: access to absolute path '/nix/store/asdfasdf.nix' is forbidden in pure eval mode (use '--impure' to override)
# (use '--show-trace' to show detailed location information)
#
# outputs = { self, nixpkgs, flake-utils }@args: import ../asdfasdf.nix args;
# THROWS ERROR TOO
#
# ~/projects/hello main ✚ nix develop .
# warning: Git tree '/home/srghma/projects/hello' is dirty
# error: access to absolute path '/home/srghma/projects/asdfasdf.nix' is forbidden in pure eval mode (use '--impure' to override)
# (use '--show-trace' to show detailed location information)
#
# outputs = { self, nixpkgs, flake-utils }@args: import /home/srghma/projects/asdfasdf.nix args;
}
Summary
1.
IF output is trying to import ../some-file-from-outside-git-repo.nix
THEN nix build .
will throw error access to absolute path is forbidden
This is a meaning of self-contained
/ hermetic evaluation
(taken from frase Note that any file that is not tracked by Git is invisible during Nix evaluation, in order to ensure hermetic evaluation)
2. (based on test 2) it seems like nix is using the git database as a cache to find anwser on question
Do I need to evaluate flake.nix at all? OR I will just use
flake.lock
?
(seems weird that nix cannot do this without git)
Am I right?