From 4e0045a4da96aa9403405adb5a937bb2c595a0dc Mon Sep 17 00:00:00 2001 From: Mikael Voss Date: Sun, 13 Oct 2024 11:24:31 +0200 Subject: [PATCH] Build with LLVM and musl --- flake.nix | 9 ++++++++- lib/platforms.nix | 9 +++++++++ nixos/module/default.nix | 1 + nixos/module/musl.nix | 7 +++++++ overlay/fixes.nix | 40 ++++++++++++++++++++++++---------------- 5 files changed, 49 insertions(+), 17 deletions(-) create mode 100644 nixos/module/musl.nix diff --git a/flake.nix b/flake.nix index 08949ff..a4baa6d 100644 --- a/flake.nix +++ b/flake.nix @@ -95,7 +95,7 @@ overlays = load ./overlay "overlay"; legacyPackages = eachSystem (system: platform: import nixpkgs { - localSystem = builtins.currentSystem or platform; + localSystem = builtins.currentSystem or system; crossSystem = platform; overlays = [ self.overlays.default ]; config.allowUnsupportedSystem = true; @@ -120,6 +120,13 @@ targetHost = config.networking.fqdnOrHostName; targetUser = null; }; + + nixpkgs = let + platform = self.lib.platforms.x86_64-linux; + in { + buildPlatform = builtins.currentSystem or platform.system; + hostPlatform = platform; + }; }; }; diff --git a/lib/platforms.nix b/lib/platforms.nix index 52308d9..5d95664 100644 --- a/lib/platforms.nix +++ b/lib/platforms.nix @@ -4,13 +4,22 @@ let inherit (nixpkgs) lib; in lib.mapAttrs (system: platform: lib.systems.elaborate platform) { "x86_64-linux" = { system = "x86_64-linux"; + config = "x86_64-unknown-linux-musl"; + useLLVM = true; + linker = "lld"; }; "aarch64-linux" = { system = "aarch64-linux"; + config = "aarch64-unknown-linux-musl"; + useLLVM = true; + linker = "lld"; }; "riscv64-linux" = { system = "riscv64-linux"; + config = "riscv64-unknown-linux-musl"; + useLLVM = true; + linker = "lld"; }; } diff --git a/nixos/module/default.nix b/nixos/module/default.nix index 27c4c2a..19e41df 100644 --- a/nixos/module/default.nix +++ b/nixos/module/default.nix @@ -11,6 +11,7 @@ iosched kernel locale-en_EU + musl network nix openssh diff --git a/nixos/module/musl.nix b/nixos/module/musl.nix new file mode 100644 index 0000000..2750d14 --- /dev/null +++ b/nixos/module/musl.nix @@ -0,0 +1,7 @@ +{ ...}: { modulesPath, ... }: { + disabledModules = [ + (modulesPath + "/config/ldso.nix") + (modulesPath + "/programs/nix-ld.nix") + (modulesPath + "/config/stub-ld.nix") + ]; +} diff --git a/overlay/fixes.nix b/overlay/fixes.nix index b37a8bc..89ae394 100644 --- a/overlay/fixes.nix +++ b/overlay/fixes.nix @@ -3,6 +3,14 @@ let inherit (nixpkgs.lib) optionalAttrs toList; inherit (prev.stdenv) hostPlatform; in { + netbsd = prev.netbsd.overrideScope (final: prev: { + compatIfNeeded = [ final.compat ]; + + compat = prev.compat.overrideAttrs (prevAttrs: { + makeFlags = prevAttrs.makeFlags ++ [ "OBJCOPY=:" ]; + }); + }); + numactl = prev.numactl.overrideAttrs (prevAttrs: { patches = prevAttrs.patches or [ ] ++ [ (final.fetchpatch { @@ -12,26 +20,18 @@ in { ]; }); + python3 = prev.python3.overrideAttrs (prevAttrs: { + postFixup = prevAttrs.postFixup + '' + pushd "$out/lib/${prevAttrs.passthru.libPrefix}" + test -e "$sysconfigdataName" || ln -s _sysconfigdata__linux_.py "$sysconfigdataName.py" + popd + ''; + }); + redis = prev.redis.overrideAttrs ({ doCheck = false; }); - python312 = prev.python312.override { - packageOverrides = final: prev: { - pywebview = prev.pywebview.overrideAttrs ({ - doCheck = false; - doInstallCheck = false; - }); - } // optionalAttrs hostPlatform.isRiscV64 { - psutil = prev.psutil.overrideAttrs (prevAttrs: { - disabledTests = prevAttrs.disabledTests or [ ] ++ [ - "net_if_addrs" - "net_if_stats" - ]; - }); - }; - }; - sioyek = prev.sioyek.overrideAttrs (prevAttrs: { env = prevAttrs.env or { } // { NIX_CFLAGS_COMPILE = toList prevAttrs.env.NIX_CFLAGS_COMPILE or [ ] @@ -39,6 +39,14 @@ in { }; }); + time = prev.time.overrideAttrs (prevAttrs: { + env = prevAttrs.env or { } // { + CFLAGS = toList prevAttrs.env.CFLAGS or [ ] ++ [ + "-Wno-error=implicit-function-declaration" + ] |> toString; + }; + }); + zeromq = prev.zeromq.overrideAttrs (prevAttrs: { postPatch = prevAttrs.postPatch or "" + '' substituteInPlace CMakeLists.txt \