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,
pkgs,
system,
config,
self',
inputs',
...
}: let
crossPkgsFor = lib.fix (finalAttrs: {
"x86_64-linux" = {
"x86_64" = pkgs.pkgsStatic;
"aarch64" = pkgs.pkgsCross.aarch64-multiplatform.pkgsStatic;
crossPkgsFor =
rec {
x86_64-linux = {
x86_64 = pkgs.pkgsStatic;
aarch64 = pkgs.pkgsCross.aarch64-multiplatform.pkgsStatic;
};
"aarch64-linux" = {
"x86_64" = pkgs.pkgsCross.musl64;
"aarch64" = pkgs.pkgsStatic;
aarch64-linux = {
x86_64 = pkgs.pkgsCross.musl64;
aarch64 = pkgs.pkgsStatic;
};
"x86_64-darwin" = {
"x86_64" = pkgs.pkgsCross.musl64;
"aarch64" = pkgs.pkgsCross.aarch64-multiplatform.pkgsStatic;
x86_64-darwin = {
x86_64 = pkgs.pkgsCross.musl64;
aarch64 = pkgs.pkgsCross.aarch64-multiplatform.pkgsStatic;
};
"aarch64-darwin" = finalAttrs."x86_64-darwin";
});
aarch64-darwin = x86_64-darwin;
}
.${system};
exeFor = arch: let
target = "${arch}-unknown-linux-musl";
@ -49,21 +51,22 @@
rustc = toolchain;
};
refraction = config.packages.refraction.override {
refraction = self'.packages.refraction.override {
naersk = naersk';
optimizeSize = true;
};
inherit (crossPkgsFor.${system}.${arch}.stdenv) cc;
in
lib.getExe (
refraction.overrideAttrs (_:
lib.fix (finalAttrs: {
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
lib.getExe (
refraction.overrideAttrs (_: newAttrs)
);
containerFor = arch:
@ -73,7 +76,7 @@
contents = [pkgs.dockerTools.caCertificates];
config.Cmd = [(exeFor arch)];
architecture = crossPkgsFor.${system}.${arch}.go.GOARCH;
architecture = crossPkgsFor.${arch}.go.GOARCH;
};
in {
legacyPackages = {

View file

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