nixpkgs-disabled: add module
This commit introduces the `nixpkgs-disabled` module, that is basically a mock of `nixpkgs` module where any value different from `null` will cause an assertion error. This is to help debugging cases where `home-manager.useGlobalPkgs` is set to `true` and `nixpkgs.*` options are being used. Nowadays this returns the following error: ``` error: The option `home-manager.users.<user>.nixpkgs` does not exist. ``` This will change too: ``` error: `nixpkgs` options are disabled when `home-manager.useGlobalPkgs` is enabled. ``` That will direct the user to the correct solution (either removing `nixpkgs` or disable `home-manager.useGlobalPkgs`).
This commit is contained in:
parent
b88c863b40
commit
223a4a17a4
2
.github/CODEOWNERS
vendored
2
.github/CODEOWNERS
vendored
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
/modules/misc/news.nix @rycee
|
/modules/misc/news.nix @rycee
|
||||||
|
|
||||||
|
/modules/misc/nixpkgs-disabled.nix @thiagokokada
|
||||||
|
|
||||||
/modules/misc/numlock.nix @evanjs
|
/modules/misc/numlock.nix @evanjs
|
||||||
/tests/modules/misc/numlock @evanjs
|
/tests/modules/misc/numlock @evanjs
|
||||||
|
|
||||||
|
|
73
modules/misc/nixpkgs-disabled.nix
Normal file
73
modules/misc/nixpkgs-disabled.nix
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
let
|
||||||
|
|
||||||
|
cfg = config.nixpkgs;
|
||||||
|
|
||||||
|
# Copied from nixpkgs.nix.
|
||||||
|
isConfig = x: builtins.isAttrs x || builtins.isFunction x;
|
||||||
|
|
||||||
|
# Copied from nixpkgs.nix.
|
||||||
|
optCall = f: x: if builtins.isFunction f then f x else f;
|
||||||
|
|
||||||
|
# Copied from nixpkgs.nix.
|
||||||
|
mergeConfig = lhs_: rhs_:
|
||||||
|
let
|
||||||
|
lhs = optCall lhs_ { inherit pkgs; };
|
||||||
|
rhs = optCall rhs_ { inherit pkgs; };
|
||||||
|
in lhs // rhs // optionalAttrs (lhs ? packageOverrides) {
|
||||||
|
packageOverrides = pkgs:
|
||||||
|
optCall lhs.packageOverrides pkgs
|
||||||
|
// optCall (attrByPath [ "packageOverrides" ] ({ }) rhs) pkgs;
|
||||||
|
} // optionalAttrs (lhs ? perlPackageOverrides) {
|
||||||
|
perlPackageOverrides = pkgs:
|
||||||
|
optCall lhs.perlPackageOverrides pkgs
|
||||||
|
// optCall (attrByPath [ "perlPackageOverrides" ] ({ }) rhs) pkgs;
|
||||||
|
};
|
||||||
|
|
||||||
|
# Copied from nixpkgs.nix.
|
||||||
|
configType = mkOptionType {
|
||||||
|
name = "nixpkgs-config";
|
||||||
|
description = "nixpkgs config";
|
||||||
|
check = x:
|
||||||
|
let traceXIfNot = c: if c x then true else lib.traceSeqN 1 x false;
|
||||||
|
in traceXIfNot isConfig;
|
||||||
|
merge = args: fold (def: mergeConfig def.value) { };
|
||||||
|
};
|
||||||
|
|
||||||
|
# Copied from nixpkgs.nix.
|
||||||
|
overlayType = mkOptionType {
|
||||||
|
name = "nixpkgs-overlay";
|
||||||
|
description = "nixpkgs overlay";
|
||||||
|
check = builtins.isFunction;
|
||||||
|
merge = lib.mergeOneOption;
|
||||||
|
};
|
||||||
|
|
||||||
|
in {
|
||||||
|
meta.maintainers = with maintainers; [ thiagokokada ];
|
||||||
|
|
||||||
|
options.nixpkgs = {
|
||||||
|
config = mkOption {
|
||||||
|
default = null;
|
||||||
|
type = types.nullOr configType;
|
||||||
|
visible = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
overlays = mkOption {
|
||||||
|
default = null;
|
||||||
|
type = types.nullOr (types.listOf overlayType);
|
||||||
|
visible = false;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
assertions = [{
|
||||||
|
assertion = cfg.config == null || cfg.overlays == null;
|
||||||
|
message = ''
|
||||||
|
`nixpkgs` options are disabled when `home-manager.useGlobalPkgs` is enabled.
|
||||||
|
'';
|
||||||
|
}];
|
||||||
|
};
|
||||||
|
}
|
|
@ -242,7 +242,8 @@ let
|
||||||
./xsession.nix
|
./xsession.nix
|
||||||
(pkgs.path + "/nixos/modules/misc/assertions.nix")
|
(pkgs.path + "/nixos/modules/misc/assertions.nix")
|
||||||
(pkgs.path + "/nixos/modules/misc/meta.nix")
|
(pkgs.path + "/nixos/modules/misc/meta.nix")
|
||||||
] ++ optional useNixpkgsModule ./misc/nixpkgs.nix;
|
] ++ optional useNixpkgsModule ./misc/nixpkgs.nix
|
||||||
|
++ optional (!useNixpkgsModule) ./misc/nixpkgs-disabled.nix;
|
||||||
|
|
||||||
pkgsModule = { config, ... }: {
|
pkgsModule = { config, ... }: {
|
||||||
config = {
|
config = {
|
||||||
|
|
Loading…
Reference in a new issue