Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixpkgs config: apply module system #16531

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkgs/modules/module-list.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
./overrides.nix
]
21 changes: 21 additions & 0 deletions pkgs/modules/overrides.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{ config, lib, pkgs, ... }:

with lib;

let
isConfig = x:
builtins.isAttrs x || builtins.isFunction x;
configType = mkOptionType {
name = "nixpkgs config";
check = traceValIfNot isConfig;
};
in

{
options = {
packageOverrides = mkOption {
type = configType;
description = "Package overrides";
};
};
}
20 changes: 7 additions & 13 deletions pkgs/top-level/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ let

lib = import ../../lib;

# The contents of the configuration file found at $NIXPKGS_CONFIG or
# $HOME/.nixpkgs/config.nix.
# for NIXOS (nixos-rebuild): use nixpkgs.config option
config =
let
inherit (builtins) getEnv pathExists;
Expand All @@ -46,19 +43,16 @@ let
homeDir = getEnv "HOME";
configFile2 = homeDir + "/.nixpkgs/config.nix";

configExpr =
rootModule =
if config_ != null then config_
else if configFile != "" && pathExists configFile then import configFile
else if homeDir != "" && pathExists configFile2 then import configFile2
else {};
else if configFile != "" && pathExists configFile then [ configFile ]
else if homeDir != "" && pathExists configFile2 then [ configFile2 ]
else [];

in
# allow both:
# { /* the config */ } and
# { pkgs, ... } : { /* the config */ }
if builtins.isFunction configExpr
then configExpr { inherit pkgs; }
else configExpr;
(lib.evalModules {
modules = rootModule ++ import ../modules/module-list.nix;
}).config;

# Allow setting the platform in the config file. Otherwise, let's use a reasonable default (pc)

Expand Down