From e4a06f35b1d88ab98fa8b6962e7a3f802232d165 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Mon, 5 May 2014 15:52:33 -0400 Subject: [PATCH] nixos: Don't evaluate twice to get the value of config.nixpkgs --- lib/modules.nix | 4 +-- nixos/lib/eval-config.nix | 35 ++++++++++++--------------- nixos/modules/misc/nixpkgs.nix | 4 --- nixos/modules/system/boot/systemd.nix | 2 +- 4 files changed, 18 insertions(+), 27 deletions(-) diff --git a/lib/modules.nix b/lib/modules.nix index b514544c1e0..84ca209d367 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -12,10 +12,10 @@ rec { and ‘config’: the nested set of all option values. */ evalModules = { modules, prefix ? [], args ? {}, check ? true }: let - internalModule = { + internalModule = rec { _file = ./modules.nix; - key = ./modules.nix; + key = _file; options = { __internal.args = mkOption { diff --git a/nixos/lib/eval-config.nix b/nixos/lib/eval-config.nix index 08adcf3a007..460f5601ae7 100644 --- a/nixos/lib/eval-config.nix +++ b/nixos/lib/eval-config.nix @@ -9,18 +9,30 @@ , modules , check ? true , prefix ? [] +, lib ? import ../../lib }: let extraArgs_ = extraArgs; pkgs_ = pkgs; system_ = system; extraModules = let e = builtins.getEnv "NIXOS_EXTRA_MODULE_PATH"; in if e == "" then [] else [(import (builtins.toPath e))]; +in + +let + pkgsModule = rec { + _file = ./eval-config.nix; + key = _file; + config = { + nixpkgs.system = lib.mkDefault system_; + }; + }; + in rec { # Merge the option definitions in all modules, forming the full # system configuration. - inherit (pkgs.lib.evalModules { + inherit (lib.evalModules { inherit prefix; - modules = modules ++ extraModules ++ baseModules; + modules = modules ++ extraModules ++ baseModules ++ [ pkgsModule ]; args = extraArgs; check = check && options.environment.checkConfigurationOptions.value; }) config options; @@ -39,30 +51,13 @@ in rec { utils = import ./utils.nix pkgs; }; - # Import Nixpkgs, allowing the NixOS option nixpkgs.config to - # specify the Nixpkgs configuration (e.g., to set package options - # such as firefox.enableGeckoMediaPlayer, or to apply global - # overrides such as changing GCC throughout the system), and the - # option nixpkgs.system to override the platform type. This is - # tricky, because we have to prevent an infinite recursion: "pkgs" - # is passed as an argument to NixOS modules, but the value of "pkgs" - # depends on config.nixpkgs.config, which we get from the modules. - # So we call ourselves here with "pkgs" explicitly set to an - # instance that doesn't depend on nixpkgs.config. pkgs = if pkgs_ != null then pkgs_ else import ./nixpkgs.nix ( let system = if nixpkgsOptions.system != "" then nixpkgsOptions.system else system_; - nixpkgsOptions = (import ./eval-config.nix { - inherit system extraArgs modules prefix; - # For efficiency, leave out most NixOS modules; they don't - # define nixpkgs.config, so it's pointless to evaluate them. - baseModules = [ ../modules/misc/nixpkgs.nix ../modules/config/no-x-libs.nix ]; - pkgs = import ./nixpkgs.nix { system = system_; config = {}; }; - check = false; - }).config.nixpkgs; + nixpkgsOptions = config.nixpkgs; in { inherit system; diff --git a/nixos/modules/misc/nixpkgs.nix b/nixos/modules/misc/nixpkgs.nix index f41c8817ba4..cbb42c00003 100644 --- a/nixos/modules/misc/nixpkgs.nix +++ b/nixos/modules/misc/nixpkgs.nix @@ -69,8 +69,4 @@ in }; }; - - config = { - nixpkgs.system = mkDefault pkgs.stdenv.system; - }; } diff --git a/nixos/modules/system/boot/systemd.nix b/nixos/modules/system/boot/systemd.nix index f853a8f6775..f3ffda02367 100644 --- a/nixos/modules/system/boot/systemd.nix +++ b/nixos/modules/system/boot/systemd.nix @@ -1,7 +1,7 @@ { config, lib, pkgs, utils, ... }: -with lib; with utils; +with lib; with import ./systemd-unit-options.nix { inherit config lib; }; let