From 981d819d4672ecd22e14199e1482cbb49aa0cb5d Mon Sep 17 00:00:00 2001 From: nikstur Date: Wed, 4 Sep 2024 14:20:24 +0200 Subject: [PATCH] botan: refactor Improve overridability and make it more idiomatic. --- pkgs/development/libraries/botan/2.0.nix | 7 -- pkgs/development/libraries/botan/3.0.nix | 9 -- pkgs/development/libraries/botan/default.nix | 114 +++++++++++++++++++ pkgs/development/libraries/botan/generic.nix | 83 -------------- pkgs/top-level/all-packages.nix | 11 +- 5 files changed, 118 insertions(+), 106 deletions(-) delete mode 100644 pkgs/development/libraries/botan/2.0.nix delete mode 100644 pkgs/development/libraries/botan/3.0.nix create mode 100644 pkgs/development/libraries/botan/default.nix delete mode 100644 pkgs/development/libraries/botan/generic.nix diff --git a/pkgs/development/libraries/botan/2.0.nix b/pkgs/development/libraries/botan/2.0.nix deleted file mode 100644 index c14fdb4cef1f..000000000000 --- a/pkgs/development/libraries/botan/2.0.nix +++ /dev/null @@ -1,7 +0,0 @@ -{ callPackage, ... } @ args: - -callPackage ./generic.nix (args // { - baseVersion = "2.19"; - revision = "5"; - hash = "sha256-3+6g4KbybWckxK8B2pp7iEh62y2Bunxy/K9S21IsmtQ="; -}) diff --git a/pkgs/development/libraries/botan/3.0.nix b/pkgs/development/libraries/botan/3.0.nix deleted file mode 100644 index 0cffb67104c6..000000000000 --- a/pkgs/development/libraries/botan/3.0.nix +++ /dev/null @@ -1,9 +0,0 @@ -{ callPackage, stdenv, lib, ... } @ args: - -callPackage ./generic.nix (args // { - baseVersion = "3.5"; - revision = "0"; - hash = "sha256-Z+ja4cokaNkN5OYByH1fMf9JKzjoq4vL0C3fcQTtip8="; - # this patch fixes build errors on MacOS with SDK 10.12, recheck to remove this again - extraPatches = lib.optionals stdenv.hostPlatform.isDarwin [ ./botan3-macos.patch ]; -}) diff --git a/pkgs/development/libraries/botan/default.nix b/pkgs/development/libraries/botan/default.nix new file mode 100644 index 000000000000..ba4883858303 --- /dev/null +++ b/pkgs/development/libraries/botan/default.nix @@ -0,0 +1,114 @@ +{ + lib, + stdenv, + fetchurl, + python3, + bzip2, + zlib, + darwin, + static ? stdenv.hostPlatform.isStatic, # generates static libraries *only* +}: + +let + common = + { + version, + hash, + patches ? [ ], + }: + stdenv.mkDerivation (finalAttrs: { + pname = "botan"; + inherit version; + + __structuredAttrs = true; + enableParallelBuilding = true; + strictDeps = true; + + outputs = [ + "out" + "dev" + ]; + + src = fetchurl { + url = "http://botan.randombit.net/releases/Botan-${finalAttrs.version}.tar.xz"; + inherit hash; + }; + + inherit patches; + + nativeBuildInputs = [ python3 ]; + buildInputs = + [ + bzip2 + zlib + ] + ++ lib.optionals stdenv.isDarwin ( + with darwin.apple_sdk.frameworks; + [ + CoreServices + Security + ] + ); + + botanConfigureFlags = + [ + "--prefix=${placeholder "out"}" + "--with-bzip2" + "--with-zlib" + ] + ++ lib.optionals stdenv.cc.isClang [ + "--cc=clang" + ] + ++ lib.optionals stdenv.hostPlatform.isAarch64 [ + "--cpu=aarch64" + ] + ++ lib.optionals static [ + "--enable-static-library" + "--disable-shared-library" + ]; + + configurePhase = '' + runHook preConfigure + python configure.py ''${botanConfigureFlags[@]} + runHook postConfigure + ''; + + preInstall = '' + if [ -d src/scripts ]; then + patchShebangs src/scripts + fi + ''; + + postInstall = '' + cd "$out"/lib/pkgconfig + ln -s botan-*.pc botan.pc || true + ''; + + doCheck = true; + + meta = with lib; { + description = "Cryptographic algorithms library"; + homepage = "https://botan.randombit.net"; + mainProgram = "botan"; + maintainers = with maintainers; [ + raskin + thillux + ]; + platforms = platforms.unix; + license = licenses.bsd2; + }; + }); +in +{ + botan3 = common { + version = "3.5.0"; + hash = "sha256-Z+ja4cokaNkN5OYByH1fMf9JKzjoq4vL0C3fcQTtip8="; + # this patch fixes build errors on MacOS with SDK 10.12, recheck to remove this again + patches = lib.optionals stdenv.hostPlatform.isDarwin [ ./botan3-macos.patch ]; + }; + + botan2 = common { + version = "2.19.5"; + hash = "sha256-3+6g4KbybWckxK8B2pp7iEh62y2Bunxy/K9S21IsmtQ="; + }; +} diff --git a/pkgs/development/libraries/botan/generic.nix b/pkgs/development/libraries/botan/generic.nix deleted file mode 100644 index 2ea07192f61c..000000000000 --- a/pkgs/development/libraries/botan/generic.nix +++ /dev/null @@ -1,83 +0,0 @@ -{ lib, stdenv, fetchurl, python3, bzip2, zlib -# Passed by version specific builders -, baseVersion, revision, hash -, sourceExtension ? "tar.xz" -, extraConfigureFlags ? "" -, extraPatches ? [ ] -, badPlatforms ? [ ] -, postPatch ? null -, knownVulnerabilities ? [ ] -, CoreServices ? null -, Security ? null -, static ? stdenv.hostPlatform.isStatic # generates static libraries *only* -, ... -}: - -stdenv.mkDerivation (finalAttrs: { - pname = "botan"; - version = "${baseVersion}.${revision}"; - - __structuredAttrs = true; - - outputs = [ "out" "dev" ]; - - src = fetchurl { - name = "Botan-${finalAttrs.version}.${sourceExtension}"; - urls = [ - "http://files.randombit.net/botan/v${baseVersion}/Botan-${finalAttrs.version}.${sourceExtension}" - "http://botan.randombit.net/releases/Botan-${finalAttrs.version}.${sourceExtension}" - ]; - inherit hash; - }; - patches = extraPatches; - inherit postPatch; - - nativeBuildInputs = [ python3 ]; - buildInputs = [ bzip2 zlib ] - ++ lib.optionals stdenv.isDarwin [ CoreServices Security ]; - - botanConfigureFlags = [ - "--prefix=${placeholder "out"}" - "--with-bzip2" - "--with-zlib" - ] ++ lib.optionals stdenv.cc.isClang [ - "--cc=clang" - ] ++ lib.optionals stdenv.hostPlatform.isAarch64 [ - "--cpu=aarch64" - ] ++ lib.optionals static [ - "--enable-static-library" - "--disable-shared-library" - ]; - - configurePhase = '' - runHook preConfigure - python configure.py ''${botanConfigureFlags[@]} ${extraConfigureFlags} - runHook postConfigure - ''; - - enableParallelBuilding = true; - - preInstall = '' - if [ -d src/scripts ]; then - patchShebangs src/scripts - fi - ''; - - postInstall = '' - cd "$out"/lib/pkgconfig - ln -s botan-*.pc botan.pc || true - ''; - - doCheck = true; - - meta = with lib; { - description = "Cryptographic algorithms library"; - mainProgram = "botan"; - maintainers = with maintainers; [ raskin thillux ]; - platforms = platforms.unix; - license = licenses.bsd2; - inherit badPlatforms; - inherit knownVulnerabilities; - }; - passthru.updateInfo.downloadPage = "http://files.randombit.net/botan/"; -}) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 89010d628c39..224ac5aba4f8 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -19489,13 +19489,10 @@ with pkgs; bosh-cli = callPackage ../applications/networking/cluster/bosh-cli { }; - botan2 = callPackage ../development/libraries/botan/2.0.nix { - inherit (darwin.apple_sdk.frameworks) CoreServices Security; - }; - - botan3 = callPackage ../development/libraries/botan/3.0.nix { - inherit (darwin.apple_sdk.frameworks) CoreServices Security; - }; + inherit (callPackages ../development/libraries/botan { }) + botan2 + botan3 + ; box2d = callPackage ../development/libraries/box2d { inherit (darwin.apple_sdk.frameworks) Carbon Cocoa Kernel OpenGL;