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": {
"locked": {
"lastModified": 1718530797,
"narHash": "sha256-pup6cYwtgvzDpvpSCFh1TEUjw2zkNpk8iolbKnyFmmU=",
"lastModified": 1722185531,
"narHash": "sha256-veKR07psFoJjINLC8RK4DiLniGGMgF3QMlS4tb74S6k=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "b60ebf54c15553b393d144357375ea956f89e9a9",
"rev": "52ec9ac3b12395ad677e8b62106f0b98c1f8569d",
"type": "github"
},
"original": {

View file

@ -36,11 +36,12 @@
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 = {
inherit (self.packages.${system}) default nix-eval-jobs;
} // lib.optionalAttrs (lib.elem system linux64BitSystems) {
# wrongMajor intentionally not included here since it is expected to fail
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
# usage.
# 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}";
# FIXME: do this more sensibly for future releases
# https://git.lix.systems/lix-project/lix/issues/406
@ -28,8 +28,13 @@ let
nix = final.nixVersions.nix_2_18_upstream;
});
inherit (prev) lib;
csi = builtins.fromJSON ''"\u001b"'';
orange = "${csi}[35;1m";
normal = "${csi}[0m";
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
pkgs.nixos and also including it in imports, or perhaps some unknown
machinations of a complicated flake library.
@ -42,9 +47,25 @@ let
delete that.
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;
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 // {
lix-overlay-present = 1;
# used for things that one wouldn't necessarily want to update, but we
@ -52,11 +73,10 @@ let
# want to do that.
lix-sources = import ./pins.nix;
lix = if lix != null then lixPkgFromSource else prev.lix;
lix = maybeWarnWrongMajor (maybeWarnDuplicate lixPackageToUse);
nixVersions = prev.nixVersions // rec {
# FIXME: do something less scuffed
nix_2_18 = maybeWarnDuplicate final.lix;
nix_2_18 = final.lix;
stable = 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
pkgs' = import pkgs.path {
inherit (pkgs) system;
};
configs = {
it-builds = nixos ({ ... }: {
imports = [ lix-module ];
@ -9,10 +12,21 @@ let
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
{
inherit configs;
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"
}