Warn on mismatched Lix module version

Especially with nixpkgs being an extremely uncontrolled variable, we
cannot guarantee that the module is always the right version. This will
cause support burden, so let's automatically diagnose it.
This commit is contained in:
jade 2024-07-30 14:38:08 -07:00
parent 03d62d5a74
commit de3c854615
5 changed files with 48 additions and 10 deletions

View file

@ -49,11 +49,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1718530797, "lastModified": 1722185531,
"narHash": "sha256-pup6cYwtgvzDpvpSCFh1TEUjw2zkNpk8iolbKnyFmmU=", "narHash": "sha256-veKR07psFoJjINLC8RK4DiLniGGMgF3QMlS4tb74S6k=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "b60ebf54c15553b393d144357375ea956f89e9a9", "rev": "52ec9ac3b12395ad677e8b62106f0b98c1f8569d",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -36,11 +36,12 @@
packages.system-profile = import ./system-profile.nix { inherit pkgs flakey-profile; }; packages.system-profile = import ./system-profile.nix { inherit pkgs flakey-profile; };
nixosTests = pkgs.recurseIntoAttrs (pkgs.callPackage ./test-nixos.nix { lix-module = self.nixosModules.default; }); nixosTests = pkgs.recurseIntoAttrs (pkgs.callPackage ./test-nixos.nix { inherit pkgs; lix-module = self.nixosModules.default; });
checks = { checks = {
inherit (self.packages.${system}) default nix-eval-jobs; inherit (self.packages.${system}) default nix-eval-jobs;
} // lib.optionalAttrs (lib.elem system linux64BitSystems) { } // lib.optionalAttrs (lib.elem system linux64BitSystems) {
# wrongMajor intentionally not included here since it is expected to fail
inherit (self.nixosTests.${system}) it-builds; inherit (self.nixosTests.${system}) it-builds;
}; };
}); });

View file

@ -5,7 +5,7 @@ let
# 2.18 since nixpkgs can introduce new breakage in its Nix unstable CLI # 2.18 since nixpkgs can introduce new breakage in its Nix unstable CLI
# usage. # usage.
# https://github.com/nixos/nixpkgs/blob/6afb255d976f85f3359e4929abd6f5149c323a02/nixos/modules/config/nix.nix#L121 # https://github.com/nixos/nixpkgs/blob/6afb255d976f85f3359e4929abd6f5149c323a02/nixos/modules/config/nix.nix#L121
lixPkgFromSource = final.callPackage (lix + "/package.nix") ({ lixPackageFromSource = final.callPackage (lix + "/package.nix") ({
versionSuffix = "-${versionSuffix}"; versionSuffix = "-${versionSuffix}";
# FIXME: do this more sensibly for future releases # FIXME: do this more sensibly for future releases
# https://git.lix.systems/lix-project/lix/issues/406 # https://git.lix.systems/lix-project/lix/issues/406
@ -28,8 +28,13 @@ let
nix = final.nixVersions.nix_2_18_upstream; nix = final.nixVersions.nix_2_18_upstream;
}); });
inherit (prev) lib;
csi = builtins.fromJSON ''"\u001b"'';
orange = "${csi}[35;1m";
normal = "${csi}[0m";
warning = '' warning = ''
warning: You have the lix overlay included into a nixpkgs import twice, ${orange}warning${normal}: You have the lix overlay included into a nixpkgs import twice,
perhaps due to the NixOS module being included twice, or because of using perhaps due to the NixOS module being included twice, or because of using
pkgs.nixos and also including it in imports, or perhaps some unknown pkgs.nixos and also including it in imports, or perhaps some unknown
machinations of a complicated flake library. machinations of a complicated flake library.
@ -42,9 +47,25 @@ let
delete that. delete that.
P.P.S. This Lix has super catgirl powers. P.P.S. This Lix has super catgirl powers.
''; '';
wrongMajorWarning = ''
${orange}warning${normal}: This Lix NixOS module is being built against a Lix with a
major version (got ${lixPackageToUse.version}) other than the one the
module was designed for (expecting ${supportedLixMajor}). Some downstream
packages like nix-eval-jobs may be broken by this. Consider using a
matching version of the Lix NixOS module to the version of Lix you are
using.
'';
maybeWarnDuplicate = x: if final.lix-overlay-present > 1 then builtins.trace warning x else x; maybeWarnDuplicate = x: if final.lix-overlay-present > 1 then builtins.trace warning x else x;
versionJson = builtins.fromJSON (builtins.readFile ./version.json);
supportedLixMajor = builtins.elemAt (builtins.match ''^([[:digit:]]+\.[[:digit:]]+)\..*'' versionJson.version) 0;
lixPackageToUse = if lix != null then lixPackageFromSource else prev.lix;
# Especially if using Lix from nixpkgs, it is plausible that the overlay
# could be used against the wrong Lix major version and cause confusing build
# errors. This is a simple safeguard to put in at least something that might be seen.
maybeWarnWrongMajor = x: if !(lib.hasPrefix supportedLixMajor lixPackageToUse.version) then builtins.trace wrongMajorWarning x else x;
overlay = override_2_18 // { overlay = override_2_18 // {
lix-overlay-present = 1; lix-overlay-present = 1;
# used for things that one wouldn't necessarily want to update, but we # used for things that one wouldn't necessarily want to update, but we
@ -52,11 +73,10 @@ let
# want to do that. # want to do that.
lix-sources = import ./pins.nix; lix-sources = import ./pins.nix;
lix = if lix != null then lixPkgFromSource else prev.lix; lix = maybeWarnWrongMajor (maybeWarnDuplicate lixPackageToUse);
nixVersions = prev.nixVersions // rec { nixVersions = prev.nixVersions // rec {
# FIXME: do something less scuffed nix_2_18 = final.lix;
nix_2_18 = maybeWarnDuplicate final.lix;
stable = nix_2_18; stable = nix_2_18;
nix_2_18_upstream = prev.nixVersions.nix_2_18; nix_2_18_upstream = prev.nixVersions.nix_2_18;
}; };

View file

@ -1,5 +1,8 @@
{ nixos, lix-module }: { pkgs, nixos, lix-module }:
let let
pkgs' = import pkgs.path {
inherit (pkgs) system;
};
configs = { configs = {
it-builds = nixos ({ ... }: { it-builds = nixos ({ ... }: {
imports = [ lix-module ]; imports = [ lix-module ];
@ -9,10 +12,21 @@ let
system.stateVersion = "24.05"; system.stateVersion = "24.05";
}); });
# Intentionally provoke the wrong major version.
# Does assume that the module is one major ahead of the release; the main
# purpose here is a manual testing fixture.
wrongMajor = pkgs'.nixos ({ ... }: {
imports = [ (import ./module.nix { lix = null; }) ];
documentation.enable = false;
fileSystems."/".device = "ignore-root-device";
boot.loader.grub.enable = false;
system.stateVersion = "24.05";
});
}; };
in in
{ {
inherit configs; inherit configs;
it-builds = configs.it-builds.config.system.build.toplevel; it-builds = configs.it-builds.config.system.build.toplevel;
wrongMajor = configs.wrongMajor.config.system.build.toplevel;
} }

3
version.json Normal file
View file

@ -0,0 +1,3 @@
{
"version": "2.91.0-dev"
}