NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.95k stars 1.53k forks source link

error: failed to configure synthetic.conf #11392

Open pmarreck opened 3 months ago

pmarreck commented 3 months ago

Platform

Additional information

MacOS Sequoia 15.1 Beta (24B5035e)

Somehow I completely hosed Nix while trying to update Nix using Nix (yeah, I shit you not), and somehow this completely screwed up my profile, so then I wanted to uninstall everything and reinstall from scratch, and ran into this.

Output

Output ```log PeterMacbookProM1Max:~ pmarreck$ curl -L https://nixos.org/nix/install | sh % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 100 4267 100 4267 0 0 22519 0 --:--:-- --:--:-- --:--:-- 22519 downloading Nix 2.24.4 binary tarball for aarch64-darwin from 'https://releases.nixos.org/nix/nix-2.24.4/nix-2.24.4-aarch64-darwin.tar.xz' to '/var/folders/98/rpg9_bzd0v750_810hh2gm0w0000gn/T/nix-binary-tarball-unpack.XXXXXXXXXX.8pilgYPtEA'... % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 14.6M 100 14.6M 0 0 14.6M 0 --:--:-- --:--:-- --:--:-- 14.6M Switching to the Multi-user Installer Welcome to the Multi-User Nix Installation This installation tool will set up your computer with the Nix package manager. This will happen in a few stages: 1. Make sure your computer doesn't already have Nix. If it does, I will show you instructions on how to clean up your old install. 2. Show you what I am going to install and where. Then I will ask if you are ready to continue. 3. Create the system users (uids [301..332]) and groups (gid 30000) that the Nix daemon uses to run builds. To create system users in a different range, exit and run this tool again with NIX_FIRST_BUILD_UID set. 4. Perform the basic installation of the Nix files daemon. 5. Configure your shell to import special Nix Profile files, so you can use Nix. 6. Start the Nix daemon. Would you like to see a more detailed list of what I will do? No TTY, assuming you would say yes :) I will: - make sure your computer doesn't already have Nix files (if it does, I will tell you how to clean them up.) - create local users (see the list above for the users I'll make) - create a local group (nixbld) - install Nix in /nix - create a configuration file in /etc/nix - set up the "default profile" by creating some Nix-related files in /var/root - back up /etc/bashrc to /etc/bashrc.backup-before-nix - update /etc/bashrc to include some Nix configuration - back up /etc/profile.d/nix.sh to /etc/profile.d/nix.sh.backup-before-nix - update /etc/profile.d/nix.sh to include some Nix configuration - back up /etc/zshrc to /etc/zshrc.backup-before-nix - update /etc/zshrc to include some Nix configuration - back up /etc/bash.bashrc to /etc/bash.bashrc.backup-before-nix - update /etc/bash.bashrc to include some Nix configuration - back up /etc/zsh/zshrc to /etc/zsh/zshrc.backup-before-nix - update /etc/zsh/zshrc to include some Nix configuration - create a Nix volume and a LaunchDaemon to mount it - create a LaunchDaemon (at /Library/LaunchDaemons/org.nixos.nix-daemon.plist) for nix-daemon Ready to continue? No TTY, assuming you would say yes :) ---- let's talk about sudo ----------------------------------------------------- This script is going to call sudo a lot. Normally, it would show you exactly what commands it is running and why. However, the script is run in a headless fashion, like this: $ curl -L https://nixos.org/nix/install | sh or maybe in a CI pipeline. Because of that, I'm going to skip the verbose output in the interest of brevity. If you would like to see the output, try like this: $ curl -L -o install-nix https://nixos.org/nix/install $ sh ./install-nix ~~> Fixing any leftover Nix volume state Before I try to install, I'll check for any existing Nix volume config and ask for your permission to remove it (so that the installer can start fresh). I'll also ask for permission to fix any issues I spot. ---- Found existing Nix volume ------------------------------------------------- special: disk4s7 uuid: 3C867E2D-6354-410B-B920-07BCDC7C4CDA encrypted: no ~~> Checking for artifacts of previous installs Before I try to install, I'll check for signs Nix already is or has been installed on this system. ---- Nix config report --------------------------------------------------------- Temp Dir: /var/folders/98/rpg9_bzd0v750_810hh2gm0w0000gn/T/tmp.tD28gsXgYX Nix Root: /nix Build Users: 32 Build Group ID: 30000 Build Group Name: nixbld build users: Username: UID _nixbld1: 301 _nixbld2: 302 _nixbld3: 303 _nixbld4: 304 _nixbld5: 305 _nixbld6: 306 _nixbld7: 307 _nixbld8: 308 _nixbld9: 309 _nixbld10: 310 _nixbld11: 311 _nixbld12: 312 _nixbld13: 313 _nixbld14: 314 _nixbld15: 315 _nixbld16: 316 _nixbld17: 317 _nixbld18: 318 _nixbld19: 319 _nixbld20: 320 _nixbld21: 321 _nixbld22: 322 _nixbld23: 323 _nixbld24: 324 _nixbld25: 325 _nixbld26: 326 _nixbld27: 327 _nixbld28: 328 _nixbld29: 329 _nixbld30: 330 _nixbld31: 331 _nixbld32: 332 Ready to continue? No TTY, assuming you would say yes :) ---- Preparing a Nix volume ---------------------------------------------------- Nix traditionally stores its data in the root directory /nix, but macOS now (starting in 10.15 Catalina) has a read-only root directory. To support Nix, I will create a volume and configure macOS to mount it at /nix. ~~> Configuring /etc/synthetic.conf to make a mount-point at /nix Password: ---- oh no! -------------------------------------------------------------------- error: failed to configure synthetic.conf We'd love to help if you need it. You can open an issue at https://github.com/NixOS/nix/issues/new?labels=installer&template=installer.md Or get in touch with the community: https://nixos.org/community PeterMacbookProM1Max:~ pmarreck$ ```

