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";
20 _file = "ambiguous.nix";
21 nixpkgs.hostPlatform = "aarch64-linux";
22 nixpkgs.buildPlatform = "aarch64-darwin";
23 nixpkgs.system = "x86_64-linux";
24 nixpkgs.localSystem.system = "x86_64-darwin";
25 nixpkgs.crossSystem.system = "i686-linux";
27 { _file = "repeat.nix";
28 nixpkgs.hostPlatform = "aarch64-linux";
34 uncheckedEval = lib.evalModules { modules = [ ../nixpkgs.nix module ]; };
35 in map (ass: ass.message) (lib.filter (ass: !ass.assertion) uncheckedEval.config.assertions);
37 readOnlyUndefined = evalMinimalConfig {
38 imports = [ ./read-only.nix ];
41 readOnlyBad = evalMinimalConfig {
42 imports = [ ./read-only.nix ];
46 readOnly = evalMinimalConfig {
47 imports = [ ./read-only.nix ];
51 readOnlyBadConfig = evalMinimalConfig {
52 imports = [ ./read-only.nix ];
54 nixpkgs.config.allowUnfree = true; # do in pkgs instead!
57 readOnlyBadOverlays = evalMinimalConfig {
58 imports = [ ./read-only.nix ];
60 nixpkgs.overlays = [ (_: _: {}) ]; # do in pkgs instead!
63 readOnlyBadHostPlatform = evalMinimalConfig {
64 imports = [ ./read-only.nix ];
66 nixpkgs.hostPlatform = "foo-linux"; # do in pkgs instead!
69 readOnlyBadBuildPlatform = evalMinimalConfig {
70 imports = [ ./read-only.nix ];
72 nixpkgs.buildPlatform = "foo-linux"; # do in pkgs instead!
75 throws = x: ! (builtins.tryEval x).success;
78 lib.recurseIntoAttrs {
81 nixpkgs.system = stdenv.hostPlatform.system;
82 })._module.args.pkgs.hello;
84 assert withHost._module.args.pkgs.stdenv.hostPlatform.system == "aarch64-linux";
85 assert withHost._module.args.pkgs.stdenv.buildPlatform.system == "aarch64-linux";
86 assert withHostAndBuild._module.args.pkgs.stdenv.hostPlatform.system == "aarch64-linux";
87 assert withHostAndBuild._module.args.pkgs.stdenv.buildPlatform.system == "aarch64-darwin";
88 assert withSameHostAndBuild.config.nixpkgs.buildPlatform == withSameHostAndBuild.config.nixpkgs.hostPlatform;
89 assert withSameHostAndBuild._module.args.pkgs.stdenv.buildPlatform == withSameHostAndBuild._module.args.pkgs.stdenv.hostPlatform;
90 assert builtins.trace (lib.head (getErrors ambiguous))
91 getErrors ambiguous ==
93 Your system configures nixpkgs with the platform parameters:
94 nixpkgs.hostPlatform, with values defined in:
97 nixpkgs.buildPlatform, with values defined in:
100 However, it also defines the legacy options:
101 nixpkgs.system, with values defined in:
103 nixpkgs.localSystem, with values defined in:
105 nixpkgs.crossSystem, with values defined in:
108 For a future proof system configuration, we recommend to remove
109 the legacy definitions.
112 nixpkgs.localSystem = pkgs.stdenv.hostPlatform;
113 nixpkgs.hostPlatform = pkgs.stdenv.hostPlatform;
118 # Tests for the read-only.nix module
119 assert readOnly._module.args.pkgs.stdenv.hostPlatform.system == pkgs.stdenv.hostPlatform.system;
120 assert throws readOnlyBad._module.args.pkgs.stdenv;
121 assert throws readOnlyUndefined._module.args.pkgs.stdenv;
122 assert throws readOnlyBadConfig._module.args.pkgs.stdenv;
123 assert throws readOnlyBadOverlays._module.args.pkgs.stdenv;
124 assert throws readOnlyBadHostPlatform._module.args.pkgs.stdenv;
125 assert throws readOnlyBadBuildPlatform._module.args.pkgs.stdenv;
126 # read-only.nix does not provide legacy options, for the sake of simplicity
127 # If you're bothered by this, upgrade your configs to use the new *Platform
129 assert !readOnly.options.nixpkgs?system;
130 assert !readOnly.options.nixpkgs?localSystem;
131 assert !readOnly.options.nixpkgs?crossSystem;