# Nixpkgs commit that mysteriously broke my cmake environment

**URL:** https://discourse.nixos.org/t/nixpkgs-commit-that-mysteriously-broke-my-cmake-environment/52152
**Category:** Help
**Created:** [September 15, 2024, 6:45am UTC](https://discourse.nixos.org/t/nixpkgs-commit-that-mysteriously-broke-my-cmake-environment/52152 "2024-09-15T06:45:23Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Peal](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/p/6de8d8/32.png) [@Peal](https://discourse.nixos.org/u/Peal)
#### Post date: [September 15, 2024, 6:45am UTC](https://discourse.nixos.org/t/nixpkgs-commit-that-mysteriously-broke-my-cmake-environment/52152/1 "2024-09-15T06:45:23Z")

</div>

I have a custom build package that works until recently. [Link to the said custom pkg](https://github.com/Kahlenden/nixos-dotfiles/blob/ccd65fcfdf0ec115e96cae2b51b0fabdce703e94/nixos/packages/caesium/default.nix)

I checked and it was built just fine in [3212a37](https://github.com/NixOS/nixpkgs/commit/3212a3719697ca78734510103c8aa10bb12584e3), and I have been pining nixpkgs to that rev since forever. I tried switching to the commit right after it, which is [cc8e3c2](https://github.com/NixOS/nixpkgs/commit/cc8e3c2dca7223414bcc553d48e07f18dadb5d56) and it would not build.

What strange is that the [commit cc8e3c2](https://github.com/NixOS/nixpkgs/commit/cc8e3c2dca7223414bcc553d48e07f18dadb5d56) doesn’t seem to have anything to do with cmake

Apparently CMAKE\_PREFIX\_PATH was not set in build command, this is the build log:

```auto
Running phase: qtPreHook
@nix { "action": "setPhase", "phase": "qtPreHook" }
Running phase: unpackPhase
@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking source archive /nix/store/jwkkw9cvbvxf98ikhphgjgb551nlfpq6-source
source root is source
Running phase: patchPhase
@nix { "action": "setPhase", "phase": "patchPhase" }
Running phase: updateAutotoolsGnuConfigScriptsPhase
@nix { "action": "setPhase", "phase": "updateAutotoolsGnuConfigScriptsPhase" }
Running phase: configurePhase
@nix { "action": "setPhase", "phase": "configurePhase" }
fixing cmake files...
cmake flags: -DCMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY=OFF 
-DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF 
-DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON 
-DCMAKE_BUILD_TYPE=Release 
-DBUILD_TESTING=OFF 
-DCMAKE_INSTALL_LOCALEDIR=/nix/store/g6sxybp240fa72387faqjjn46xsxsjhn-caesium-image-compressor-2.7.1/share/locale 
-DCMAKE_INSTALL_LIBEXECDIR=/nix/store/g6sxybp240fa72387faqjjn46xsxsjhn-caesium-image-compressor-2.7.1/libexec 
-DCMAKE_INSTALL_LIBDIR=/nix/store/g6sxybp240fa72387faqjjn46xsxsjhn-caesium-image-compressor-2.7.1/lib 
-DCMAKE_INSTALL_DOCDIR=/nix/store/g6sxybp240fa72387faqjjn46xsxsjhn-caesium-image-compressor-2.7.1/share/doc/caesium-image-compressor 
-DCMAKE_INSTALL_INFODIR=/nix/store/g6sxybp240fa72387faqjjn46xsxsjhn-caesium-image-compressor-2.7.1/share/info 
-DCMAKE_INSTALL_MANDIR=/nix/store/g6sxybp240fa72387faqjjn46xsxsjhn-caesium-image-compressor-2.7.1/share/man 
-DCMAKE_INSTALL_OLDINCLUDEDIR=/nix/store/g6sxybp240fa72387faqjjn46xsxsjhn-caesium-image-compressor-2.7.1/include 
-DCMAKE_INSTALL_INCLUDEDIR=/nix/store/g6sxybp240fa72387faqjjn46xsxsjhn-caesium-image-compressor-2.7.1/include 
-DCMAKE_INSTALL_SBINDIR=/nix/store/g6sxybp240fa72387faqjjn46xsxsjhn-caesium-image-compressor-2.7.1/sbin 
-DCMAKE_INSTALL_BINDIR=/nix/store/g6sxybp240fa72387faqjjn46xsxsjhn-caesium-image-compressor-2.7.1/bin 
-DCMAKE_INSTALL_NAME_DIR=/nix/store/g6sxybp240fa72387faqjjn46xsxsjhn-caesium-image-compressor-2.7.1/lib 
-DCMAKE_POLICY_DEFAULT_CMP0025=NEW 
-DCMAKE_OSX_SYSROOT= -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_STRIP=/nix/store/zznja5f8v3jafffyah1rk46vpfcn38dv-gcc-wrapper-13.3.0/bin/strip 
-DCMAKE_RANLIB=/nix/store/zznja5f8v3jafffyah1rk46vpfcn38dv-gcc-wrapper-13.3.0/bin/ranlib 
-DCMAKE_AR=/nix/store/zznja5f8v3jafffyah1rk46vpfcn38dv-gcc-wrapper-13.3.0/bin/ar 
-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_INSTALL_PREFIX=/nix/store/g6sxybp240fa72387faqjjn46xsxsjhn-caesium-image-compressor-2.7.1
-- The CXX compiler identification is GNU 13.3.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /nix/store/zznja5f8v3jafffyah1rk46vpfcn38dv-gcc-wrapper-13.3.0/bin/g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:52 (message):
  CMAKE_PREFIX_PATH is not defined. Cannot find Qt dir.

-- Configuring incomplete, errors occurred!

```

---

<div class="post-metadata">

### Author: ![Atemu](https://discourse.nixos.org/user_avatar/discourse.nixos.org/atemu/32/10383_2.png) [@Atemu](https://discourse.nixos.org/u/Atemu)
#### Post date: [September 15, 2024, 6:56am UTC](https://discourse.nixos.org/t/nixpkgs-commit-that-mysteriously-broke-my-cmake-environment/52152/2 "2024-09-15T06:56:01Z")

</div>

I don’t know where you got the impression from that these two commits follow each other but neither is the other’s parent. There’s 11481 commits between them in fact.

Could you do a first-parent bisect between the two?

---

<div class="post-metadata">

### Author: ![Peal](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/p/6de8d8/32.png) [@Peal](https://discourse.nixos.org/u/Peal)
#### Post date: [October 22, 2024, 10:39am UTC](https://discourse.nixos.org/t/nixpkgs-commit-that-mysteriously-broke-my-cmake-environment/52152/3 "2024-10-22T10:39:44Z")

</div>

Hello, I took a break and completely forgot about this post. I’m so sorry

It turns out that when i do git bisect, i got the specific commit

> <https://github.com/NixOS/nixpkgs/commit/9ccfa877218074582ff21fe950944fa0a7240248#diff-72784174e495c2924a1f2149ef0907caf3fd38b4841453896ad5d47b5922515e>
>
> staging-next 2024-08-06

they change it from

```auto
addCMakeParams() {
    addToSearchPath CMAKE_PREFIX_PATH $1
}

```

to:

```auto
addCMakeParams() {
    addToSearchPath NIXPKGS_CMAKE_PREFIX_PATH $1
}

```

I’m still not sure how do i fix this since in the [original package’s `CMakeList.txt`](https://github.com/Lymphatus/caesium-image-compressor/blob/43aa74016e125367637c8744bddc163fc3dbcc87/CMakeLists.txt) contains this:

```auto
if (NOT (DEFINED ENV{CMAKE_PREFIX_PATH} OR DEFINED CMAKE_PREFIX_PATH))
    message(FATAL_ERROR "CMAKE_PREFIX_PATH is not defined. Cannot find Qt dir.")
endif ()

# And this:

find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets Core Gui Concurrent Svg Network Sql LinguistTools REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets Core Gui Concurrent Svg Network Sql LinguistTools REQUIRED)

```

and acording to what i know, `CMAKE_PREFIX_PATH` flag is required to use `find_package` in cmake

---

<div class="post-metadata">

### Author: ![kjeremy](https://discourse.nixos.org/user_avatar/discourse.nixos.org/kjeremy/32/4884_2.png) [@kjeremy](https://discourse.nixos.org/u/kjeremy)
#### Post date: [October 22, 2024, 3:41pm UTC](https://discourse.nixos.org/t/nixpkgs-commit-that-mysteriously-broke-my-cmake-environment/52152/4 "2024-10-22T15:41:30Z")

</div>

The move to `NIXPKGS_CMAKE_PREFIX_PATH` also caused us a lot of problems in nix-ros-overlay. See: [Since b6676bf cmake\_modules cannot be found · Issue #491 · lopsided98/nix-ros-overlay · GitHub](https://github.com/lopsided98/nix-ros-overlay/issues/491) basically the solution ended up being to patch some `.cmake` files in catkin.

---

<div class="post-metadata">

### Author: ![Peal](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/p/6de8d8/32.png) [@Peal](https://discourse.nixos.org/u/Peal)
#### Post date: [October 22, 2024, 11:00pm UTC](https://discourse.nixos.org/t/nixpkgs-commit-that-mysteriously-broke-my-cmake-environment/52152/5 "2024-10-22T23:00:59Z")

</div>

Thank you so much for the solution. Though I have a dumb question. How do i make a patch file?  
do i just copy the `.cmake` file to another location, fix it and `diff -u ./a/CMakeList.txt ./b/CMakeList.txt > cmake_patch.patch`?

I have a feeling like it is not the case at all. Could you please teach me how do i make patch file properly?

---

<div class="post-metadata">

### Author: ![paparodeo](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/p/f05b48/32.png) [@paparodeo](https://discourse.nixos.org/u/paparodeo)
#### Post date: [October 23, 2024, 4:41am UTC](https://discourse.nixos.org/t/nixpkgs-commit-that-mysteriously-broke-my-cmake-environment/52152/6 "2024-10-23T04:41:33Z")

</div>

Looking at the previously linked `CMakeList.txt` it seems there is just a check to see if `CMAKE_PREFIX_PATH` exists but it doesn’t actually do anything with it, as below it seems to just use normal `find_package`. if this is the case, there is no patch required and in your derivation you can probably just set `env.CMAKE_PREFIX_PATH = "";` to satisfy the check and things should build.

FWIW: the change which removed `CMAKE_PREFIX_PATH` from the cmake setup hook is this one: [cmake: fix strictDeps by paparodeo · Pull Request #318226 · NixOS/nixpkgs · GitHub](https://github.com/NixOS/nixpkgs/pull/318226)

---

<div class="post-metadata">

### Author: ![SergeK](https://discourse.nixos.org/user_avatar/discourse.nixos.org/sergek/32/2972_2.png) [@SergeK](https://discourse.nixos.org/u/SergeK)
#### Post date: [October 24, 2024, 7:24am UTC](https://discourse.nixos.org/t/nixpkgs-commit-that-mysteriously-broke-my-cmake-environment/52152/7 "2024-10-24T07:24:04Z")

</div>

In the PR we had discussed the potential alternative that would keep `CMAKE_PREFIX_PATH` but modify only the way it’s interpreted: [cmake: fix strictDeps by paparodeo · Pull Request #318226 · NixOS/nixpkgs · GitHub](https://github.com/NixOS/nixpkgs/pull/318226#issuecomment-2254491401). It’s not guaranteed to be smooth, but it should be a matter of somebody allocating the time to do the work

---

<div class="post-metadata">

### Author: ![paparodeo](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/p/f05b48/32.png) [@paparodeo](https://discourse.nixos.org/u/paparodeo)
#### Post date: [October 24, 2024, 6:17pm UTC](https://discourse.nixos.org/t/nixpkgs-commit-that-mysteriously-broke-my-cmake-environment/52152/8 "2024-10-24T18:17:57Z")

</div>

i think that we’d still see failures due to bespoke cmake builds trying to use `CMAKE_PREFIX_PATH` and not realizing it can be a partial path that needs to be concatenated with `CMAKE_FIND_ROOT_PATH`. eg: the thing that broke in the ros overlay with `NIXPKGS_CMAKE_PREFIX_PATH` would still be broken.

however, the OP issue might have been solved as it seems that build system just errors out of `CMAKE_PREFIX_PATH` doesn’t exist.

so i am not sure if we will be able to get cmake to work how we want it, not search `CMAKE_PREFIX_PATH` when using `find_program`, and also not break some bespoke cmake build system. but others are welcome to try.

[edit]: tho the fixes could be upstreamed to use `CMAKE_FIND_ROOT_PATH` but it seems unlikely `NIXPKGS_CMAKE_PREFIX_PATH` would be welcomed outside of nixpkgs.

---

<div class="post-metadata">

### Author: ![SergeK](https://discourse.nixos.org/user_avatar/discourse.nixos.org/sergek/32/2972_2.png) [@SergeK](https://discourse.nixos.org/u/SergeK)
#### Post date: [October 24, 2024, 6:52pm UTC](https://discourse.nixos.org/t/nixpkgs-commit-that-mysteriously-broke-my-cmake-environment/52152/9 "2024-10-24T18:52:15Z")

</div>

> [@paparodeo](#):
>
> not realizing it can be a partial path that needs to be concatenated with `CMAKE_FIND_ROOT_PATH`. e

Ah right I didn’t think that far, but

> [@paparodeo](#):
>
> tho the fixes could be upstreamed to use `CMAKE_FIND_ROOT_PATH` but it seems unlikely `NIXPKGS_CMAKE_PREFIX_PATH` would be welcomed outside of nixpkgs.

Yes, at least with `CMAKE_FIND_ROOT_PATH` we can honestly say we’re “doing the expected thing” and the others are wrong 🙃
