at 18.03-beta 4.8 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 = traceValIfNot isConfig; 37 merge = args: fold (def: mergeConfig def.value) {}; 38 }; 39 40 overlayType = mkOptionType { 41 name = "nixpkgs-overlay"; 42 description = "nixpkgs overlay"; 43 check = lib.isFunction; 44 merge = lib.mergeOneOption; 45 }; 46 47 pkgsType = mkOptionType { 48 name = "nixpkgs"; 49 description = "An evaluation of Nixpkgs; the top level attribute set of packages"; 50 check = builtins.isAttrs; 51 }; 52 53in 54 55{ 56 options.nixpkgs = { 57 58 pkgs = mkOption { 59 defaultText = literalExample 60 ''import "''${nixos}/.." { 61 inherit (config.nixpkgs) config overlays system; 62 } 63 ''; 64 default = import ../../.. { inherit (cfg) config overlays system; }; 65 type = pkgsType; 66 example = literalExample ''import <nixpkgs> {}''; 67 description = '' 68 This is the evaluation of Nixpkgs that will be provided to 69 all NixOS modules. Defining this option has the effect of 70 ignoring the other options that would otherwise be used to 71 evaluate Nixpkgs, because those are arguments to the default 72 value. The default value imports the Nixpkgs source files 73 relative to the location of this NixOS module, because 74 NixOS and Nixpkgs are distributed together for consistency, 75 so the <code>nixos</code> in the default value is in fact a 76 relative path. The <code>config</code>, <code>overlays</code> 77 and <code>system</code> come from this option's siblings. 78 79 This option can be used by applications like NixOps to increase 80 the performance of evaluation, or to create packages that depend 81 on a container that should be built with the exact same evaluation 82 of Nixpkgs, for example. Applications like this should set 83 their default value using <code>lib.mkDefault</code>, so 84 user-provided configuration can override it without using 85 <code>lib</code>. 86 87 Note that using a distinct version of Nixpkgs with NixOS may 88 be an unexpected source of problems. Use this option with care. 89 ''; 90 }; 91 92 config = mkOption { 93 default = {}; 94 example = literalExample 95 '' 96 { allowBroken = true; allowUnfree = true; } 97 ''; 98 type = configType; 99 description = '' 100 The configuration of the Nix Packages collection. (For 101 details, see the Nixpkgs documentation.) It allows you to set 102 package configuration options. 103 104 Ignored when <code>nixpkgs.pkgs</code> is set. 105 ''; 106 }; 107 108 overlays = mkOption { 109 default = []; 110 example = literalExample 111 '' 112 [ (self: super: { 113 openssh = super.openssh.override { 114 hpnSupport = true; 115 kerberos = self.libkrb5; 116 }; 117 }; 118 ) ] 119 ''; 120 type = types.listOf overlayType; 121 description = '' 122 List of overlays to use with the Nix Packages collection. 123 (For details, see the Nixpkgs documentation.) It allows 124 you to override packages globally. This is a function that 125 takes as an argument the <emphasis>original</emphasis> Nixpkgs. 126 The first argument should be used for finding dependencies, and 127 the second should be used for overriding recipes. 128 129 Ignored when <code>nixpkgs.pkgs</code> is set. 130 ''; 131 }; 132 133 system = mkOption { 134 type = types.str; 135 example = "i686-linux"; 136 description = '' 137 Specifies the Nix platform type for which NixOS should be built. 138 If unset, it defaults to the platform type of your host system. 139 Specifying this option is useful when doing distributed 140 multi-platform deployment, or when building virtual machines. 141 142 Ignored when <code>nixpkgs.pkgs</code> is set. 143 ''; 144 }; 145 }; 146 147 config = { 148 _module.args = { 149 pkgs = cfg.pkgs; 150 pkgs_i686 = cfg.pkgs.pkgsi686Linux; 151 }; 152 }; 153}