diff --git a/.cirrus.yml b/.cirrus.yml index 5beb1f2f..2653dafe 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -166,3 +166,55 @@ static_binary_task: save_cache_script: | mv /nix .cache chown -Rf $(whoami) .cache + +# Build the static binary for arm64 +static_binary_arm64_task: + # depends_on: + # - 'config' + # - 'fmt' + + gce_instance: + image_name: "${FEDORA_CACHE_IMAGE_NAME}" + cpu: 8 + memory: 12 + disk: 200 + + # Community-maintained task, may fail on occasion. If so, uncomment + # the next line and file an issue with details about the failure. + # allow_failures: true + + timeout_in: '20m' + + env: + # Do not use 'latest', fixed-version tag for runtime stability. + CTR_FQIN: "docker.io/nixos/nix:2.3.6" + # Authentication token for pushing the build cache to cachix. + # This is critical, it helps to avoid a very lengthy process of + # statically building every dependency needed to build podman. + # Assuming the pinned nix dependencies in nix/nixpkgs.json have not + # changed, this cache will ensure that only the static podman binary is + # built. + # CACHIX_AUTH_TOKEN: ENCRYPTED[] + + init_script: | + set -ex + setenforce 0 + growpart /dev/sda 1 || true + resize2fs /dev/sda1 || true + + build_script: | + set -ex + podman run -i --rm \ + -e CACHIX_AUTH_TOKEN \ + -v $PWD:$PWD:Z \ + -w $PWD \ + $CTR_FQIN \ + sh -c \ + "nix-env -iA cachix -f https://cachix.org/api/v1/install && \ + cachix use conmon && \ + nix-build nix/default-arm64.nix && \ + nix-store -qR --include-outputs \$(nix-instantiate nix/default.nix) | grep -v conmon | cachix push conmon && \ + cp -R result/bin ." + + binaries_artifacts: + path: "bin/conmon" diff --git a/nix/default-arm64.nix b/nix/default-arm64.nix new file mode 100644 index 00000000..f6e08b6a --- /dev/null +++ b/nix/default-arm64.nix @@ -0,0 +1,95 @@ +let + pkgs = (import ./nixpkgs.nix { + crossSystem = { + config = "aarch64-unknown-linux-gnu"; + }; + overlays = [ + (final: pkg: { + pcre = (static pkg.pcre).overrideAttrs (x: { + configureFlags = x.configureFlags ++ [ + "--enable-static" + ]; + }); + }) + ]; + config = { + packageOverrides = pkg: { + autogen = (static pkg.autogen); + e2fsprogs = (static pkg.e2fsprogs); + libuv = (static pkg.libuv); + glib = (static pkg.glib).overrideAttrs (x: { + outputs = [ "bin" "out" "dev" ]; + mesonFlags = [ + "-Ddefault_library=static" + "-Ddevbindir=${placeholder ''dev''}/bin" + "-Dgtk_doc=false" + "-Dnls=disabled" + ]; + postInstall = '' + moveToOutput "share/glib-2.0" "$dev" + substituteInPlace "$dev/bin/gdbus-codegen" --replace "$out" "$dev" + sed -i "$dev/bin/glib-gettextize" -e "s|^gettext_dir=.*|gettext_dir=$dev/share/glib-2.0/gettext|" + sed '1i#line 1 "${x.pname}-${x.version}/include/glib-2.0/gobject/gobjectnotifyqueue.c"' \ + -i "$dev"/include/glib-2.0/gobject/gobjectnotifyqueue.c + ''; + }); + gnutls = (static pkg.gnutls).overrideAttrs (x: { + configureFlags = (x.configureFlags or [ ]) ++ [ + "--disable-non-suiteb-curves" + "--disable-openssl-compatibility" + "--disable-rpath" + "--enable-local-libopts" + "--without-p11-kit" + ]; + }); + systemd = (static pkg.systemd).overrideAttrs (x: { + outputs = [ "out" "dev" ]; + mesonFlags = x.mesonFlags ++ [ + "-Dstatic-libsystemd=true" + ]; + }); + }; + }; + }); + + static = pkg: pkg.overrideAttrs (x: { + doCheck = false; + configureFlags = (x.configureFlags or [ ]) ++ [ + "--without-shared" + "--disable-shared" + ]; + dontDisableStatic = true; + enableSharedExecutables = false; + enableStatic = true; + }); + + self = with pkgs; stdenv.mkDerivation rec { + name = "conmon"; + src = ./..; + vendorSha256 = null; + doCheck = false; + enableParallelBuilding = true; + outputs = [ "out" ]; + nativeBuildInputs = with buildPackages; [ + bash + gitMinimal + pcre + pkg-config + which + ]; + buildInputs = [ glibc glibc.static glib ]; + prePatch = '' + export CFLAGS='-static -pthread' + export LDFLAGS='-s -w -static-libgcc -static' + export EXTRA_LDFLAGS='-s -w -linkmode external -extldflags "-static -lm"' + ''; + buildPhase = '' + patchShebangs . + make + ''; + installPhase = '' + install -Dm755 bin/conmon $out/bin/conmon + ''; + }; +in +self