Created
December 3, 2024 04:29
-
-
Save getchoo/df684f6b14d2cc79a4a6e25c374abd6d to your computer and use it in GitHub Desktop.
Revisions
-
getchoo created this gist
Dec 3, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ let pkgs = import <nixpkgs> { config = { }; overlays = [ ]; }; inherit (pkgs) lib; # Packages we want to build optimized versions of packages = lib.getAttrs [ "hello" # Test package "jdk8" "jdk17" "jdk21" ] pkgs; # Microarchitectures we want to optimize for microarchitectures = lib.attrNames lib.systems.architectures.features; # Do something for each microarchitecture forAllMicroarchitectures = lib.genAttrs microarchitectures; # Create an optimized stdenv for each microarchitecture stdenvFor = forAllMicroarchitectures ( march: pkgs.stdenvAdapters.withCFlags [ "-O3" "-march=${march}" "-mtune=${march}" ] pkgs.stdenv ); # Override a given package with the stdenv optimized for the given microarchitecture applyOptimizations = march: package: package.override { stdenv = stdenvFor.${march}; }; in # For each microarchitecture forAllMicroarchitectures ( march: # Apply optimizations for each package lib.mapAttrs (lib.const (applyOptimizations march)) packages )