{ description = "Hello world Rust program statically linked against musl"; inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; outputs = { nixpkgs, ... }: let supportedSystems = [ "x86_64-linux" "aarch64-linux" ]; forAllSystems = nixpkgs.lib.genAttrs supportedSystems; mk = localSystem: crossSystem: rec { systems = (if localSystem == crossSystem then { system = localSystem; } else { inherit crossSystem localSystem; }); pkgs = (import nixpkgs systems).pkgsMusl; main = pkgs.rustPlatform.buildRustPackage { pname = "rust-musl-hello"; version = "0.1.0"; src = ./.; cargoLock = { lockFile = ./Cargo.lock; }; }; image = pkgs.dockerTools.streamLayeredImage { name = "rust-musl-dynamic-hello"; tag = "latest"; contents = [ pkgs.busybox main ]; config = { Cmd = [ "/bin/rust-musl-hello" ]; }; }; }; in { packages = forAllSystems (localSystem: { default = (mk localSystem localSystem).main; }); apps = forAllSystems (localSystem: let mkAI = remoteSystem: { type = "app"; program = toString (mk localSystem remoteSystem).image; }; in { mkImageI = mkAI "x86_64-linux"; mkImageA = mkAI "aarch64-linux"; }); devShells = forAllSystems (system: let pkgs = import nixpkgs { inherit system; }; in { default = pkgs.mkShell { buildInputs = with pkgs; [ cargo nixfmt ]; }; }); }; }