nixpkgs/pkgs/by-name/me/melange/package.nix
aleksana 571c71e6f7 treewide: migrate packages to pkgs/by-name, take 1
We are migrating packages that meet below requirements:

1. using `callPackage`
2. called path is a directory
3. overriding set is empty (`{ }`)
4. not containing path expressions other than relative path (to
makenixpkgs-vet happy)
5. not referenced by nix files outside of the directory, other
than`pkgs/top-level/all-packages.nix`
6. not referencing nix files outside of the directory
7. not referencing `default.nix` (since it's changed to `package.nix`)
8. `outPath` doesn't change after migration

The tool is here: https://github.com/Aleksanaa/by-name-migrate.
2024-11-09 20:04:51 +08:00

74 lines
2.0 KiB
Nix

{ lib
, buildGoModule
, fetchFromGitHub
, installShellFiles
}:
buildGoModule rec {
pname = "melange";
version = "0.14.10";
src = fetchFromGitHub {
owner = "chainguard-dev";
repo = pname;
rev = "v${version}";
hash = "sha256-fHHIIlxKTF4q9LOeL3jyLS7HQ/IFmx+1fS/7PitrclM=";
# populate values that require us to use git. By doing this in postFetch we
# can delete .git afterwards and maintain better reproducibility of the src.
leaveDotGit = true;
postFetch = ''
cd "$out"
git rev-parse HEAD > $out/COMMIT
# in format of 0000-00-00T00:00:00Z
date -u -d "@$(git log -1 --pretty=%ct)" "+%Y-%m-%dT%H:%M:%SZ" > $out/SOURCE_DATE_EPOCH
find "$out" -name .git -print0 | xargs -0 rm -rf
'';
};
vendorHash = "sha256-Okil1H6+O8YjTptI00mQQ1+04OiuO/zf1L8es4CdnNc=";
subPackages = [ "." ];
nativeBuildInputs = [ installShellFiles ];
ldflags = [
"-s"
"-w"
"-X sigs.k8s.io/release-utils/version.gitVersion=v${version}"
"-X sigs.k8s.io/release-utils/version.gitTreeState=clean"
];
# ldflags based on metadata from git and source
preBuild = ''
ldflags+=" -X sigs.k8s.io/release-utils/version.gitCommit=$(cat COMMIT)"
ldflags+=" -X sigs.k8s.io/release-utils/version.buildDate=$(cat SOURCE_DATE_EPOCH)"
'';
postInstall = ''
installShellCompletion --cmd melange \
--bash <($out/bin/melange completion bash) \
--fish <($out/bin/melange completion fish) \
--zsh <($out/bin/melange completion zsh)
'';
doInstallCheck = true;
installCheckPhase = ''
runHook preInstallCheck
$out/bin/melange --help
$out/bin/melange version 2>&1 | grep "v${version}"
runHook postInstallCheck
'';
meta = with lib; {
homepage = "https://github.com/chainguard-dev/melange";
changelog = "https://github.com/chainguard-dev/melange/blob/${src.rev}/NEWS.md";
description = "Build APKs from source code";
mainProgram = "melange";
license = licenses.asl20;
maintainers = with maintainers; [ developer-guy ];
};
}