From de3c8546154d27a5739dba81de835010cf9835a1 Mon Sep 17 00:00:00 2001 From: Jade Lovelace Date: Tue, 30 Jul 2024 14:38:08 -0700 Subject: [PATCH] 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. --- flake.lock | 6 +++--- flake.nix | 3 ++- overlay.nix | 30 +++++++++++++++++++++++++----- test-nixos.nix | 16 +++++++++++++++- version.json | 3 +++ 5 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 version.json diff --git a/flake.lock b/flake.lock index 12aa181..3b15c48 100644 --- a/flake.lock +++ b/flake.lock @@ -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": { diff --git a/flake.nix b/flake.nix index 6a83ec1..b7b412a 100644 --- a/flake.nix +++ b/flake.nix @@ -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; }; }); diff --git a/overlay.nix b/overlay.nix index cc1a04b..caa3a65 100644 --- a/overlay.nix +++ b/overlay.nix @@ -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; }; diff --git a/test-nixos.nix b/test-nixos.nix index 376eaf0..b6fef10 100644 --- a/test-nixos.nix +++ b/test-nixos.nix @@ -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; } diff --git a/version.json b/version.json new file mode 100644 index 0000000..808e1b1 --- /dev/null +++ b/version.json @@ -0,0 +1,3 @@ +{ + "version": "2.91.0-dev" +}