at 18.09-beta 7.1 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.nixpkgs; 7 8 isConfig = x: 9 builtins.isAttrs x || lib.isFunction x; 10 11 optCall = f: x: 12 if lib.isFunction f 13 then f x 14 else f; 15 16 mergeConfig = lhs_: rhs_: 17 let 18 lhs = optCall lhs_ { inherit pkgs; }; 19 rhs = optCall rhs_ { inherit pkgs; }; 20 in 21 lhs // rhs // 22 optionalAttrs (lhs ? packageOverrides) { 23 packageOverrides = pkgs: 24 optCall lhs.packageOverrides pkgs // 25 optCall (attrByPath ["packageOverrides"] ({}) rhs) pkgs; 26 } // 27 optionalAttrs (lhs ? perlPackageOverrides) { 28 perlPackageOverrides = pkgs: 29 optCall lhs.perlPackageOverrides pkgs // 30 optCall (attrByPath ["perlPackageOverrides"] ({}) rhs) pkgs; 31 }; 32 33 configType = mkOptionType { 34 name = "nixpkgs-config"; 35 description = "nixpkgs config"; 36 check = x: 37 let traceXIfNot = c: 38 if c x then true 39 else lib.traceSeqN 1 x false; 40 in traceXIfNot isConfig; 41 merge = args: fold (def: mergeConfig def.value) {}; 42 }; 43 44 overlayType = mkOptionType { 45 name = "nixpkgs-overlay"; 46 description = "nixpkgs overlay"; 47 check = lib.isFunction; 48 merge = lib.mergeOneOption; 49 }; 50 51 pkgsType = mkOptionType { 52 name = "nixpkgs"; 53 description = "An evaluation of Nixpkgs; the top level attribute set of packages"; 54 check = builtins.isAttrs; 55 }; 56 57in 58 59{ 60 options.nixpkgs = { 61 62 pkgs = mkOption { 63 defaultText = literalExample 64 ''import "''${nixos}/.." { 65 inherit (config.nixpkgs) config overlays localSystem crossSystem; 66 } 67 ''; 68 default = import ../../.. { 69 localSystem = { inherit (cfg) system; } // cfg.localSystem; 70 inherit (cfg) config overlays crossSystem; 71 }; 72 type = pkgsType; 73 example = literalExample ''import <nixpkgs> {}''; 74 description = '' 75 This is the evaluation of Nixpkgs that will be provided to 76 all NixOS modules. Defining this option has the effect of 77 ignoring the other options that would otherwise be used to 78 evaluate Nixpkgs, because those are arguments to the default 79 value. The default value imports the Nixpkgs source files 80 relative to the location of this NixOS module, because 81 NixOS and Nixpkgs are distributed together for consistency, 82 so the <code>nixos</code> in the default value is in fact a 83 relative path. The <code>config</code>, <code>overlays</code>, 84 <code>localSystem</code>, and <code>crossSystem</code> come 85 from this option's siblings. 86 87 This option can be used by applications like NixOps to increase 88 the performance of evaluation, or to create packages that depend 89 on a container that should be built with the exact same evaluation 90 of Nixpkgs, for example. Applications like this should set 91 their default value using <code>lib.mkDefault</code>, so 92 user-provided configuration can override it without using 93 <code>lib</code>. 94 95 Note that using a distinct version of Nixpkgs with NixOS may 96 be an unexpected source of problems. Use this option with care. 97 ''; 98 }; 99 100 config = mkOption { 101 default = {}; 102 example = literalExample 103 '' 104 { allowBroken = true; allowUnfree = true; } 105 ''; 106 type = configType; 107 description = '' 108 The configuration of the Nix Packages collection. (For 109 details, see the Nixpkgs documentation.) It allows you to set 110 package configuration options. 111 112 Ignored when <code>nixpkgs.pkgs</code> is set. 113 ''; 114 }; 115 116 overlays = mkOption { 117 default = []; 118 example = literalExample 119 '' 120 [ (self: super: { 121 openssh = super.openssh.override { 122 hpnSupport = true; 123 kerberos = self.libkrb5; 124 }; 125 }; 126 ) ] 127 ''; 128 type = types.listOf overlayType; 129 description = '' 130 List of overlays to use with the Nix Packages collection. 131 (For details, see the Nixpkgs documentation.) It allows 132 you to override packages globally. This is a function that 133 takes as an argument the <emphasis>original</emphasis> Nixpkgs. 134 The first argument should be used for finding dependencies, and 135 the second should be used for overriding recipes. 136 137 Ignored when <code>nixpkgs.pkgs</code> is set. 138 ''; 139 }; 140 141 localSystem = mkOption { 142 type = types.attrs; # TODO utilize lib.systems.parsedPlatform 143 default = { system = builtins.currentSystem; }; 144 example = { system = "aarch64-linux"; config = "aarch64-unknown-linux-gnu"; }; 145 defaultText = literalExample 146 ''(import "''${nixos}/../lib").lib.systems.examples.aarch64-multiplatform''; 147 description = '' 148 Specifies the platform on which NixOS should be built. When 149 <code>nixpkgs.crossSystem</code> is unset, it also specifies 150 the platform <emphasis>for</emphasis> which NixOS should be 151 built. If this option is unset, it defaults to the platform 152 type of the machine where evaluation happens. Specifying this 153 option is useful when doing distributed multi-platform 154 deployment, or when building virtual machines. See its 155 description in the Nixpkgs manual for more details. 156 157 Ignored when <code>nixpkgs.pkgs</code> is set. 158 ''; 159 }; 160 161 crossSystem = mkOption { 162 type = types.nullOr types.attrs; # TODO utilize lib.systems.parsedPlatform 163 default = null; 164 example = { system = "aarch64-linux"; config = "aarch64-unknown-linux-gnu"; }; 165 defaultText = literalExample 166 ''(import "''${nixos}/../lib").lib.systems.examples.aarch64-multiplatform''; 167 description = '' 168 Specifies the platform for which NixOS should be 169 built. Specify this only if it is different from 170 <code>nixpkgs.localSystem</code>, the platform 171 <emphasis>on</emphasis> which NixOS should be built. In other 172 words, specify this to cross-compile NixOS. Otherwise it 173 should be set as null, the default. See its description in the 174 Nixpkgs manual for more details. 175 176 Ignored when <code>nixpkgs.pkgs</code> is set. 177 ''; 178 }; 179 180 system = mkOption { 181 type = types.str; 182 example = "i686-linux"; 183 description = '' 184 Specifies the Nix platform type on which NixOS should be built. 185 It is better to specify <code>nixpkgs.localSystem</code> instead. 186 <programlisting> 187 { 188 nixpkgs.system = ..; 189 } 190 </programlisting> 191 is the same as 192 <programlisting> 193 { 194 nixpkgs.localSystem.system = ..; 195 } 196 </programlisting> 197 See <code>nixpkgs.localSystem</code> for more information. 198 199 Ignored when <code>nixpkgs.pkgs</code> is set. 200 ''; 201 }; 202 }; 203 204 config = { 205 _module.args = { 206 pkgs = cfg.pkgs; 207 pkgs_i686 = cfg.pkgs.pkgsi686Linux; 208 }; 209 }; 210}