dustinlyons / nixos-config

General purpose Nix configuration for macOS / NixOS with starter templates + step-by-step guides ✨
BSD 3-Clause "New" or "Revised" License
1.79k stars 113 forks source link

MacOS M2 - install issue #30

Closed ignatiusm closed 1 year ago

ignatiusm commented 1 year ago

Hi πŸ‘‹ Thanks for this excellent repository!

I wonder if you had any debugging advice for a nix-noob who is trying to set up nix on a fresh M2 MacBook Pro running Sonoma 14.1.1

I'm encountering an issue while running the build step of bin/build. To my eyes it looks like glibc isn't successfully building. It says the GNU C library is currently unavailable for this platform. I can see an entry for glibc on search.nixos.org (but, indeed, no darwin support). It gets through to the configuring phase

My question is: why do you think it is looking for glibc when doing a build on darwin? I've tried a few things (clean reinstall, adding gnugrep and glibc to list of packages, using NixOS/nixpkgs - main and unstable) but am a bit hampered by my Nix ignorance here. Do you have any suggestions for how to address this?

Starting build...
warning: Git tree '/Users/iggy/nixos-config' is dirty
error: builder for '/nix/store/d20vsmbkvs93qcdhlaliig2g4bz38lsw-glibc-nolibgcc-2.38-23.drv' failed with exit code 1;
       last 10 log lines:
[I've added in a few more log lines from nix log for extra context: 
...
@nix { "action": "setPhase", "phase": "configurePhase" }
configuring
configure flags: --disable-static --prefix=/nix/store/csvckbkqpbcq61kriv05prznm2ln1y1c-glibc-nolibgcc-2.38-23 --bindir=/nix/store/s4i9zfnjadh2qxgb1qsa8ri4j1gavr4i-glibc-nolibgcc-2.38-23-bin/bin --sbindir=/nix/store/s4i9zfnjadh2qxgb1qsa>
configure: creating cache config.cache
checking build system type... aarch64-apple-darwin23.1.0
checking host system type... aarch64-apple-darwin23.1.0
checking for gcc... gcc
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether gcc accepts -g... yes
checking for gcc option to enable C11 features... none needed
checking whether the compiler supports GNU C++... yes
checking whether g++ accepts -g... yes
checking for g++ option to enable C++11 features... none needed
checking whether g++ can link programs... no
checking for sysdeps preconfigure fragments... aarch64 alpha arc arm csky hppa i386 loongarch m68k microblaze checking for grep that handles long lines and -e... /nix/store/kxbn7dv0i7p0ylsbr53j7z0gf45kim78-gnugrep-3.11/bin/grep]
       > checking for egrep... /nix/store/kxbn7dv0i7p0ylsbr53j7z0gf45kim78-gnugrep-3.11/bin/grep -E
       > mips nios2 or1k powerpc riscv s390 sh checking for grep that handles long lines and -e... (cached) /nix/store/kxbn7dv0i7p0ylsbr53j7z0gf45kim78-gnugrep-3.11/bin/grep
       > checking for egrep... (cached) /nix/store/kxbn7dv0i7p0ylsbr53j7z0gf45kim78-gnugrep-3.11/bin/grep -E
       > sparc x86_64
       > configure: error:
       > *** The GNU C library is currently unavailable for this platform.
       > *** If you are interested in seeing glibc on this platform visit
       > *** the "How to submit a new port" in the wiki:
       > ***   https://sourceware.org/glibc/wiki/#Development
       > *** and join the community!
       For full logs, run 'nix-store -l /nix/store/d20vsmbkvs93qcdhlaliig2g4bz38lsw-glibc-nolibgcc-2.38-23.drv'.
error: 1 dependencies of derivation '/nix/store/br1z6ln523bd2ngwv1q1il49wb864ril-home-manager-applications.drv' failed to build
error: 1 dependencies of derivation '/nix/store/728vr3w204fnsi0j7jhd70w5p429x5d3-home-manager-fonts.drv' failed to build
error: 1 dependencies of derivation '/nix/store/7538zh42mv1s7jh9rjpg13hhcj6vdal4-home-manager-path.drv' failed to build
error: 1 dependencies of derivation '/nix/store/g7k28kvkwmjxl5pmavryihhm0yd77x7a-system-applications.drv' failed to build
error: 1 dependencies of derivation '/nix/store/4n8k3dfx9h3g31lji33bma9jmmda2wbj-darwin-system-23.11.20231114.e5e3346+darwin4.e67f2bf.drv' failed to build
dustinlyons commented 1 year ago

