k3s: fix build for aarch64

The upstream project already builds and releases for aarch64. This makes
the couple small tweaks that I found necessary for k3s to cross-compile
for aarch64.

I also ran it through nixpkgs-fmt.
This commit is contained in:
Euan Kemp 2020-05-08 17:59:48 -07:00 committed by Frederik Rietdijk
parent 10134fc301
commit e61dc85117
2 changed files with 55 additions and 18 deletions

View file

@ -1,6 +1,22 @@
{ stdenv, lib, makeWrapper, socat, iptables, iproute, bridge-utils
, conntrack-tools, buildGoPackage, git, runc, libseccomp, pkgconfig
, ethtool, utillinux, ipset, fetchFromGitHub, fetchurl, fetchzip
{ stdenv
, lib
, makeWrapper
, socat
, iptables
, iproute
, bridge-utils
, conntrack-tools
, buildGoPackage
, git
, runc
, libseccomp
, pkgconfig
, ethtool
, utillinux
, ipset
, fetchFromGitHub
, fetchurl
, fetchzip
, fetchgit
}:
@ -47,7 +63,7 @@ let
# Note: marked as apache 2.0 license
url = "https://github.com/rancher/k3s-root/releases/download/v${k3sRootVersion}/k3s-root-amd64.tar";
sha256 = "12xafn5jivl8lqdcs25b28xrc4mf7yf1xif5np169nvvxgvmpdxp";
stripRoot=false;
stripRoot = false;
};
k3sPlugins = buildGoPackage rec {
name = "k3s-cni-plugins";
@ -153,6 +169,12 @@ let
nativeBuildInputs = [ git pkgconfig ];
buildInputs = [ k3sBuildStage1 k3sPlugins runc ];
# k3s appends a suffix to the final distribution binary for some arches
archSuffix =
if stdenv.hostPlatform.system == "x86_64-linux" then ""
else if stdenv.hostPlatform.system == "aarch64-linux" then "-arm64"
else throw "k3s isn't being built for ${stdenv.hostPlatform.system} yet.";
# In order to build the thick k3s binary (which is what
# ./scripts/package-cli does), we need to get all the binaries that script
# expects in place.
@ -182,7 +204,7 @@ let
pushd go/src/${goPackagePath}
mkdir -p "$out/bin"
install -m 0755 -t "$out/bin" ./dist/artifacts/k3s
install -m 0755 -T ./dist/artifacts/k3s${archSuffix} "$out/bin/k3s"
popd
'';
@ -202,12 +224,20 @@ stdenv.mkDerivation rec {
# Important utilities used by the kubelet, see
# https://github.com/kubernetes/kubernetes/issues/26093#issuecomment-237202494
# Note the list in that issue is stale and some aren't relevant for k3s.
k3sRuntimeDeps = [
socat iptables iproute bridge-utils ethtool utillinux ipset conntrack-tools
k3sRuntimeDeps = [
socat
iptables
iproute
bridge-utils
ethtool
utillinux
ipset
conntrack-tools
];
buildInputs = [
k3sBuild makeWrapper
buildInputs = [
k3sBuild
makeWrapper
] ++ k3sRuntimeDeps;
unpackPhase = "true";
@ -225,11 +255,11 @@ stdenv.mkDerivation rec {
--prefix PATH : "$out/bin"
'';
meta = {
description = "A lightweight Kubernetes distribution.";
license = licenses.asl20;
homepage = "https://k3s.io";
maintainers = [ maintainers.euank ];
platforms = platforms.linux;
};
meta = {
description = "A lightweight Kubernetes distribution.";
license = licenses.asl20;
homepage = "https://k3s.io";
maintainers = [ maintainers.euank ];
platforms = platforms.linux;
};
}

View file

@ -55,10 +55,17 @@ index 72d3c07ece..3e5455b262 100755
echo Building containerd-shim
make -C ./vendor/github.com/containerd/containerd bin/containerd-shim
diff --git a/scripts/package-cli b/scripts/package-cli
index 4c66ce32df..6d1e0c03cb 100755
index 4c66ce32df..280b428bb8 100755
--- a/scripts/package-cli
+++ b/scripts/package-cli
@@ -55,10 +55,10 @@ LDFLAGS="
@@ -49,16 +49,16 @@ fi
CMD_NAME=dist/artifacts/k3s${BIN_SUFFIX}
-go generate
+CGO_ENABLED=0 env -u GOARCH go generate
LDFLAGS="
-X github.com/rancher/k3s/pkg/version.Version=$VERSION
-X github.com/rancher/k3s/pkg/version.GitCommit=${COMMIT:0:8}
-w -s
"