Nix flake and fetcher-cache-v1.sqlite

I’m trying to follow the wiki instructions with NixOS and start using flakes, but I’m running into so many errors I think I’ve missed some important prerequisite.

I’m on nixos-unstable.

I added the

{ pkgs, ... }: {
   nix = {
    package = pkgs.nixUnstable;
    extraOptions = ''
      experimental-features = nix-command flakes
    '';
   };
}

to my configuration.nix and that rebuilt fine. But the example command from the Tweag tutorial fails:

marcus@ione> nix shell github:edolstra/dwarffs --command dwarffs --version                                          
error: --- Error ------------------------------------------------------------------------------------------------------------------- nix
cannot open SQLite database '/home/marcus/.cache/nix/fetcher-cache-v1.sqlite'

That DB does not exist. I thought I would be cunning, went and found the DB’s schema in the nix source and create the DB myself. With the flakes-enabled version of nix:

marcus@ione> nix run nixpkgs.sqlite                                                                                                   
error: --- SysError ---------------------------------------------------------------------------------------------------------------- nix
getting status of '/home/marcus/nixpkgs.sqlite': No such file or directory
marcus@ione> nix-shell -p sqlite3                                                                                                 
error: --- UndefinedVarError ------------------------------------------------------------------------------------------------- nix-shell
at: (1:94) from string

     1| with import <nixpkgs> { }; (pkgs.runCommandCC or pkgs.runCommand) "shell" { buildInputs = [ (sqlite3) ]; } ""
      |                                                                                              ^

undefined variable 'sqlite3'
(use '--show-trace' to show detailed location information)

The above command has a typo, should have been sqlite, not sqlite3. Note the different error when I use the correct attribute:

marcus@ione> nix run nixpkgs.sqlite                                                                                                   
error: --- SysError ---------------------------------------------------------------------------------------------------------------- nix
getting status of '/home/marcus/nixpkgs.sqlite': No such file or directory

So I rolled back to a previous NixOS generation, got the database created, went back to the current generation with flakes enabled, but still:

marcus@ione> nix shell github:edolstra/dwarffs --command dwarffs --version                                                      
error: --- SQLiteError ------------------------------------------------------------------------------------------------------------- nix
executing SQLite statement 'insert or replace into Cache(input, info, path, immutable, timestamp) values (?, ?, ?, ?, ?)': attempt to write a readonly database (in '/home/marcus/.cache/nix/fetcher-cache-v1.sqlite')

chmod 777 on the DB, still same error.

Lots of people seem to be using flakes already, so I guess I’m doing something wrong, anyone got any advice?

It was so damn obvious. ~/.cache/nix was owned by root. sudo chown marcus:users ~/.cache/nix/ and it looks like everything is working now.

2 Likes

Hey I’m getting the same issue can you help me with this I’m new to nix.

Have you checked the permissions from /Users/rishabhmathur/.cache/nix? In my case, I had a similar issue as described by @marcus7070 (the eval-cache-v3 directory was owned by root)

1 Like