Priorities

Add :+1: to issues you find important.

pmarreck commented 3 months ago

What makes this worse is that my version of Bash, which my shell configuration depends on, depends on a more recent Bash than ships with macOS, so hosing my Nix install also hosed everything in my shell configuration :/

pmarreck commented 3 months ago

edit: I noticed that /etc/synthetic.conf was just filled with 7 lines each of which just contained "nix" so after deleting the synthetic.conf file and re-running the installer, it ended up later with this error:

bash-3.2$ curl -L https://nixos.org/nix/install | tee nix-install-commands.log | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  4267  100  4267    0     0  15568      0 --:--:-- --:--:-- --:--:-- 15568
downloading Nix 2.24.4 binary tarball for aarch64-darwin from 'https://releases.nixos.org/nix/nix-2.24.4/nix-2.24.4-aarch64-darwin.tar.xz' to '/var/folders/98/rpg9_bzd0v750_810hh2gm0w0000gn/T/nix-binary-tarball-unpack.XXXXXXXXXX.z3fkpEh2Py'...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 14.6M  100 14.6M    0     0  9514k      0  0:00:01  0:00:01 --:--:-- 9514k
Switching to the Multi-user Installer
Welcome to the Multi-User Nix Installation

This installation tool will set up your computer with the Nix package
manager. This will happen in a few stages:

1. Make sure your computer doesn't already have Nix. If it does, I
   will show you instructions on how to clean up your old install.

2. Show you what I am going to install and where. Then I will ask
   if you are ready to continue.

3. Create the system users (uids [301..332]) and groups (gid 30000)
   that the Nix daemon uses to run builds. To create system users
   in a different range, exit and run this tool again with
   NIX_FIRST_BUILD_UID set.

4. Perform the basic installation of the Nix files daemon.

5. Configure your shell to import special Nix Profile files, so you
   can use Nix.

6. Start the Nix daemon.

Would you like to see a more detailed list of what I will do?
No TTY, assuming you would say yes :)

I will:

 - make sure your computer doesn't already have Nix files
   (if it does, I will tell you how to clean them up.)
 - create local users (see the list above for the users I'll make)
 - create a local group (nixbld)
 - install Nix in /nix
 - create a configuration file in /etc/nix
 - set up the "default profile" by creating some Nix-related files in
   /var/root
 - back up /etc/bashrc to /etc/bashrc.backup-before-nix
 - update /etc/bashrc to include some Nix configuration
 - back up /etc/profile.d/nix.sh to /etc/profile.d/nix.sh.backup-before-nix
 - update /etc/profile.d/nix.sh to include some Nix configuration
 - back up /etc/zshrc to /etc/zshrc.backup-before-nix
 - update /etc/zshrc to include some Nix configuration
 - back up /etc/bash.bashrc to /etc/bash.bashrc.backup-before-nix
 - update /etc/bash.bashrc to include some Nix configuration
 - back up /etc/zsh/zshrc to /etc/zsh/zshrc.backup-before-nix
 - update /etc/zsh/zshrc to include some Nix configuration
 - create a Nix volume and a LaunchDaemon to mount it
 - create a LaunchDaemon (at /Library/LaunchDaemons/org.nixos.nix-daemon.plist) for nix-daemon

Ready to continue?
No TTY, assuming you would say yes :)

---- let's talk about sudo -----------------------------------------------------
This script is going to call sudo a lot. Normally, it would show you
exactly what commands it is running and why. However, the script is
run in a headless fashion, like this:

  $ curl -L https://nixos.org/nix/install | sh

or maybe in a CI pipeline. Because of that, I'm going to skip the
verbose output in the interest of brevity.

If you would like to
see the output, try like this:

  $ curl -L -o install-nix https://nixos.org/nix/install
  $ sh ./install-nix

