1 # [nixpkgs]$ nix-build -A nixosTests.nixpkgs --show-trace
3 { evalMinimalConfig, pkgs, lib, stdenv }:
5 eval = mod: evalMinimalConfig {
6 imports = [ ../nixpkgs.nix mod ];
9 nixpkgs.hostPlatform = "aarch64-linux";
11 withHostAndBuild = eval {
12 nixpkgs.hostPlatform = "aarch64-linux";
13 nixpkgs.buildPlatform = "aarch64-darwin";
15 withSameHostAndBuild = eval {
16 nixpkgs.hostPlatform = "aarch64-linux";
17 nixpkgs.buildPlatform = "aarch64-linux";
19 externalPkgsWithConfig = {
20 _file = "ext-pkgs-config.nix";
22 nixpkgs.config.allowUnfree = true;
25 _file = "ambiguous.nix";
26 nixpkgs.hostPlatform = "aarch64-linux";
27 nixpkgs.buildPlatform = "aarch64-darwin";
28 nixpkgs.system = "x86_64-linux";
29 nixpkgs.localSystem.system = "x86_64-darwin";
30 nixpkgs.crossSystem.system = "i686-linux";
32 { _file = "repeat.nix";
33 nixpkgs.hostPlatform = "aarch64-linux";
39 uncheckedEval = lib.evalModules { modules = [ ../nixpkgs.nix module ]; };
40 in map (ass: ass.message) (lib.filter (ass: !ass.assertion) uncheckedEval.config.assertions);
42 readOnlyUndefined = evalMinimalConfig {
43 imports = [ ./read-only.nix ];
46 readOnlyBad = evalMinimalConfig {
47 imports = [ ./read-only.nix ];
51 readOnly = evalMinimalConfig {
52 imports = [ ./read-only.nix ];
56 readOnlyBadConfig = evalMinimalConfig {
57 imports = [ ./read-only.nix ];
59 nixpkgs.config.allowUnfree = true; # do in pkgs instead!
62 readOnlyBadOverlays = evalMinimalConfig {
63 imports = [ ./read-only.nix ];
65 nixpkgs.overlays = [ (_: _: {}) ]; # do in pkgs instead!
68 readOnlyBadHostPlatform = evalMinimalConfig {
69 imports = [ ./read-only.nix ];
71 nixpkgs.hostPlatform = "foo-linux"; # do in pkgs instead!
74 readOnlyBadBuildPlatform = evalMinimalConfig {
75 imports = [ ./read-only.nix ];
77 nixpkgs.buildPlatform = "foo-linux"; # do in pkgs instead!
80 throws = x: ! (builtins.tryEval x).success;
83 lib.recurseIntoAttrs {
86 nixpkgs.system = stdenv.hostPlatform.system;
87 })._module.args.pkgs.hello;
89 assert withHost._module.args.pkgs.stdenv.hostPlatform.system == "aarch64-linux";
90 assert withHost._module.args.pkgs.stdenv.buildPlatform.system == "aarch64-linux";
91 assert withHostAndBuild._module.args.pkgs.stdenv.hostPlatform.system == "aarch64-linux";
92 assert withHostAndBuild._module.args.pkgs.stdenv.buildPlatform.system == "aarch64-darwin";
93 assert withSameHostAndBuild.config.nixpkgs.buildPlatform == withSameHostAndBuild.config.nixpkgs.hostPlatform;
94 assert withSameHostAndBuild._module.args.pkgs.stdenv.buildPlatform == withSameHostAndBuild._module.args.pkgs.stdenv.hostPlatform;
95 assert builtins.trace (lib.head (getErrors ambiguous))
96 getErrors ambiguous ==
98 Your system configures nixpkgs with the platform parameters:
99 nixpkgs.hostPlatform, with values defined in:
102 nixpkgs.buildPlatform, with values defined in:
105 However, it also defines the legacy options:
106 nixpkgs.system, with values defined in:
108 nixpkgs.localSystem, with values defined in:
110 nixpkgs.crossSystem, with values defined in:
113 For a future proof system configuration, we recommend to remove
114 the legacy definitions.
116 assert builtins.trace (lib.head (getErrors externalPkgsWithConfig))
117 getErrors externalPkgsWithConfig ==
119 Your system configures nixpkgs with an externally created instance.
120 `nixpkgs.config` options should be passed when creating the instance instead.
128 - ext-pkgs-config.nix
131 nixpkgs.localSystem = pkgs.stdenv.hostPlatform;
132 nixpkgs.hostPlatform = pkgs.stdenv.hostPlatform;
137 # Tests for the read-only.nix module
138 assert readOnly._module.args.pkgs.stdenv.hostPlatform.system == pkgs.stdenv.hostPlatform.system;
139 assert throws readOnlyBad._module.args.pkgs.stdenv;
140 assert throws readOnlyUndefined._module.args.pkgs.stdenv;
141 assert throws readOnlyBadConfig._module.args.pkgs.stdenv;
142 assert throws readOnlyBadOverlays._module.args.pkgs.stdenv;
143 assert throws readOnlyBadHostPlatform._module.args.pkgs.stdenv;
144 assert throws readOnlyBadBuildPlatform._module.args.pkgs.stdenv;
145 # read-only.nix does not provide legacy options, for the sake of simplicity
146 # If you're bothered by this, upgrade your configs to use the new *Platform
148 assert !readOnly.options.nixpkgs?system;
149 assert !readOnly.options.nixpkgs?localSystem;
150 assert !readOnly.options.nixpkgs?crossSystem;