Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

M1 Mac support #1

Closed
2 of 3 tasks
srid opened this issue Nov 25, 2021 · 8 comments · Fixed by #2
Closed
2 of 3 tasks

M1 Mac support #1

srid opened this issue Nov 25, 2021 · 8 comments · Fixed by #2
Assignees
Labels
help wanted Extra attention is needed

Comments

@srid
Copy link
Owner

srid commented Nov 25, 2021

Make nix build (and bin/run) succeed on M1 Mac with native Nix installed.

No rosetta.

@srid srid added the help wanted Extra attention is needed label Nov 25, 2021
@srid
Copy link
Owner Author

srid commented Nov 25, 2021

diff --git a/flake.lock b/flake.lock
index 60b86d5..4b2a246 100644
--- a/flake.lock
+++ b/flake.lock
@@ -33,11 +33,11 @@
     },
     "nixpkgs": {
       "locked": {
-        "lastModified": 1637533542,
-        "narHash": "sha256-9jR9AOz4OZf4IxMdIgveOur8n5WbZJBAXtXOe434l78=",
+        "lastModified": 1637882183,
+        "narHash": "sha256-J2PoXItGsstIP4NoI36ipEgZMP8Hhht0HmwtvFyBHA0=",
         "owner": "NixOS",
         "repo": "nixpkgs",
-        "rev": "b2181bc967053310657128d687e44ec683e7604b",
+        "rev": "96cf0b7f273370aaa4cdef40e0282a139170cba3",
         "type": "github"
       },
       "original": {
diff --git a/flake.nix b/flake.nix
index a927662..e151796 100644
--- a/flake.nix
+++ b/flake.nix
@@ -8,7 +8,7 @@
     };
   };
   outputs = inputs@{ self, nixpkgs, flake-utils, ... }:
