nixpkgs/pkgs/by-name/ar/arduino-cli/package.nix
Artturin e0464e4788 treewide: replace stdenv.is with stdenv.hostPlatform.is
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"
```
2024-09-25 00:04:37 +03:00

114 lines
2.9 KiB
Nix

{
lib,
stdenv,
buildGoModule,
fetchFromGitHub,
buildFHSEnv,
installShellFiles,
go-task,
}:
let
pkg = buildGoModule rec {
pname = "arduino-cli";
version = "1.0.4";
src = fetchFromGitHub {
owner = "arduino";
repo = pname;
rev = "refs/tags/v${version}";
hash = "sha256-0a2YlgswjiZT1aPO513IZTb/Pba0IydvB0je3e6rN9M=";
};
nativeBuildInputs = [ installShellFiles ];
nativeCheckInputs = [ go-task ];
subPackages = [ "." ];
vendorHash = "sha256-53gQrYgdQ/54+KAQwfUZWebz7Tb1cEt8jGd9PbhS87s=";
postPatch =
let
skipTests = [
# tries to "go install"
"TestDummyMonitor"
# try to Get "https://downloads.arduino.cc/libraries/library_index.tar.bz2"
"TestDownloadAndChecksums"
"TestParseArgs"
"TestParseReferenceCores"
"TestPlatformSearch"
"TestPlatformSearchSorting"
];
in
''
substituteInPlace Taskfile.yml \
--replace-fail "go test" "go test -p $NIX_BUILD_CORES -skip '(${lib.concatStringsSep "|" skipTests})'"
'';
doCheck = stdenv.hostPlatform.isLinux;
checkPhase = ''
runHook preCheck
task go:test
runHook postCheck
'';
ldflags = [
"-s"
"-w"
"-X github.com/arduino/arduino-cli/version.versionString=${version}"
"-X github.com/arduino/arduino-cli/version.commit=unknown"
] ++ lib.optionals stdenv.hostPlatform.isLinux [ "-extldflags '-static'" ];
postInstall = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
export HOME="$(mktemp -d)"
installShellCompletion --cmd arduino-cli \
--bash <($out/bin/arduino-cli completion bash) \
--zsh <($out/bin/arduino-cli completion zsh) \
--fish <($out/bin/arduino-cli completion fish)
unset HOME
'';
meta = with lib; {
inherit (src.meta) homepage;
description = "Arduino from the command line";
mainProgram = "arduino-cli";
changelog = "https://github.com/arduino/arduino-cli/releases/tag/${version}";
license = [
licenses.gpl3Only
licenses.asl20
];
maintainers = with maintainers; [
ryantm
sfrijters
];
};
};
in
if stdenv.hostPlatform.isLinux then
# buildFHSEnv is needed because the arduino-cli downloads compiler
# toolchains from the internet that have their interpreters pointed at
# /lib64/ld-linux-x86-64.so.2
buildFHSEnv {
inherit (pkg) name meta;
runScript = "${pkg.outPath}/bin/arduino-cli";
extraInstallCommands =
''
mv $out/bin/$name $out/bin/arduino-cli
''
+ lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
cp -r ${pkg.outPath}/share $out/share
'';
passthru.pureGoPkg = pkg;
targetPkgs = pkgs: with pkgs; [ zlib ];
}
else
pkg