@@ -59,7 +59,7 @@ Requirements
5959 overlays = [steiger.overlays.ociTools];
6060 pkgs = import nixpkgs { inherit system overlays; };
6161 in {
62- packages .${system} = {
62+ steigerImages .${system} = {
6363 default = pkgs.ociTools.buildImage {
6464 name = "hello";
6565
@@ -85,6 +85,126 @@ Requirements
8585
8686</details >
8787
88+ #### Cross-compilation
89+
90+ Steiger provides a nested outputs structure for organizing packages when you need to
91+ configure cross-compilation yourself using specialized tools like crane for Rust projects.
92+
93+ ##### Configuration
94+
95+ Enable the nested path structure by adding the following to your ` steiger.yaml ` :
96+
97+ ``` yaml
98+ build :
99+ services :
100+ type : nix
101+ platformStrategy : crossSystem
102+ packages :
103+ service : default
104+ ` ` `
105+
106+ This changes how packages should be organized in your flake outputs,
107+ creating a nested structure that separates build host and target systems.
108+
109+ ##### Attribute Path Structure
110+
111+ When ` platformStrategy: crossSystem` is enabled, packages must be organized as:
112+ ` <flake-path>#steigerImages.<host-system>.<target-system>.<package-name>`
113+
114+ Examples :
115+
116+ - ` #steigerImages.x86_64-linux.aarch64-linux.default` - Build on x86_64-linux, targeting aarch64-linux
117+ - ` #steigerImages.aarch64-darwin.x86_64-linux.default` - Build on aarch64-darwin, targeting x86_64-linux
118+ - ` #steigerImages.x86_64-linux.x86_64-linux.default` - Native build on x86_64-linux
119+
120+ This nested structure allows you to :
121+
122+ - Build for all combinations of host and target systems
123+ - Configure your own cross-compilation toolchains
124+ - Maintain clear separation between build-time and runtime dependencies
125+
126+ <details>
127+ <summary>Example of rust cross-compilation with crane</summary>
128+
129+ ` ` ` nix
130+ {
131+ inputs = {
132+ nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
133+ steiger.url = "github:brainhivenl/steiger";
134+ crane.url = "github:ipetkov/crane";
135+ rust-overlay = {
136+ url = "github:oxalica/rust-overlay";
137+ inputs.nixpkgs.follows = "nixpkgs";
138+ };
139+ };
140+
141+ outputs = {
142+ nixpkgs,
143+ steiger,
144+ crane,
145+ rust-overlay,
146+ ...
147+ }: let
148+ systems = ["aarch64-darwin" "x86_64-darwin" "x86_64-linux" "aarch64-linux"];
149+ overlays = [steiger.overlays.ociTools (import rust-overlay)];
150+
151+ eachCrossSystem = packages:
152+ nixpkgs.lib.genAttrs systems (localSystem:
153+ nixpkgs.lib.genAttrs systems (crossSystem:
154+ packages localSystem crossSystem));
155+
156+ # for more information see:
157+ # https://github.com/ipetkov/crane/blob/master/examples/cross-rust-overlay/flake.nix
158+ crateExpression = {
159+ craneLib,
160+ openssl,
161+ libiconv,
162+ lib,
163+ pkg-config,
164+ stdenv,
165+ }:
166+ craneLib.buildPackage {
167+ src = craneLib.cleanCargoSource ./.;
168+ strictDeps = true;
169+
170+ nativeBuildInputs =
171+ [pkg-config]
172+ ++ lib.optionals stdenv.buildPlatform.isDarwin [libiconv];
173+
174+ buildInputs = [openssl];
175+ };
176+ in {
177+ steigerImages = eachCrossSystem (localSystem: crossSystem: let
178+ pkgs = import nixpkgs {
179+ system = localSystem;
180+ inherit overlays;
181+ };
182+ pkgsCross = import nixpkgs {
183+ inherit localSystem crossSystem overlays;
184+ };
185+
186+ craneLib = crane.mkLib pkgsCross;
187+ package = pkgsCross.callPackage crateExpression {inherit craneLib;};
188+ in {
189+ default = pkgs.ociTools.buildImage {
190+ name = "my-service";
191+
192+ copyToRoot = pkgsCross.buildEnv {
193+ name = "service-env";
194+ paths = [package];
195+ pathsToLink = ["/bin"];
196+ };
197+
198+ config.Cmd = ["/bin/${package.pname}"];
199+ compressor = "none";
200+ };
201+ });
202+ };
203+ }
204+ ` ` `
205+
206+ </details>
207+
88208# # Build Caching
89209
90210Steiger delegates caching to the underlying build systems rather than implementing its own cache layer :
0 commit comments