1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-12-04 16:11:06 +01:00

home-environment: extend release check to include pkgs

`lib` comes from the Nixpkgs used to instantiate Home Manager itself and
cannot change within the module fixpoint. However, `pkgs` is configurable
(via `nixpkgs.*` or `_module.args`) and may come from a different Nixpkgs
instance from the one providing `lib`.

Mismatches between Home Manager's release and the release of the `pkgs`
instance are more common and also more likely to cause subtle issues.

This change extends the release check to include `pkgs.lib.trivial.release`
so that such mismatches can be detected and reported.
This commit is contained in:
Matt Sturgeon 2025-12-02 04:33:03 +00:00 committed by Austin Horstman
parent c3d1e5c65a
commit ab8e4b2b5a
3 changed files with 56 additions and 5 deletions

View file

@ -570,14 +570,25 @@ in
warnings = warnings =
let let
hmRelease = config.home.version.release; hmRelease = config.home.version.release;
nixpkgsRelease = lib.trivial.release; libRelease = lib.trivial.release;
releaseMismatch = config.home.enableNixpkgsReleaseCheck && hmRelease != nixpkgsRelease; pkgsRelease = pkgs.lib.trivial.release;
releaseMismatch = hmRelease != libRelease || hmRelease != pkgsRelease;
versionsSummary =
if libRelease == pkgsRelease then
''
Home Manager version ${hmRelease} and
Nixpkgs version ${libRelease}.''
else
''
Home Manager version: ${hmRelease}
Nixpkgs version used to evaluate Home Manager: ${libRelease}
Nixpkgs version used for packages (`pkgs`): ${pkgsRelease}'';
in in
lib.optional releaseMismatch '' lib.optional (config.home.enableNixpkgsReleaseCheck && releaseMismatch) ''
You are using You are using
Home Manager version ${hmRelease} and ${lib.replaceString "\n" "\n " versionsSummary}
Nixpkgs version ${nixpkgsRelease}.
Using mismatched versions is likely to cause errors and unexpected Using mismatched versions is likely to cause errors and unexpected
behavior. It is therefore highly recommended to use a release of Home behavior. It is therefore highly recommended to use a release of Home

View file

@ -2,4 +2,5 @@
home-session-path = ./session-path.nix; home-session-path = ./session-path.nix;
home-session-search-variables = ./session-search-variables.nix; home-session-search-variables = ./session-search-variables.nix;
home-session-variables = ./session-variables.nix; home-session-variables = ./session-variables.nix;
home-nixpkgs-release-check-pkgs = ./nixpkgs-release-check-pkgs.nix;
} }

View file

@ -0,0 +1,39 @@
{ lib, ... }:
let
releaseInfo = lib.importJSON ../../../release.json;
hmRelease = releaseInfo.release;
pkgsRelease = "<invalid>";
in
{
test.asserts.warnings.expected = [
''
You are using
Home Manager version: ${hmRelease}
Nixpkgs version used to evaluate Home Manager: ${hmRelease}
Nixpkgs version used for packages (`pkgs`): ${pkgsRelease}
Using mismatched versions is likely to cause errors and unexpected
behavior. It is therefore highly recommended to use a release of Home
Manager that corresponds with your chosen release of Nixpkgs.
If you insist then you can disable this warning by adding
home.enableNixpkgsReleaseCheck = false;
to your configuration.
''
];
nixpkgs.overlays = [
(final: prev: {
lib = prev.lib.extend (
final: prev: {
trivial = prev.trivial // {
release = pkgsRelease;
};
}
);
})
];
}