Can you export your current environment and share the result?

$ env

ignatiusm commented 1 year ago

Sure (thanks for a speedy reply! πŸš€ )

TERM_PROGRAM=Apple_Terminal
SHELL=/bin/zsh
TERM=xterm-256color
TMPDIR=/var/folders/dc/cnzrbwx50_1cpdmxz839vmg00000gn/T/
TERM_PROGRAM_VERSION=452
TERM_SESSION_ID=85D518F6-96F9-4D08-B771-54C1A1F1B752
USER=iggy
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.zytT31kHRe/Listeners
PATH=/Users/iggy/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin
LaunchInstanceID=22FE9B71-CEF3-4A7E-9F56-5D06035F31F3
__CFBundleIdentifier=com.apple.Terminal
PWD=/Users/iggy/nixos-config
XPC_FLAGS=0x0
XPC_SERVICE_NAME=0
SHLVL=1
HOME=/Users/iggy
LOGNAME=iggy
SECURITYSESSIONID=186b4
OLDPWD=/Users/iggy/nixos-config
NIX_PROFILES=/nix/var/nix/profiles/default /Users/iggy/.nix-profile
NIX_SSL_CERT_FILE=/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt
LANG=en_NZ.UTF-8
_=/usr/bin/env
ignatiusm commented 1 year ago

@dustinlyons - I tried again with nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-23.05-darwin"; in the inputs block of flake.nix and it got past that error!! πŸŽ‰

Currently in the "Switching to new generation" and installing phases.

I see you use your own fork of nixpkgs. How does my somewhat hacky fix fit in with that pattern?

Again, thank you very much for all the hard work you've put into making your config easily sharable πŸ™‡

dustinlyons commented 1 year ago

@ignatiusm That's great to hear! My fork provides a few options:

So you'll be fine if you're sticking with Mac.

In re: to your error, I was able to reproduce it! So that's actually great. When I try to run bin/build I now get the same thing. I only got the error after updating my flake locally to the latest nixpkgs. So previous flake inputs worked, latest flake inputs don't.

This is a good introduction to Nix. This will happen from time to time; you'll update your dependencies and the build will break. But the amazing thing about nixpkgs is someone is likely already on it! A patch is probably likely already in the works, the community is fast; all you have to do is wait, run nix flake update, and build again.

nixpkgs is amazing because it's like this massive community all patching software together :)

So, here's my general process when I update the flake and it doesn't build:

  1. Go to nixpkgs Github Issues and search for the error. If nothing is there, I may submit one
  2. If I don't need to update right away, I'll usually just stop and wait a few days
  3. If I do need to update, I'll try to figure out what package is broken and drop a 6-7 line patch in my overlays/ dir that locks the bad package to a previous working commit hash.
  4. Or if I can't be bothered to do that, I'll just remove whatever is broken (if I can) with a comment that I should add it back later.

This is great because think about the past, when you get strange errors building dependencies: you're usually on your own. Here, we lean on the community of nixpkgs.

dustinlyons commented 1 year ago

I recently added CI to this repository; I need to do the same for nixpkgs so that my fork doesn't update unless the template build passes. And need to procur a Mac Mini to run aarch64-darwin. On the list :)

dustinlyons commented 1 year ago

Looks like it's the docker package failing to build. I commented out the lines docker and docker-compose in shared/packages.nix and it builds.

dustinlyons commented 1 year ago

Also, the reason nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-23.05-darwin" works for you is because whatever bug this is hasn't hit that input yet. My nixpkgs fork grabs the latest commit hash.

dustinlyons commented 1 year ago

I went ahead and submitted an issue for this: https://github.com/NixOS/nixpkgs/issues/267685 and disabled docker in the configuration for now.

dustinlyons commented 1 year ago

Someone released a patch to fix the issue, there is now an open PR: https://github.com/NixOS/nixpkgs/pull/267751

ignatiusm commented 1 year ago

Thank you for your super informative and welcoming response!! I'm very grateful for your help and encouragement.

One question: how did you narrow it down to docker that was broken? It wasn't listed in the log snippet above as one of the pkgs that had glibc as a dependency. Is there a command to see the tree of dependencies?

dustinlyons commented 1 year ago

When I reproduced it locally, the log output showed docker as the last derivation in the call stack. Usually it will show you the broken package at build time.

For tree of dependencies. you can play around with nix-tree.

$ nix shell nixpkgs#nix-tree
$ cd nixos-config && nix-tree