@@ -74,7 +74,7 @@ pkgsCross.mmix
7474If you want to set ` pkgs ` to a cross-compilation toolchain globally in a flake, you only
7575need to add a Module in ` flake.nix ` , as shown below:
7676
77- ``` nix{15-20 }
77+ ``` nix{12-17 }
7878{
7979 description = "NixOS running on LicheePi 4A";
8080
@@ -84,16 +84,14 @@ need to add a Module in `flake.nix`, as shown below:
8484
8585 outputs = inputs@{ self, nixpkgs, ... }: {
8686 nixosConfigurations.lp4a = nixpkgs.lib.nixosSystem {
87- # native platform
88- system = "x86_64-linux";
8987 modules = [
90-
91- # add this module, to enable cross-compilation.
9288 {
93- nixpkgs.crossSystem = {
94- # target platform
95- system = "riscv64-linux";
96- };
89+ # the platform that performs the build-step
90+ nixpkgs.localSystem.system = "x86_64-linux";
91+
92+ # the platform that will execute the resulting binaries
93+ # add this to enable cross-compilation.
94+ nixpkgs.crossSystem.system = "riscv64-linux";
9795 }
9896
9997 # ...... other modules
@@ -131,7 +129,7 @@ your NixOS Module to enable the simulated build system of `aarch64-linux` and
131129As for ` flake.nix ` , its setting method is very simple, even simpler than the setting of
132130cross-compilation, as shown below:
133131
134- ``` nix{11 }
132+ ``` nix{13 }
135133{
136134 description = "NixOS running on LicheePi 4A";
137135
@@ -141,17 +139,18 @@ cross-compilation, as shown below:
141139
142140 outputs = inputs@{ self, nixpkgs, ... }: {
143141 nixosConfigurations.lp4a = nixpkgs.lib.nixosSystem {
144- # native platform
145- system = "riscv64-linux";
146142 modules = [
143+ # the native platform
144+ # usually this is already set in the generated `hardware-configuration.nix` and can be omit.
145+ { nixpkgs.hostPlatform = "riscv64-linux"; }
147146 # ...... other modules
148147 ];
149148 };
150149 };
151150}
152151```
153152
154- You do not need to add any additional modules, just specify ` system ` as ` riscv64-linux ` .
153+ You do not need to add any additional modules, just specify ` nixpkgs.hostPlatform ` as ` riscv64-linux ` .
155154Nix will automatically detect whether the current system is ` riscv64-linux ` during the
156155build. If not, it will automatically build through the emulated system(QEMU). For users,
157156these underlying operations are completely transparent.
@@ -223,20 +222,20 @@ Loading installable ''...
223222Added 17755 variables.
224223
225224# replace gcc through overlays, this will create a new instance of nixpkgs
226- nix-repl> a = import < nixpkgs> { crossSystem = { config = " riscv64-unknown- linux-gnu " ; } ; overlays = [ (self: super: { gcc = self.gcc12 ; }) ]; }
225+ nix-repl> a = import < nixpkgs> { crossSystem = " riscv64-linux" ; overlays = [ (self: super: { gcc = self.gcc13 ; }) ]; }
227226
228227# check the gcc version, it is indeed changed to 12.2
229228nix-repl> a.pkgsCross.riscv64.stdenv.cc
230- «derivation /nix/store/jjvvwnf3hzk71p65x1n8bah3hrs08bpf -riscv64-unknown-linux-gnu-stage-final- gcc-wrapper-12.2 .0.drv»
229+ «derivation /nix/store/kdi3g7px1bxz2r1jmjnr4pahscw8jj96 -riscv64-unknown-linux-gnu-gcc-wrapper-13.4 .0.drv»
231230
232231# take a look at the default pkgs, it is still 11.3
233232nix-repl> pkgs.pkgsCross.riscv64.stdenv.cc
234- «derivation /nix/store/pq3g0wq3yfc4hqrikr03ixmhqxbh35q7 -riscv64-unknown-linux-gnu-stage-final- gcc-wrapper-11 .3.0.drv»
233+ «derivation /nix/store/xd8s47j71z3lym5f2j9zy3v9r0ifw209 -riscv64-unknown-linux-gnu-gcc-wrapper-14 .3.0.drv»
235234```
236235
237236So how to use this method in Flakes? The example ` flake.nix ` is as follows:
238237
239- ``` nix{13-20 }
238+ ``` nix{20-21 }
240239{
241240 description = "NixOS running on LicheePi 4A";
242241
@@ -247,15 +246,17 @@ So how to use this method in Flakes? The example `flake.nix` is as follows:
247246 outputs = { self, nixpkgs, ... }:
248247 {
249248 nixosConfigurations.lp4a = nixpkgs.lib.nixosSystem {
250- system = "x86_64-linux";
251249 modules = [
252250 {
253- nixpkgs.crossSystem = {
254- config = "riscv64-unknown-linux-gnu";
255- };
251+ # the platform that performs the build-step
252+ nixpkgs.localSystem.system = "x86_64-linux";
256253
257- # replace gcc with gcc12 through overlays
258- nixpkgs.overlays = [ (self: super: { gcc = self.gcc12; }) ];
254+ # the platform that will execute the resulting binaries
255+ # add this to enable cross-compilation.
256+ nixpkgs.crossSystem.system = "riscv64-linux";
257+
258+ # replace gcc with gcc13 through overlays
259+ nixpkgs.overlays = [ (self: super: { gcc = self.gcc13; }) ];
259260 }
260261
261262 # other modules ......
@@ -273,7 +274,7 @@ To avoid this problem, a better way is to create a new `pkgs` instance, and only
273274instance when building the packages we want to modify. The example ` flake.nix ` is as
274275follows:
275276
276- ``` nix{10-19,34-37 }
277+ ``` nix{10-17,32 }
277278{
278279 description = "NixOS running on LicheePi 4A";
279280
@@ -283,33 +284,29 @@ follows:
283284
284285 outputs = { self, nixpkgs, ... }: let
285286 # create a new pkgs instance with overlays
286- pkgs-gcc12 = import nixpkgs {
287+ pkgs-gcc13 = import nixpkgs {
287288 localSystem = "x86_64-linux";
288- crossSystem = {
289- config = "riscv64-unknown-linux-gnu";
290- };
289+ crossSystem = "riscv64-linux";
291290
292291 overlays = [
293- (self: super: { gcc = self.gcc12 ; })
292+ (self: super: { gcc = self.gcc13 ; })
294293 ];
295294 };
296295 in {
297296 nixosConfigurations.lp4a = nixpkgs.lib.nixosSystem {
298- system = "x86_64-linux";
299297 specialArgs = {
300298 # pass the new pkgs instance to the module
301- inherit pkgs-gcc12 ;
299+ inherit pkgs-gcc13 ;
302300 };
303301 modules = [
304302 {
305- nixpkgs.crossSystem = {
306- config = "riscv64-unknown-linux-gnu";
307- };
303+ nixpkgs.localSystem.system = "x86_64-linux";
304+ nixpkgs.crossSystem.system = "riscv64-linux";
308305 }
309306
310- ({pkgs-gcc12 , ...}: {
307+ ({pkgs-gcc13 , ...}: {
311308 # use the custom pkgs instance to build the package hello
312- environment.systemPackages = [ pkgs-gcc12 .hello ];
309+ environment.systemPackages = [ pkgs-gcc13 .hello ];
313310 })
314311
315312 # other modules ......
0 commit comments