~~> Fixing any leftover Nix volume state
Before I try to install, I'll check for any existing Nix volume config
and ask for your permission to remove it (so that the installer can
start fresh). I'll also ask for permission to fix any issues I spot.

---- Found existing Nix volume -------------------------------------------------
  special:  disk4s7
     uuid:  3C867E2D-6354-410B-B920-07BCDC7C4CDA
encrypted:  no

~~> Checking for artifacts of previous installs
Before I try to install, I'll check for signs Nix already is or has
been installed on this system.

---- Nix config report ---------------------------------------------------------
        Temp Dir:   /var/folders/98/rpg9_bzd0v750_810hh2gm0w0000gn/T/tmp.8lvKFBsJRW
        Nix Root:   /nix
     Build Users:   32
  Build Group ID:   30000
Build Group Name:   nixbld

build users:
    Username:   UID
     _nixbld1:  301
     _nixbld2:  302
     _nixbld3:  303
     _nixbld4:  304
     _nixbld5:  305
     _nixbld6:  306
     _nixbld7:  307
     _nixbld8:  308
     _nixbld9:  309
     _nixbld10: 310
     _nixbld11: 311
     _nixbld12: 312
     _nixbld13: 313
     _nixbld14: 314
     _nixbld15: 315
     _nixbld16: 316
     _nixbld17: 317
     _nixbld18: 318
     _nixbld19: 319
     _nixbld20: 320
     _nixbld21: 321
     _nixbld22: 322
     _nixbld23: 323
     _nixbld24: 324
     _nixbld25: 325
     _nixbld26: 326
     _nixbld27: 327
     _nixbld28: 328
     _nixbld29: 329
     _nixbld30: 330
     _nixbld31: 331
     _nixbld32: 332

Ready to continue?
No TTY, assuming you would say yes :)

---- Preparing a Nix volume ----------------------------------------------------
    Nix traditionally stores its data in the root directory /nix, but
    macOS now (starting in 10.15 Catalina) has a read-only root directory.
    To support Nix, I will create a volume and configure macOS to mount it
    at /nix.

~~> Configuring /etc/synthetic.conf to make a mount-point at /nix

~~> Creating a Nix volume
Volume Nix Store on disk4s7 force-unmounted

~~> Configuring /etc/fstab to specify volume mount options

~~> Configuring LaunchDaemon to mount 'Nix Store'

~~> Setting up the build group nixbld
            Exists: Yes

~~> Setting up the build user _nixbld1

---- oh no! --------------------------------------------------------------------
It seems the build user _nixbld1 already exists, but with the UID
with the UID '451'. This script can't really handle that right
now, so I'm going to give up.

If you already created the users and you know they start from
451 and go up from there, you can edit this script and change
NIX_FIRST_BUILD_UID near the top of the file to 451 and try
again.

We'd love to help if you need it.

You can open an issue at
https://github.com/NixOS/nix/issues/new?labels=installer&template=installer.md

Or get in touch with the community: https://nixos.org/community

Generally-speaking, both your install and remove scripts should be idempotent. That means that re-running any of them, even if they error halfway through, should not result in an inconsistent state. So for example, if you already see a _nixbldN user, you should either not recreate it (which it looks like this script is trying to do!), or you should remove and recreate it with the same user ID.

abathur commented 3 months ago

What does ls -la /nix show? And what exactly did /etc/synthetic.conf look like before you deleted it?

---- oh no! -------------------------------------------------------------------- It seems the build user _nixbld1 already exists, but with the UID with the UID '451'. This script can't really handle that right now, so I'm going to give up.

If you already created the users and you know they start from 451 and go up from there, you can edit this script and change NIX_FIRST_BUILD_UID near the top of the file to 451 and try again.

The above, paired with the fact that you're on Sequoia already, makes me wonder if you've installed with the detsys installer (which was provisionally working around the issue on Sequoia by using UIDs starting with 451).

If so, you're generally expected to use their uninstall command to clean up.

edit: I noticed that /etc/synthetic.conf was just filled with 7 lines each of which just contained "nix" ... Generally-speaking, both your install and remove scripts should be idempotent. That means that re-running any of them, even if they error halfway through, should not result in an inconsistent state. So for example, if you already see a _nixbldN user, you should either not recreate it (which it looks like this script is trying to do!), or you should remove and recreate it with the same user ID.

The official installer actually does look-before-it-leaps with respect to both adding the nix line to /etc/synthetic.conf and creating the users. It is probably right for it to fail here because it's being run over the top of an install that doesn't match its assumptions.

If you did use the detsys installer, their uninstall routine might be able to clean up?

(That said, since you've already run the official installer over the top and started making manual changes, it wouldn't surprise me if their uninstaller also refuses to clean it up at this point. If that's the case, I'd check their repo for manual uninstall instructions to clean up.)

randomizedcoder commented 1 month ago

My fix was

sudo mv /etc/synthetic.conf /etc/not.synthetic.conf

Then it worked!