DeterminateSystems / nix-installer

Install Nix and flakes with the fast and reliable Determinate Nix Installer, with over 2 million installs.
GNU Lesser General Public License v2.1
2.01k stars 52 forks source link

macos fresh install - `cannot open SQLite database` #632

Open billyogat opened 12 months ago

billyogat commented 12 months ago

After a clean install I'm unable to run echo "Hello Nix" | nix run "nixpkgs#ponysay" in step 2 of the quick start guide.

Environment info:

macOS 13.5.2
MacBook Pro - Apple M1 Pro

Example command execution after an uninstall and reinstall:

❯ curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install

info: downloading installer (https://install.determinate.systems/nix/tag/v0.11.0/nix-installer-aarch64-darwin)
`nix-installer` needs to run as `root`, attempting to escalate now via `sudo`...
Nix install plan (v0.11.0)
Planner: macos (with default settings)

Planned actions:
* Create an encrypted APFS volume `Nix Store` for Nix on `disk3` and add it to `/etc/fstab` mounting on `/nix`
* Fetch `https://releases.nixos.org/nix/nix-2.17.0/nix-2.17.0-aarch64-darwin.tar.xz` to `/nix/temp-install-dir`
* Create a directory tree in `/nix`
* Move the downloaded Nix into `/nix`
* Create build users (UID 300-332) and group (GID 30000)
* Configure Time Machine exclusions
* Setup the default Nix profile
* Place the Nix configuration in `/etc/nix/nix.conf`
* Configure the shell profiles
* Configure Nix daemon related settings with launchctl
* Remove directory `/nix/temp-install-dir`

Proceed? ([Y]es/[n]o/[e]xplain): y
 INFO Step: Create an encrypted APFS volume `Nix Store` for Nix on `disk3` and add it to `/etc/fstab` mounting on `/nix`
 INFO Step: Provision Nix
 INFO Step: Create build users (UID 300-332) and group (GID 30000)
 INFO Step: Configure Time Machine exclusions
 INFO Step: Configure Nix
 INFO Step: Configure Nix daemon related settings with launchctl
 INFO Step: Remove directory `/nix/temp-install-dir`
Nix was installed successfully!
To get started using Nix, open a new shell or run `. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh`

❯ . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh

❯ nix --version
nix (Nix) 2.17.0

❯ echo "Hello Nix" | nix run "nixpkgs#ponysay"
error: cannot open SQLite database '/Users/scott/.cache/nix/fetcher-cache-v1.sqlite': unable to open database file

If there is additional information you need let me know.

Thanks for the help!

billyogat commented 12 months ago

Running as sudo works; echo "Hello Nix" | sudo nix run "nixpkgs#ponysay".

Is that the expected workflow?

Is it expected that root is the owner of ~/.cache/nix?

Hoverbear commented 12 months ago

That is unexpected. I'll try to reproduce.

We don't create a ~/.cache directory, the installer runs as root, and won't manipulate your user homedir.

Hoverbear commented 12 months ago

I'm unfortunately not able to reproduce this.

Here I check to see I have no existing nix related things in my homedir:

ephemeraladmin@mac-epic-turducken ~ % ls ~/.cache ~/.local/state/nix ~/.nix-profile
ls: /Users/ephemeraladmin/.cache: No such file or directory
ls: /Users/ephemeraladmin/.local/state/nix: No such file or directory
ls: /Users/ephemeraladmin/.nix-profile: No such file or directory

Proceeding with install:

ephemeraladmin@mac-epic-turducken ~ % curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install
info: downloading installer https://install.determinate.systems/nix/tag/v0.11.0/nix-installer-aarch64-darwin
`nix-installer` needs to run as `root`, attempting to escalate now via `sudo`...
Nix install plan (v0.11.0)
Planner: macos (with default settings)

Planned actions:
* Create an APFS volume `Nix Store` for Nix on `disk3` and add it to `/etc/fstab` mounting on `/nix`
* Fetch `https://releases.nixos.org/nix/nix-2.17.0/nix-2.17.0-aarch64-darwin.tar.xz` to `/nix/temp-install-dir`
* Create a directory tree in `/nix`
* Move the downloaded Nix into `/nix`
* Create build users (UID 300-332) and group (GID 30000)
* Configure Time Machine exclusions
* Setup the default Nix profile
* Place the Nix configuration in `/etc/nix/nix.conf`
* Configure the shell profiles
* Configure Nix daemon related settings with launchctl
* Remove directory `/nix/temp-install-dir`

Proceed? ([Y]es/[n]o/[e]xplain): y
 INFO Step: Create an APFS volume `Nix Store` for Nix on `disk3` and add it to `/etc/fstab` mounting on `/nix`
 INFO Step: Provision Nix
 INFO Step: Create build users (UID 300-332) and group (GID 30000)
 INFO Step: Configure Time Machine exclusions
 INFO Step: Configure Nix
 INFO Step: Configure Nix daemon related settings with launchctl
 INFO Step: Remove directory `/nix/temp-install-dir`
Nix was installed successfully!
To get started using Nix, open a new shell or run `. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh`

ephemeraladmin@mac-epic-turducken ~ % . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh

I check again for nix files in my homedir:

ephemeraladmin@mac-epic-turducken ~ % ls ~/.cache ~/.local/state/nix ~/.nix-profile
ls: /Users/ephemeraladmin/.cache: No such file or directory
ls: /Users/ephemeraladmin/.local/state/nix: No such file or directory
ls: /Users/ephemeraladmin/.nix-profile: No such file or directory
ephemeraladmin@mac-epic-turducken ~ % nix --version
nix (Nix) 2.17.0
ephemeraladmin@mac-epic-turducken ~ % echo "Hello Nix" | nix run "nixpkgs#ponysay"
 _____________________________
< Hello Nix                   >
 -----------------------------
                            \
                             \
                              \
                               ▄▄▄▄  ▄▄█▄▄▄█▄
                            ▄▄▄████▄▄▄███▄▄█▄▄
                           ▄▄████▄██████▄▄███▄█▄▄▄▄▄
                           █▄██▄▄█▄▄▄▄▄▄▄████▄▄▄████▄▄
                           ██▄▄██▄█▄█████▄▄▄█▄▀▀▀▄████
                           ▀▄████████████████    ███▄▀
                           ▄▄██▄▄▄▄████▄▄▄▄███ ▄▄▄▀▀
               ▄▄▄▄      ▄▄▄▄██▄▄███▄▄▄▄██████ ▀█▄▀
             ▄▄████▄▄    ██▄▄█▄▄▄▄▄████▄▄▄████
      ▄▄▄▄▄ ▄▄█▄▄▄▄▄█▄▄   ▀▄██████▄▄██▄▄▄▄▄████ ▄▄▄
    ▄▄█████▄████████▄▄██  ▄▄██▄▄██▄▄█▄▄▄▄▄▄▄█▄▄▄███▄▄
    █████▄▄▄▄▄████▄▀▄▄▄█   ▀▄▄▄█▄█████▄      ████████
    ▀▄████████▄▄████ █▄▄▄▄▄▄▄▄▄█▄▄█▄███▄▄▄▄▄▄▄▄██▄▄▀
     ▀▄█████▄▄██████▄▄██▄▄█▄█▄▄█▄█████▄▄▄▄▄▄▄▄▄▀▀
  ▄▄▄▄███████████▄▀ ██▄▄▄▄▄▄▄▄████████▄▄
  ███████████▄█▀▀   ██▄▄██▄▄▄▄▄▄████▄███▄▄
  ▀▄▄▄▄██▄▄█████     ▀▄▄▄▄██▄▄███████▄█▄▄▀
█ ██▄▄▄████████      ▄▄████████████▄▄██
█▄▄██▄▀▄█▄▄▄▀▀        ▀▀▀▀▀▀▀▀███████▄▀
 ▀▄▄▄▀                         ▀▀▀▀▀

Finally, checking again:

ephemeraladmin@mac-epic-turducken ~ % ls ~/.cache ~/.local/state/nix ~/.nix-profile
ls: /Users/ephemeraladmin/.local/state/nix: No such file or directory
ls: /Users/ephemeraladmin/.nix-profile: No such file or directory
/Users/ephemeraladmin/.cache:
nix
ephemeraladmin@mac-epic-turducken ~ % ls -lah ~/.cache
total 0
drwxr-xr-x   3 ephemeraladmin  staff    96B Sep 15 09:31 .
drwxr-x---+ 18 ephemeraladmin  staff   576B Sep 15 09:31 ..
drwxr-xr-x   6 ephemeraladmin  staff   192B Sep 15 09:31 nix
ephemeraladmin@mac-epic-turducken ~ % ls -lah | grep .cache
drwxr-xr-x   3 ephemeraladmin  staff    96B Sep 15 09:31 .cache

Here you can see the installer does not create the ~/.cache directory, and if nix creates it, the owner should be your user.

I suspect your ~/.cache directory may have other contents and been created by something else, which made it root for some reason? "Real" systems are a lot more messy than a stock install. 😅

Maybe you can look in ~/.cache and see what else is in there?

billyogat commented 11 months ago

Thanks for the reply and all the info. I really appreciate it!! I'll go digging and see what I can find.

BLucky-gh commented 11 months ago

I just ran into the issue too, running sudo chown -R $(whoami) ~/.cache/nix solved it, so the problem is just that whatever is creating the nix cache folder is creating it as root, and since I got the error on my first ever run of the nix command, the folder was definitely created by the installer

Considering the installer promotes itself to root, and that nothing else has been run between the install and nix fmt . (in my case), it's almost definitely a bug in either the installer itself, or one of its dependencies

tangowithfoxtrot commented 7 months ago

@BLucky-gh Thank you! I just fresh-installed and ran into this as well and that fixed it for me.