mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-01-08 14:03:29 +00:00
e0464e4788
In preparation for the deprecation of `stdenv.isX`. These shorthands are not conducive to cross-compilation because they hide the platforms. Darwin might get cross-compilation for which the continued usage of `stdenv.isDarwin` will get in the way One example of why this is bad and especially affects compiler packages https://www.github.com/NixOS/nixpkgs/pull/343059 There are too many files to go through manually but a treewide should get users thinking when they see a `hostPlatform.isX` in a place where it doesn't make sense. ``` fd --type f "\.nix" | xargs sd --fixed-strings "stdenv.is" "stdenv.hostPlatform.is" fd --type f "\.nix" | xargs sd --fixed-strings "stdenv'.is" "stdenv'.hostPlatform.is" fd --type f "\.nix" | xargs sd --fixed-strings "clangStdenv.is" "clangStdenv.hostPlatform.is" fd --type f "\.nix" | xargs sd --fixed-strings "gccStdenv.is" "gccStdenv.hostPlatform.is" fd --type f "\.nix" | xargs sd --fixed-strings "stdenvNoCC.is" "stdenvNoCC.hostPlatform.is" fd --type f "\.nix" | xargs sd --fixed-strings "inherit (stdenv) is" "inherit (stdenv.hostPlatform) is" fd --type f "\.nix" | xargs sd --fixed-strings "buildStdenv.is" "buildStdenv.hostPlatform.is" fd --type f "\.nix" | xargs sd --fixed-strings "effectiveStdenv.is" "effectiveStdenv.hostPlatform.is" fd --type f "\.nix" | xargs sd --fixed-strings "originalStdenv.is" "originalStdenv.hostPlatform.is" ```
52 lines
1.8 KiB
Nix
52 lines
1.8 KiB
Nix
{ lib
|
||
, stdenv
|
||
, fetchurl
|
||
, unzip
|
||
}:
|
||
|
||
let
|
||
platforms = {
|
||
aarch64-linux = { folder = "aarch64"; ld-linux = "ld-linux-aarch64.so.1"; };
|
||
armv7l-linux = { folder = "armv7"; ld-linux = "ld-linux-armhf.so.3"; };
|
||
i686-linux = { folder = "i686"; ld-linux = "ld-linux.so.2"; };
|
||
x86_64-darwin = { folder = "."; };
|
||
x86_64-linux = { folder = "amd64"; ld-linux = "ld-linux-x86-64.so.2"; };
|
||
};
|
||
platform = platforms."${stdenv.hostPlatform.system}"
|
||
or (throw "Unsupported system: ${stdenv.hostPlatform.system}");
|
||
download = if stdenv.hostPlatform.isDarwin
|
||
then { extension = "macos.zip"; hash = "sha256-MnL6lH7q/BrACG4fFJNfnvoh0JClVeaJIlX+XIj2aG4="; }
|
||
else { extension = "linux.tar.gz"; hash = "sha256-rDi7pvDeKQM96GZTjDr6ZDQTGbaVu+OI77xf2egw6Sg="; };
|
||
in
|
||
stdenv.mkDerivation rec {
|
||
pname = "pngout";
|
||
version = "20200115";
|
||
|
||
src = fetchurl {
|
||
inherit (download) hash;
|
||
url = "http://static.jonof.id.au/dl/kenutils/pngout-${version}-${download.extension}";
|
||
};
|
||
|
||
nativeBuildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ unzip ];
|
||
|
||
# pngout is code-signed on Darwin, so don’t alter the binary to avoid breaking the signature.
|
||
dontFixup = stdenv.hostPlatform.isDarwin;
|
||
|
||
installPhase = ''
|
||
mkdir -p $out/bin
|
||
cp ${platform.folder}/pngout $out/bin
|
||
'' + lib.optionalString stdenv.hostPlatform.isLinux ''
|
||
patchelf --set-interpreter ${stdenv.cc.libc}/lib/${platform.ld-linux} $out/bin/pngout
|
||
'';
|
||
|
||
meta = {
|
||
description = "Tool that aggressively optimizes the sizes of PNG images";
|
||
sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
|
||
license = lib.licenses.unfreeRedistributable;
|
||
homepage = "http://advsys.net/ken/utils.htm";
|
||
platforms = lib.attrNames platforms;
|
||
maintainers = [ lib.maintainers.sander ];
|
||
mainProgram = "pngout";
|
||
};
|
||
}
|