Skip to content

Commit

Permalink
nixpkgs: always provide the option definitions
Browse files Browse the repository at this point in the history
This allows evaluation of configurations where nixpkgs.* options are
used even when in a flake setup with unchanged default values.
  • Loading branch information
Gerschtli committed Dec 10, 2021
1 parent 843252c commit 8511636
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
1 change: 1 addition & 0 deletions modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ let
{
_module.args.home-manager = home-manager;
_module.args.pkgs = mkDefault pkgs;
_module.args.isFlake = isFlake;
}
configModule
] ++ import ./module-list.nix { inherit pkgs isFlake; };
Expand Down
3 changes: 2 additions & 1 deletion modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
./environment/path.nix
./environment/session-init.nix
./home-manager.nix
./nixpkgs/options.nix
./time.nix
./user.nix
./version.nix
(pkgs.path + "/nixos/modules/misc/assertions.nix")
] ++ pkgs.lib.optionals (!isFlake) [ ./nixpkgs.nix ]
] ++ pkgs.lib.optionals (!isFlake) [ ./nixpkgs/config.nix ]
24 changes: 24 additions & 0 deletions modules/nixpkgs/config.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) 2019-2021, see AUTHORS. Licensed under MIT License, see LICENSE.

# Inspired by
# https://github.com/rycee/home-manager/blob/master/modules/misc/nixpkgs.nix
# (Copyright (c) 2017-2019 Robert Helgesson and Home Manager contributors,
# licensed under MIT License as well)

{ config, lib, pkgs, ... }:

with lib;

{
###### implementation

config = {

_module.args.pkgs = import <nixpkgs> (
filterAttrs (n: v: v != null) config.nixpkgs
);

nixpkgs.overlays = import ../../overlays;

};
}
19 changes: 9 additions & 10 deletions modules/nixpkgs.nix → modules/nixpkgs/options.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Copyright (c) 2019-2020, see AUTHORS. Licensed under MIT License, see LICENSE.
# Copyright (c) 2019-2021, see AUTHORS. Licensed under MIT License, see LICENSE.

# Inspired by
# https://github.com/rycee/home-manager/blob/master/modules/misc/nixpkgs.nix
# (Copyright (c) 2017-2019 Robert Helgesson and Home Manager contributors,
# licensed under MIT License as well)

{ config, lib, pkgs, ... }:
{ config, lib, pkgs, isFlake, ... }:

with lib;

Expand Down Expand Up @@ -53,11 +53,6 @@ let
check = builtins.isFunction;
merge = lib.mergeOneOption;
};

_pkgs = import <nixpkgs> (
filterAttrs (n: v: v != null) config.nixpkgs
);

in

{
Expand Down Expand Up @@ -164,9 +159,13 @@ in

config = {

_module.args.pkgs = _pkgs;

nixpkgs.overlays = import ../overlays;
assertions = [
{
assertion = isFlake -> (config.nixpkgs.config != null || (config.nixpkgs.overlays != null && config.nixpkgs.overlays != []));
message = "In a flake setup, the options nixpkgs.* should not be used. Instead, rely on the provided flake "
+ "outputs and pass in the necessary nixpkgs object.";
}
];

};
}

0 comments on commit 8511636

Please sign in to comment.