From 4d0b369475b476d95b002729186f06dae6ba5072 Mon Sep 17 00:00:00 2001 From: FireFragment <55660550+FireFragment@users.noreply.github.com> Date: Thu, 16 May 2024 19:39:16 +0200 Subject: [PATCH] Add crate-specific overrides --- build.nix | 28 ++++++++++++++++++++++++++-- config.nix | 4 +++- crate_specific.nix | 8 ++++++++ default.nix | 3 ++- 4 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 crate_specific.nix diff --git a/build.nix b/build.nix index f1552c4..91a5ccb 100644 --- a/build.nix +++ b/build.nix @@ -68,6 +68,8 @@ , fetchurl , lndir , userAttrs +, crateSpecificOverrides +, pkgs }: let @@ -130,14 +132,16 @@ let jq rsync ] ++ nativeBuildInputs - ++ lib.optionals (mode == "clippy") [clippy]; + ++ lib.optionals (mode == "clippy") [clippy] + ++ neededCrateSpecificOverrides.nativeBuildInputs; buildInputs = lib.optionals stdenv.isDarwin [ darwin.Security darwin.apple_sdk.frameworks.CoreServices darwin.cf-private darwin.libiconv - ] ++ buildInputs; + ] ++ buildInputs + ++ neededCrateSpecificOverrides.buildInputs; inherit builtDependencies; @@ -374,6 +378,26 @@ let }; }; + neededCrateSpecificOverrides = + let + overridesList = builtins.map + ( crateInfo: + if builtins.hasAttr crateInfo.name crateSpecificOverrides then + crateSpecificOverrides.${crateInfo.name} { inherit crateInfo; } + else {} + ) + cratesIoDependencies; + in builtins.foldl' + (acc: elem: + { + buildInputs = acc.buildInputs ++ elem.buildInputs or []; + nativeBuildInputs = acc.nativeBuildInputs ++ elem.nativeBuildInputs or []; + } + ) + { buildInputs = []; nativeBuildInputs = []; } + overridesList; + + # Crates.io dependencies required to compile user's crate. # # As an output, for each dependency, this derivation produces a subdirectory diff --git a/config.nix b/config.nix index 730018b..7ec4141 100644 --- a/config.nix +++ b/config.nix @@ -1,4 +1,4 @@ -{ lib, libb, builtinz, arg }: +{ lib, libb, builtinz, arg, pkgs }: let allowFun = attrs0: attrName: default: if builtins.hasAttr attrName attrs0 then @@ -311,6 +311,8 @@ let # Example: # [ { name = "wabt", version = "2.0.6", sha256 = "..." } ] cratesIoDependencies = libb.mkVersions buildPlanConfig.cargolock; + + crateSpecificOverrides = import ./crate_specific.nix { inherit pkgs; }; }; # config used when planning the builds diff --git a/crate_specific.nix b/crate_specific.nix new file mode 100644 index 0000000..eb7fa98 --- /dev/null +++ b/crate_specific.nix @@ -0,0 +1,8 @@ +{ pkgs }: + +{ + openssl-sys = { ... }: { + nativeBuildInputs = with pkgs; [ pkg-config ]; + buildInputs = with pkgs; [ openssl ]; + }; +} diff --git a/default.nix b/default.nix index a377938..1bc1383 100644 --- a/default.nix +++ b/default.nix @@ -13,6 +13,7 @@ , writeText , zstd , clippy +, pkgs }@defaultBuildAttrs: let @@ -22,7 +23,7 @@ let { inherit lib writeText remarshal runCommandLocal formats; }; mkConfig = arg: - import ./config.nix { inherit lib arg libb builtinz; }; + import ./config.nix { inherit lib arg libb builtinz pkgs; }; buildPackage = arg: let