Unclear "unexpected end-of-file" error message with basic flake.nix

I have the following innocent-looking flake.nix file:

{
  inputs = { flake-utils.url = "github:numtide/flake-utils"; };

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      let pkgs = nixpkgs.legacyPackages."${system}"; in
      { devShell = pkgs.mkShell { nativeBuildInputs = [ pkgs.hello ]; }; });
}

but when I run nix develop it complains:

❯ nix develop             
error: unexpected end-of-file

AFAICT my flake.nix is valid nix. Running with --verbose and --show-trace flags doesn’t change the output.

Why am I seeing this error? And why does it not clarify what the exact parse error is?

In fact I can make the reproduction even simpler:

{
  inputs = { flake-utils.url = "github:numtide/flake-utils"; };

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      {
        devShell = nixpkgs.legacyPackages."${system}".mkShell { };
      });
}
1 Like

Not sure off the top of my head, but you can add multiple verbose flags (up to 5 iirc) for more verbosity (easiest as -vv and so on). Maybe one of those will clarify what it’s doing when it breaks.

1 Like

Thanks @abathur ! I tried running with maximum verbosity (full log posted here), but oddly I’m only left with more questions!

The last few lines look relatively innocuous to my untrained eye:

building of '/nix/store/hyqg2r0xmxvz8xrnhxgcgwy57zn9zk8f-nix-shell-env.drv!*' from .drv file: loading derivation
acquiring write lock on '/nix/var/nix/temproots/96032'
downgrading to read lock on '/nix/var/nix/temproots/96032'
building of '/nix/store/hyqg2r0xmxvz8xrnhxgcgwy57zn9zk8f-nix-shell-env.drv!*' from .drv file: have derivation
substitution of 'sha256:60dac55dd52f83679561b3d6b57dc7741682e8e0b75e66e48e5cf1786e78f327!out': created
substitution of 'sha256:60dac55dd52f83679561b3d6b57dc7741682e8e0b75e66e48e5cf1786e78f327!out': woken up
substitution of 'sha256:60dac55dd52f83679561b3d6b57dc7741682e8e0b75e66e48e5cf1786e78f327!out': init
closing daemon connection because of an exception
error: unexpected end-of-file

Perhaps I’m missing something?

Found a further simplification, this time removing the dependence on flake-utils:

{
  outputs = { self, nixpkgs }:
    { devShell.aarch64-darwin = nixpkgs.legacyPackages.aarch64-darwin.mkShell { }; };
}

This is really starting to smell like a bug to me…

Created Simple flake.nix works on x86_64-linux but errors on aarch64-darwin · Issue #8705 · NixOS/nix · GitHub to track this issue

2 Likes

This kind of errors is usually caused by a broken store path or tarball cache.

Please clear your nix related caches of involved users ($HOME/.cache/nix) and also run a store-check (sudo nix-store --verify --check-contents --repair).

2 Likes

I just ran

rm -rf $HOME/.cache/nix
sudo nix-store --verify --check-contents --repair

The nix-store repair did find some broken entries in the store, which I find to be very odd, but repairing them and removing the cache has not had any impact on nix develop’s behavior :frowning:

2 Likes

I get the same error when trying to run

nix-build  -A <MY-PROGRAM> --substituters ssh://<MY-REMOTE-BUILDER-MACHINE>

...

closing daemon connection because of an exception
error: unexpected end-of-file