diff --git a/flake.nix b/flake.nix index 55a32aa..2d71623 100644 --- a/flake.nix +++ b/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; } diff --git a/nix/static.nix b/nix/static.nix index c147999..94b30ea 100644 --- a/nix/static.nix +++ b/nix/static.nix @@ -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; + }; + })