diff --git a/flake.nix b/flake.nix index 08949ff..65c0f21 100644 --- a/flake.nix +++ b/flake.nix @@ -98,7 +98,10 @@ localSystem = builtins.currentSystem or platform; crossSystem = platform; overlays = [ self.overlays.default ]; - config.allowUnsupportedSystem = true; + config = { + allowUnsupportedSystem = true; + replaceStdenv = { pkgs }: self.lib.stdenv pkgs; + }; }); packages = eachSystem (system: platform: diff --git a/lib/stdenv.nix b/lib/stdenv.nix new file mode 100644 index 0000000..7b93802 --- /dev/null +++ b/lib/stdenv.nix @@ -0,0 +1,23 @@ +{ ... }: pkgs: + +let + inherit (pkgs) lib; + inherit (lib) optionalAttrs toList; + + ldflags = [ "-lmimalloc" ]; + rustflags = map (flag: [ "-C" "link-arg=${flag}" ]) ldflags |> lib.flatten; + + exclude = lib.genAttrs [ + "mimalloc" + "perl" + ] (pkg: null); +in pkgs.addAttrsToDerivation (prevAttrs: optionalAttrs (!exclude ? ${lib.getName prevAttrs}) ({ + buildInputs = prevAttrs.buildInputs or [ ] ++ [ pkgs.mimalloc ]; + env = prevAttrs.env or { } // optionalAttrs (prevAttrs ? env.NIX_LDFLAGS) { + NIX_LDFLAGS = toList prevAttrs.NIX_LDFLAGS or [ ] ++ ldflags |> toString; + }; + + NIX_RUSTFLAGS = prevAttrs.NIX_RUSTFLAGS or [ ] ++ rustflags; +} // optionalAttrs (!prevAttrs ? env.NIX_LDFLAGS) { + NIX_LDFLAGS = toList prevAttrs.NIX_LDFLAGS or [ ] ++ ldflags; +})) pkgs.stdenv diff --git a/overlay/mimalloc.nix b/overlay/mimalloc.nix index 3c16203..8c587b6 100644 --- a/overlay/mimalloc.nix +++ b/overlay/mimalloc.nix @@ -33,10 +33,6 @@ in { fractal = prev.fractal.overrideAttrs (prevAttrs: { nativeBuildInputs = prevAttrs.nativeBuildInputs or [ ] ++ [ final.makeBinaryWrapper ]; - buildInputs = prevAttrs.buildInputs or [ ] ++ [ final.mimalloc ]; - - NIX_RUSTFLAGS = lib.toList prevAttrs.NIX_RUSTFLAGS or [ ] ++ [ "-C" "link-arg=-lmimalloc" ]; - postInstall = prevAttrs.postInstall or "" + '' wrapProgram "$out/bin/fractal" \ --set MIMALLOC_RESERVE_HUGE_OS_PAGES 1 @@ -47,47 +43,4 @@ in { mpv = final.mpv-unwrapped; extraMakeWrapperArgs = [ "--set" "MIMALLOC_RESERVE_HUGE_OS_PAGES" "1" ]; }; -} // lib.genAttrs [ - "bat" - "bottom" - "cryptsetup" - "dbus-broker" - "erlang" - "fd" - "firefox-unwrapped" - "fuzzel" - "helix" - "kitty" - "mako" - "mpv-unwrapped" - "niri" - "nix" - "nushell" - "openssh" - "pipewire" - "pueue" - "ripgrep" - "sd" - "sioyek" - "sudo-rs" - "systemd" - "swayidle" - "swaylock" - "swaylock-effects" - "thunderbird-unwrapped" - "uutils-coreutils" - "uutils-coreutils-noprefix" - "waybar" - "wirepluber" - "xdg-desktop-portal-gnome" - "xdg-desktop-portal-gtk" -] (pkg: prev.${pkg}.overrideAttrs (prevAttrs: { - buildInputs = prevAttrs.buildInputs or [ ] ++ [ final.mimalloc ]; - env = prevAttrs.env or { } // lib.optionalAttrs (prevAttrs ? env.NIX_LDFLAGS) { - NIX_LDFLAGS = toString (lib.toList prevAttrs.env.NIX_LDFLAGS or [ ] ++ [ "-lmimalloc" ]); - }; - - NIX_RUSTFLAGS = lib.toList prevAttrs.NIX_RUSTFLAGS or [ ] ++ [ "-C" "link-arg=-lmimalloc" ]; -} // lib.optionalAttrs (!prevAttrs ? env.NIX_LDFLAGS) { - NIX_LDFLAGS = lib.toList prevAttrs.NIX_LDFLAGS or [ ] ++ [ "-lmimalloc" ]; -})) +}