-    flake-utils.lib.eachSystem [ "x86_64-linux" "x86_64-darwin" ] (system:
+    flake-utils.lib.eachSystem [ "x86_64-linux" "aarch64-darwin" "x86_64-darwin" ] (system:
       let
         overlays = [ ];
         pkgs =
@@ -27,11 +27,11 @@
               pkgs.haskell.lib.addBuildTools drv (with pkgs.haskellPackages;
               [
                 # Specify your build/dev dependencies here.
-                cabal-fmt
+                # cabal-fmt
                 cabal-install
-                ghcid
-                haskell-language-server
-                ormolu
+                # ghcid
+                # haskell-language-server
+                # ormolu
                 pkgs.nixpkgs-fmt
               ]);
           };

/nix/store/7vjmcgcxm0jy0w2jsyk99n0kiq52q296-compiler-rt-libc-9.0.1.drv failed to build:

[ 48%] Building C object lib/builtins/CMakeFiles/clang_rt.cc_kext_arm64_osx.dir/floatsidf.c.o
/tmp/nix-build-compiler-rt-libc-9.0.1.drv-0/compiler-rt-9.0.1.src/lib/sanitizer_common/sanitizer_platform_limits_posix.cc:168:31: error: invalid application of 'sizeof' to an incomplete
  unsigned struct_stat64_sz = sizeof(struct stat64);
                              ^     ~~~~~~~~~~~~~~~
/tmp/nix-build-compiler-rt-libc-9.0.1.drv-0/compiler-rt-9.0.1.src/lib/sanitizer_common/sanitizer_platform_limits_posix.cc:168:45: note: forward declaration of '__sanitizer::stat64'
  unsigned struct_stat64_sz = sizeof(struct stat64);
                                            ^
/tmp/nix-build-compiler-rt-libc-9.0.1.drv-0/compiler-rt-9.0.1.src/lib/sanitizer_common/sanitizer_platform_limits_posix.cc:194:33: error: invalid application of 'sizeof' to an incomplete
  unsigned struct_statfs64_sz = sizeof(struct statfs64);
                                ^     ~~~~~~~~~~~~~~~~~
/tmp/nix-build-compiler-rt-libc-9.0.1.drv-0/compiler-rt-9.0.1.src/lib/sanitizer_common/sanitizer_platform_limits_posix.cc:194:47: note: forward declaration of '__sanitizer::statfs64'
  unsigned struct_statfs64_sz = sizeof(struct statfs64);
                                              ^
[ 49%] Building C object lib/builtins/CMakeFiles/clang_rt.builtins_arm64_osx.dir/fixunsdfdi.c.o
2 errors generated.
make[2]: *** [lib/sanitizer_common/CMakeFiles/RTSanitizerCommonNoHooks.osx.dir/build.make:370: lib/sanitizer_common/CMakeFiles/RTSanitizerCommonNoHooks.osx.dir/sanitizer_platform_limits_
make[1]: *** [CMakeFiles/Makefile2:851: lib/sanitizer_common/CMakeFiles/RTSanitizerCommonNoHooks.osx.dir/all] Error 2

@srid
Copy link
Owner Author

srid commented Nov 28, 2021

I should note this happens in nix-shell and not nix-build: NixOS/nixpkgs#147739

@srid
Copy link
Owner Author

srid commented Nov 29, 2021

After advancing Nixpkgs,

image

@srid
Copy link
Owner Author

srid commented Nov 29, 2021

@sternenseemann - Any chance I can entertain your interest in this?

I advanced Nixpkgs past your NixOS/nixpkgs#147260 hoping that that might fix it (maybe it fix the llvm error above), but still I can't build even cabal2nix (fails at th-abstraction). As an aside, I wonder why cabal2nix's dependencies are not cached.

@sternenseemann
Copy link

Any chance I can entertain your interest in this?

I entertain the littlest interest in aarch64-darwin possible to be honest, I don't have no M1 machine nor plan purchasing one, so the whole platform just causes me a lot of annoyance I can't do anything about…

maybe it fix the llvm error above

Indeed, LLVM 9 was used for haskellPackages before which did not support aarch64-darwin at all. LLVM >= 11 should support it though, hence the build failure disappears.

but still I can't build even cabal2nix (fails at th-abstraction).

Looking at the error it seems to me that this might be some kind of code signing issue, you should be able to confirm this using the log(1) utility. My first instinct was that this was due to execution of the test suite, but this doesn't seem to be the case as ./Setup actually gets killed, at seemingly random places in other builds. Interestingly this seemingly only started happening after upgrading LLVM, e. g. th-abstraction was building with LLVM 9.

At this point, I can't really guess what the issue might be. Worth a try might be recompiling GHC and the package set using LLVM 11.

Regrettably, the contributed support for aarch64-darwin has been limited to getting GHC to compile and very little work has gone into actually making the packages produced by it work properly.

As an aside, I wonder why cabal2nix's dependencies are not cached.

Well, it is kind of hard to cache dependencies that don't build.

sternenseemann added a commit to sternenseemann/nixpkgs that referenced this issue Nov 30, 2021
While GHC now can be bootstrapped and built on aarch64-darwin, it seems
to work only to an extent. All sorts of strange issues have manifested
themselves in `haskellPackages` and downstream usage which leads me to
conclude that it would be misleading to call it supported on this
platform, especially in a stable channel. To give a few examples,
separate bin outputs just don't work in general [1] and `opt` fails
for unknown reasons in some derivations [2]. As I don't own any
appropriate hardware, I have tried tackling these issues by staring into
my crystal ball, but so far to no avail (even worse, new issues [3] have
cropped up due to changes that should have been an improvement).

Given these circumstances, I'm not willing to call GHC supported on
aarch64-darwin for the stable channel. I'm (for now) hopeful that we can
improve the situation on `master` going forward, but it is not
guaranteed that these changes will be backportable without a ton of
effort.

Should it turn out that we can't resolve these issues or maintain GHC's
aarch64-darwin support due to a lack of contributors going forward, I am
also prepared to drop aarch64-darwin support completely. While it has
been proclaimed a Tier 3 platform, I would argue that the “popular”
package GHC has never been working, at least not properly.

[1]: NixOS#140774
     NixOS#140180
[2]: https://matrix.to/#/!RbXGJhHMsnQcNIDFWN:nixos.org/$C6FK74EajqSTk58JzriYpQJ9f6x3UH3tIREcn04Y-rM?via=nixos.org&via=matrix.org&via=tchncs.de
[3]: srid/haskell-template#1 (comment)
@sternenseemann
Copy link

Should be fixed on current nixpkgs master.

@srid
Copy link
Owner Author

srid commented Dec 5, 2021

Awesome, @sternenseemann ! 🕺🏿

It mostly works now after a0672b6. One final thing left to resolve is build failures for ghcid, ormolu, etc (see below) ... but nix build with these build tools commented out works.

error: cycle detected in build of '/nix/store/am90h7yjq0jdk5ha80r2gwq5xs1kqfnl-ghcid-0.8.7.drv' 
  in the references of output 'bin' from output 'out'

Looks to be this issue: NixOS/nixpkgs#140774

@sternenseemann
Copy link

Looks to be this issue: NixOS/nixpkgs#140774

Yes.

@srid srid self-assigned this Dec 5, 2021
@srid srid closed this as completed in #2 Dec 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants