nix/deployment: pre-select system in crossPkgsFor

This commit is contained in:
seth 2024-01-08 15:02:36 -05:00
parent f0550dd429
commit f2a3582c77
No known key found for this signature in database
GPG key ID: D31BD0D494BBEE86
2 changed files with 31 additions and 27 deletions

View file

@ -9,28 +9,30 @@
lib, lib,
pkgs, pkgs,
system, system,
config, self',
inputs', inputs',
... ...
}: let }: let
crossPkgsFor = lib.fix (finalAttrs: { crossPkgsFor =
"x86_64-linux" = { rec {
"x86_64" = pkgs.pkgsStatic; x86_64-linux = {
"aarch64" = pkgs.pkgsCross.aarch64-multiplatform.pkgsStatic; x86_64 = pkgs.pkgsStatic;
}; aarch64 = pkgs.pkgsCross.aarch64-multiplatform.pkgsStatic;
};
"aarch64-linux" = { aarch64-linux = {
"x86_64" = pkgs.pkgsCross.musl64; x86_64 = pkgs.pkgsCross.musl64;
"aarch64" = pkgs.pkgsStatic; aarch64 = pkgs.pkgsStatic;
}; };
"x86_64-darwin" = { x86_64-darwin = {
"x86_64" = pkgs.pkgsCross.musl64; x86_64 = pkgs.pkgsCross.musl64;
"aarch64" = pkgs.pkgsCross.aarch64-multiplatform.pkgsStatic; aarch64 = pkgs.pkgsCross.aarch64-multiplatform.pkgsStatic;
}; };
"aarch64-darwin" = finalAttrs."x86_64-darwin"; aarch64-darwin = x86_64-darwin;
}); }
.${system};
exeFor = arch: let exeFor = arch: let
target = "${arch}-unknown-linux-musl"; target = "${arch}-unknown-linux-musl";
@ -49,21 +51,22 @@
rustc = toolchain; rustc = toolchain;
}; };
refraction = config.packages.refraction.override { refraction = self'.packages.refraction.override {
naersk = naersk'; naersk = naersk';
optimizeSize = true; optimizeSize = true;
}; };
inherit (crossPkgsFor.${system}.${arch}.stdenv) cc; newAttrs = lib.fix (finalAttrs: {
CARGO_BUILD_TARGET = target;
"CC_${target'}" = "${cc}/bin/${cc.targetPrefix}cc";
"CARGO_TARGET_${targetUpper}_RUSTFLAGS" = "-C target-feature=+crt-static";
"CARGO_TARGET_${targetUpper}_LINKER" = finalAttrs."CC_${target'}";
});
inherit (crossPkgsFor.${arch}.stdenv) cc;
in in
lib.getExe ( lib.getExe (
refraction.overrideAttrs (_: refraction.overrideAttrs (_: newAttrs)
lib.fix (finalAttrs: {
CARGO_BUILD_TARGET = target;
"CC_${target'}" = "${cc}/bin/${cc.targetPrefix}cc";
"CARGO_TARGET_${targetUpper}_RUSTFLAGS" = "-C target-feature=+crt-static";
"CARGO_TARGET_${targetUpper}_LINKER" = finalAttrs."CC_${target'}";
}))
); );
containerFor = arch: containerFor = arch:
@ -73,7 +76,7 @@
contents = [pkgs.dockerTools.caCertificates]; contents = [pkgs.dockerTools.caCertificates];
config.Cmd = [(exeFor arch)]; config.Cmd = [(exeFor arch)];
architecture = crossPkgsFor.${system}.${arch}.go.GOARCH; architecture = crossPkgsFor.${arch}.go.GOARCH;
}; };
in { in {
legacyPackages = { legacyPackages = {

View file

@ -3,6 +3,7 @@
lib, lib,
pkgs, pkgs,
config, config,
self',
... ...
}: { }: {
pre-commit.settings.hooks = { pre-commit.settings.hooks = {
@ -38,7 +39,7 @@
rust-analyzer rust-analyzer
# nix # nix
config.formatter self'.formatter
nil nil
]; ];