1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-26 21:19:45 +01:00

home-environment: add Nixpkgs release version check

This adds a warning when a release version mismatch is detected
between Home Manager and Nixpkgs.
This commit is contained in:
Robert Helgesson 2021-07-03 00:36:30 +02:00
parent 7df6656b11
commit ac319fd314
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
2 changed files with 41 additions and 0 deletions

1
.release Normal file
View file

@ -0,0 +1 @@
21.11

View file

@ -390,6 +390,21 @@ in
Extra commands to run in the Home Manager profile builder.
'';
};
home.enableNixpkgsReleaseCheck = mkOption {
type = types.bool;
default = true;
description = ''
Determines whether to check for release version mismatch between Home
Manager and Nixpkgs. Using mismatched versions is likely to cause errors
and unexpected behavior. It is therefore highly recommended to use a
release of Home Manager than corresponds with your chosen release of
Nixpkgs.
</para><para>
When this option is enabled and a mismatch is detected then a warning
will be printed when the user configuration is being built.
'';
};
};
config = {
@ -404,6 +419,31 @@ in
}
];
warnings =
let
hmRelease = fileContents ../.release;
nixpkgsRelease = pkgs.lib.trivial.release;
releaseMismatch =
config.home.enableNixpkgsReleaseCheck
&& hmRelease != nixpkgsRelease;
in
optional releaseMismatch ''
You are using
Home Manager version ${hmRelease} and
Nixpkgs version ${nixpkgsRelease}.
Using mismatched versions is likely to cause errors and unexpected
behavior. It is therefore highly recommended to use a release of Home
Manager than corresponds with your chosen release of Nixpkgs.
If you insist then you can disable this warning by adding
home.enableNixpkgsReleaseCheck = false;
to your configuration.
'';
home.username =
mkIf (versionOlder config.home.stateVersion "20.09")
(mkDefault (builtins.getEnv "USER"));