nixpkgs/pkgs/by-name/kc/kcl/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

70 lines
1.8 KiB
Nix

{ lib
, stdenv
, buildGoModule
, fetchFromGitHub
, kclvm_cli
, kclvm
, makeWrapper
, installShellFiles
, darwin
,
}:
buildGoModule rec {
pname = "kcl";
version = "0.9.8";
src = fetchFromGitHub {
owner = "kcl-lang";
repo = "cli";
rev = "v${version}";
hash = "sha256-s8pFnItmw3+l9GKqdqX0Rxsy47h6vO+yUtVNCuyn/m8=";
};
vendorHash = "sha256-DGYYH5sKhpcWHYoUim4NyflzqsXFc4MCOqIw5jIfIiM=";
# By default, libs and bins are stripped. KCL will crash on darwin if they are.
dontStrip = stdenv.hostPlatform.isDarwin;
ldflags = [
"-w -s"
"-X=kcl-lang.io/cli/pkg/version.version=v${version}"
];
nativeBuildInputs = [ makeWrapper installShellFiles ];
buildInputs = [ kclvm kclvm_cli ] ++ (
lib.optional stdenv.hostPlatform.isDarwin [
darwin.apple_sdk.frameworks.Security
darwin.apple_sdk.frameworks.CoreServices
darwin.apple_sdk.frameworks.SystemConfiguration
]
);
subPackages = [ "cmd/kcl" ];
# env vars https://github.com/kcl-lang/kcl-go/blob/main/pkg/env/env.go#L29
postFixup = ''
wrapProgram $out/bin/kcl \
--prefix PATH : "${lib.makeBinPath [kclvm kclvm_cli]}" \
--prefix KCL_LIB_HOME : "${lib.makeLibraryPath [kclvm]}" \
--prefix KCL_GO_DISABLE_INSTALL_ARTIFACT : false
'';
postInstall = ''
export HOME=$(mktemp -d)
installShellCompletion --cmd kcl \
--bash <($out/bin/kcl completion bash) \
--fish <($out/bin/kcl completion fish) \
--zsh <($out/bin/kcl completion zsh)
'';
meta = with lib; {
description = "A command line interface for KCL programming language";
homepage = "https://github.com/kcl-lang/cli";
license = licenses.asl20;
platforms = platforms.linux ++ platforms.darwin;
maintainers = with maintainers; [ selfuryon peefy ];
mainProgram = "kcl";
};
}