From b3457b78ac65e9c4b2702b9b37f01c8355a82cb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabi=C3=A1n=20Heredia=20Montiel?= Date: Wed, 25 Sep 2024 19:46:13 -0600 Subject: [PATCH 1/2] overlay: make finalNix depend on the nix version being used by a package This should address both of the following (were 35 is more general and 36 a specific case) - https://git.lix.systems/lix-project/nixos-module/issues/35 - https://git.lix.systems/lix-project/nixos-module/issues/36 --- overlay.nix | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/overlay.nix b/overlay.nix index cbc9515..658295a 100644 --- a/overlay.nix +++ b/overlay.nix @@ -60,11 +60,25 @@ let # 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 = + overlay = lib.genAttrs overridelist_upstream ( - name: if (lib.functionArgs prev.${name}.override ? "nix") then prev.${name}.override { - nix = final.nixVersions.stable_upstream; - } else prev.${name} + name: + if (lib.functionArgs prev.${name}.override ? "nix") then + let + # Get the two common inputs of a derivation/package. + inputs = prev.${name}.buildInputs ++ prev.${name}.nativeBuildInputs; + nixDependency = lib.findFirst + (drv: (drv.pname or "") == "nix") + prev.nixVersions.stable_upstream # default to stable nix if nix is not an input + inputs; + nixMajor = lib.versions.major nixDependency.version; + nixMinor = lib.versions.minor nixDependency.version; + nixAttr = "nix_${nixMajor}_${nixMinor}"; + finalNix = final.nixVersions.${nixAttr}; + in + prev.${name}.override { + nix = finalNix; + } else prev.${name} ) // { lix-overlay-present = 1; # used for things that one wouldn't necessarily want to update, but we From bb51b2d1618e57ef2cd90fb780b9eba1e30802d6 Mon Sep 17 00:00:00 2001 From: Jade Lovelace Date: Mon, 30 Sep 2024 13:34:26 -0700 Subject: [PATCH 2/2] jade revision pass --- overlay.nix | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/overlay.nix b/overlay.nix index 658295a..fe34019 100644 --- a/overlay.nix +++ b/overlay.nix @@ -1,16 +1,13 @@ { lix, versionSuffix ? "" }: final: prev: let - # This is kind of scary to not override the nix version to pretend to be - # 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 lixPackageFromSource = final.callPackage (lix + "/package.nix") ({ inherit versionSuffix; stdenv = final.clangStdenv; }); - # These packages depend on Nix features that Lix does not support + # These packages should receive CppNix since they may link to it or otherwise + # cause problems (or even just silly mass-rebuilds) if we give them Lix overridelist_upstream = [ "attic-client" "devenv" @@ -60,7 +57,15 @@ let # 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 = + # It is not enough to *just* throw whatever the default nix version is at + # anything in the "don't give lix" list, we have to *also* ensure that we + # give whatever upstream version as specified in the callPackage invocation. + # + # Unfortunately I don't think there is any actual way to directly query that, + # so we instead do something extremely evil and guess which version it + # probably was. This code is not generalizable to arbitrary derivations, so + # it will hopefully not make us cry, at least. + useCppNixOverlay = lib.genAttrs overridelist_upstream ( name: if (lib.functionArgs prev.${name}.override ? "nix") then @@ -71,15 +76,18 @@ let (drv: (drv.pname or "") == "nix") prev.nixVersions.stable_upstream # default to stable nix if nix is not an input inputs; - nixMajor = lib.versions.major nixDependency.version; - nixMinor = lib.versions.minor nixDependency.version; + nixMajor = lib.versions.major (nixDependency.version or ""); + nixMinor = lib.versions.minor (nixDependency.version or ""); nixAttr = "nix_${nixMajor}_${nixMinor}"; finalNix = final.nixVersions.${nixAttr}; in prev.${name}.override { nix = finalNix; - } else prev.${name} - ) // { + } + else prev.${name} + ); + + overlay = useCppNixOverlay // { lix-overlay-present = 1; # used for things that one wouldn't necessarily want to update, but we # nevertheless shove it in the overlay and fixed-point it in case one *does*