# \`cmakeFlags\` silently dropped in \`buildPythonPackage\` stdenv

**URL:** https://discourse.nixos.org/t/cmakeflags-silently-dropped-in-buildpythonpackage-stdenv/80808
**Category:** Help
**Created:** [October 27, 2026, 7:40pm UTC](https://discourse.nixos.org/t/cmakeflags-silently-dropped-in-buildpythonpackage-stdenv/80808 "2026-10-27T19:40:00Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![debtquity](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/d/91b2a8/32.png) [@debtquity](https://discourse.nixos.org/u/debtquity)
#### Post date: [October 27, 2026, 7:40pm UTC](https://discourse.nixos.org/t/cmakeflags-silently-dropped-in-buildpythonpackage-stdenv/80808/1 "2026-10-27T19:40:00Z")

</div>

I am working on converting:

```auto
  cmakeFlags = lib.concatLists [
    [
      (lib.cmakeFeature "CMAKE_INSTALL_PREFIX" "${placeholder "out"}/${python.sitePackages}")
    ]
    [(lib.cmakeBool "BUILD_MD" withMd)]
    [(lib.cmakeBool "BUILD_HPMC" withHpmc)]
    [(lib.cmakeBool "BUILD_METAL" withMetal)]
    [(lib.cmakeBool "BUILD_MPCD" withMpcd)]

    [(lib.cmakeBool "BUILD_TESTING" finalAttrs.doCheck)]

    [(lib.cmakeBool "ENABLE_MPI" withMpi)]
    (lib.optional withMpi (lib.cmakeFeature "MPI_HOME" "${lib.getDev mpi}"))
  ];

```

to

```auto
  cmakeFlags = [
    (lib.cmakeFeature "CMAKE_INSTALL_PREFIX" "${placeholder "out"}/${python.sitePackages}")

    (lib.cmakeBool "BUILD_MD" withMd)
    (lib.cmakeBool "BUILD_HPMC" withHpmc)
    (lib.cmakeBool "BUILD_METAL" withMetal)
    (lib.cmakeBool "BUILD_MPCD" withMpcd)

    (lib.cmakeBool "BUILD_TESTING" finalAttrs.doCheck)

    (lib.cmakeBool "ENABLE_MPI" withMpi)
    (lib.optional withMpi (lib.cmakeFeature "MPI_HOME" "${lib.getDev mpi}"))
  ];

```

However, the change will result in build failure since the `cmakeFlags` will get silently dropped (default configuration from upstream attempt to install python libs into site-packages of python path) [1]:

```auto
...
2026-10-27T17:56:03.5881997Z python3.14-hoomd-blue> 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/8ybr6xv40hmg53bzyrm9fm6v2l383q4m-python3.14-hoomd-blue-7.2.0/share/locale -DCMAKE_INSTALL_LIBEXECDIR=/nix/store/8ybr6xv40hmg53bzyrm9fm6v2l383q4m-python3.14-hoomd-blue-7.2.0/libexec -DCMAKE_INSTALL_LIBDIR=/nix/store/8ybr6xv40hmg53bzyrm9fm6v2l383q4m-python3.14-hoomd-blue-7.2.0/lib -DCMAKE_INSTALL_DOCDIR=/nix/store/8ybr6xv40hmg53bzyrm9fm6v2l383q4m-python3.14-hoomd-blue-7.2.0/share/doc/HOOMD -DCMAKE_INSTALL_INFODIR=/nix/store/8ybr6xv40hmg53bzyrm9fm6v2l383q4m-python3.14-hoomd-blue-7.2.0/share/info -DCMAKE_INSTALL_MANDIR=/nix/store/8ybr6xv40hmg53bzyrm9fm6v2l383q4m-python3.14-hoomd-blue-7.2.0/share/man -DCMAKE_INSTALL_INCLUDEDIR=/nix/store/8ybr6xv40hmg53bzyrm9fm6v2l383q4m-python3.14-hoomd-blue-7.2.0/include -DCMAKE_INSTALL_SBINDIR=/nix/store/8ybr6xv40hmg53bzyrm9fm6v2l383q4m-python3.14-hoomd-blue-7.2.0/sbin -DCMAKE_INSTALL_BINDIR=/nix/store/8ybr6xv40hmg53bzyrm9fm6v2l383q4m-python3.14-hoomd-blue-7.2.0/bin -DCMAKE_INSTALL_NAME_DIR=/nix/store/8ybr6xv40hmg53bzyrm9fm6v2l383q4m-python3.14-hoomd-blue-7.2.0/lib -DCMAKE_STRIP=/nix/store/fliwi0hjfdjb1wgg4cncxlv58a14ndah-gcc-wrapper-14.4.0/bin/strip -DCMAKE_RANLIB=/nix/store/fliwi0hjfdjb1wgg4cncxlv58a14ndah-gcc-wrapper-14.4.0/bin/ranlib -DCMAKE_AR=/nix/store/fliwi0hjfdjb1wgg4cncxlv58a14ndah-gcc-wrapper-14.4.0/bin/ar -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DPYBIND11_PYTHONLIBS_OVERWRITE=OFF -DPYTHON_EXECUTABLE=/nix/store/xahxrjs30p3mw0a42bqg9ikgkikskw8m-python3-3.14.8/bin/python3.14 -DPYTHON_INCLUDE_DIR=/nix/store/xahxrjs30p3mw0a42bqg9ikgkikskw8m-python3-3.14.8/include/python3.14 -DPYTHON_SITE_PACKAGES=/nix/store/xahxrjs30p3mw0a42bqg9ikgkikskw8m-python3-3.14.8/lib/python3.14/site-packages
...
2026-10-27T18:45:58.5067116Z error: Cannot build '/nix/store/wfl3cf28iv00y7i3qnzlqaax2l911ch8-python3.14-hoomd-blue-7.2.0.drv'.
2026-10-27T18:45:58.5068098Z Reason: builder failed with exit code 2.
2026-10-27T18:45:58.5068586Z Output paths:
2026-10-27T18:45:58.5069229Z /nix/store/8ybr6xv40hmg53bzyrm9fm6v2l383q4m-python3.14-hoomd-blue-7.2.0
2026-10-27T18:45:58.5069961Z Last 25 log lines:
2026-10-27T18:45:58.5070379Z > [35%] Built target copy_md_pytest
2026-10-27T18:45:58.5070870Z > [40%] Built target copy_hpmc_pytest
2026-10-27T18:45:58.5071344Z > [41%] Built target copy_hpmc
2026-10-27T18:45:58.5071791Z > [42%] Built target copy_hpmc_tune
2026-10-27T18:45:58.5072253Z > [44%] Built target copy_hpmc-pair
2026-10-27T18:45:58.5072725Z > [44%] Built target copy_hpmc-external
2026-10-27T18:45:58.5073186Z > [46%] Built target copy_mpcd
2026-10-27T18:45:58.5073454Z > [47%] Built target copy_hpmc-nec
2026-10-27T18:45:58.5073728Z > [48%] Built target copy_mpcd_pytest
2026-10-27T18:45:58.5074050Z > [57%] Built target _hoomd
2026-10-27T18:45:58.5074365Z > [62%] Built target _hpmc
2026-10-27T18:45:58.5074818Z > [88%] Built target _md
2026-10-27T18:45:58.5075062Z > [100%] Built target _mpcd
2026-10-27T18:45:58.5075676Z > Install the project...
2026-10-27T18:45:58.5076406Z > -- Install configuration: "Release"
2026-10-27T18:45:58.5077015Z > CMake Error at hoomd/extern/cmake_install.cmake:46 (file):
2026-10-27T18:45:58.5077695Z > file cannot create directory:
2026-10-27T18:45:58.5078679Z > /nix/store/xahxrjs30p3mw0a42bqg9ikgkikskw8m-python3-3.14.8/lib/python3.14/site-packages/hoomd/include/hoomd/extern.
2026-10-27T18:45:58.5079732Z > Maybe need administrative privileges.
2026-10-27T18:45:58.5080282Z > Call Stack (most recent call first):
2026-10-27T18:45:58.5080808Z > hoomd/cmake_install.cmake:47 (include)
2026-10-27T18:45:58.5081326Z > cmake_install.cmake:52 (include)
2026-10-27T18:45:58.5081790Z >
2026-10-27T18:45:58.5082097Z > 
2026-10-27T18:45:58.5082471Z > make: *** [Makefile:110: install] Error 1

```

Is this a bug in stdenv, or am I missing something else?

[1] [review #579046 · debtquity/nixpkgs-review-gha@c28ca54 · GitHub](https://github.com/debtquity/nixpkgs-review-gha/actions/runs/40554128419/attempts/1)

---

<div class="post-metadata">

### Author: ![bitbloxhub](https://discourse.nixos.org/user_avatar/discourse.nixos.org/bitbloxhub/32/35210_2.png) [@bitbloxhub](https://discourse.nixos.org/u/bitbloxhub)
#### Post date: [October 27, 2026, 8:01pm UTC](https://discourse.nixos.org/t/cmakeflags-silently-dropped-in-buildpythonpackage-stdenv/80808/2 "2026-10-27T20:01:14Z")

</div>

> [@debtquity](#):
>
> `(lib.optional withMpi (lib.cmakeFeature "MPI_HOME" "${lib.getDev mpi}"))`

I see the issue:  
[`lib.optional`](https://noogle.dev/f/lib/optional/) returns either an empty list or a list with the optional item (implementation: `cond: elem: if cond then [elem] else [];`), so it works with `lib.concatLists`, but not with the `cmakeFlags` list directly (your current impl ends up with something like `["flag" "other-flag" ... ([ "optional flag"] or just [])`). use `++ lib.optional withMpi ...` after the closing bracket instead.

---

<div class="post-metadata">

### Author: ![debtquity](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/d/91b2a8/32.png) [@debtquity](https://discourse.nixos.org/u/debtquity)
#### Post date: [October 27, 2026, 8:10pm UTC](https://discourse.nixos.org/t/cmakeflags-silently-dropped-in-buildpythonpackage-stdenv/80808/3 "2026-10-27T20:10:20Z")

</div>

I fixed by moving `(lib.optional withMpi ..)` outside the list:

```auto
  cmakeFlags = [
    ...
    (lib.cmakeBool "ENABLE_MPI" withMpi)
  ]
  ++ (lib.optional withMpi (lib.cmakeFeature "MPI_HOME" "${lib.getDev mpi}"));

```

thanks, @K900 on matrix
