perf(nix): refactor mkStatic
this should speed up evaluation a bit by caching all the things
This commit is contained in:
parent
1b5c6d14d1
commit
55bc54722e
2 changed files with 22 additions and 18 deletions
12
flake.nix
12
flake.nix
|
@ -71,17 +71,17 @@
|
|||
packages' = self.packages.${system};
|
||||
|
||||
mkStatic = pkgs.callPackage ./nix/static.nix {
|
||||
inherit (self.packages.${pkgs.system}) refraction;
|
||||
inherit (packages') refraction;
|
||||
rust-overlay = rust-overlay.packages.${system};
|
||||
};
|
||||
|
||||
mkContainerFor =
|
||||
containerize =
|
||||
refraction:
|
||||
pkgs.dockerTools.buildLayeredImage {
|
||||
name = "refraction";
|
||||
tag = "latest-${refraction.stdenv.hostPlatform.qemuArch}";
|
||||
tag = "latest-${refraction.passthru.architecture}";
|
||||
config.Cmd = [ (lib.getExe refraction) ];
|
||||
inherit (refraction) architecture;
|
||||
inherit (refraction.passthru) architecture;
|
||||
};
|
||||
in
|
||||
{
|
||||
|
@ -89,8 +89,8 @@
|
|||
|
||||
static-x86_64 = mkStatic { arch = "x86_64"; };
|
||||
static-aarch64 = mkStatic { arch = "aarch64"; };
|
||||
container-x86_64 = mkContainerFor packages'.static-x86_64;
|
||||
container-aarch64 = mkContainerFor packages'.static-aarch64;
|
||||
container-x86_64 = containerize packages'.static-x86_64;
|
||||
container-aarch64 = containerize packages'.static-aarch64;
|
||||
|
||||
default = packages'.refraction;
|
||||
}
|
||||
|
|
|
@ -4,30 +4,34 @@
|
|||
rust-overlay,
|
||||
pkgsCross,
|
||||
}:
|
||||
{ arch }:
|
||||
let
|
||||
targets = with pkgsCross; {
|
||||
crossPlatformFor = with pkgsCross; {
|
||||
x86_64 = musl64.pkgsStatic;
|
||||
aarch64 = aarch64-multiplatform.pkgsStatic;
|
||||
};
|
||||
|
||||
getRustcTarget = pkgs: pkgs.stdenv.hostPlatform.rust.rustcTarget;
|
||||
toolchain = rust-overlay.rust.minimal.override {
|
||||
extensions = [ "rust-std" ];
|
||||
targets = lib.mapAttrsToList (lib.const getRustcTarget) targets;
|
||||
targets = lib.mapAttrsToList (_: pkgs: pkgs.stdenv.hostPlatform.rust.rustcTarget) crossPlatformFor;
|
||||
};
|
||||
|
||||
mkRustPlatformWith =
|
||||
pkgs:
|
||||
rustPlatformFor = lib.mapAttrs (
|
||||
_: pkgs:
|
||||
pkgs.makeRustPlatform (
|
||||
lib.genAttrs [
|
||||
"cargo"
|
||||
"rustc"
|
||||
] (lib.const toolchain)
|
||||
);
|
||||
rustPlatforms = lib.mapAttrs (lib.const mkRustPlatformWith) targets;
|
||||
] (_: toolchain)
|
||||
)
|
||||
) crossPlatformFor;
|
||||
in
|
||||
refraction.override {
|
||||
rustPlatform = rustPlatforms.${arch};
|
||||
{ arch }:
|
||||
(refraction.override {
|
||||
rustPlatform = rustPlatformFor.${arch};
|
||||
optimizeSize = true;
|
||||
}
|
||||
}).overrideAttrs
|
||||
(old: {
|
||||
passthru = old.passthru or { } // {
|
||||
inherit toolchain;
|
||||
};
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue