diff --git a/modules/default.nix b/modules/default.nix index 673363c..254f66d 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -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; }; diff --git a/modules/module-list.nix b/modules/module-list.nix index ef31d86..768ad0a 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -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 ] diff --git a/modules/nixpkgs/config.nix b/modules/nixpkgs/config.nix new file mode 100644 index 0000000..7941b5a --- /dev/null +++ b/modules/nixpkgs/config.nix @@ -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 ( + filterAttrs (n: v: v != null) config.nixpkgs + ); + + nixpkgs.overlays = import ../../overlays; + + }; +} diff --git a/modules/nixpkgs.nix b/modules/nixpkgs/options.nix similarity index 90% rename from modules/nixpkgs.nix rename to modules/nixpkgs/options.nix index 233ec63..f23ad6c 100644 --- a/modules/nixpkgs.nix +++ b/modules/nixpkgs/options.nix @@ -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; @@ -53,11 +53,6 @@ let check = builtins.isFunction; merge = lib.mergeOneOption; }; - - _pkgs = import ( - filterAttrs (n: v: v != null) config.nixpkgs - ); - in { @@ -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."; + } + ]; }; }