# How to create a nix shell for C++ programming

**URL:** https://discourse.nixos.org/t/how-to-create-a-nix-shell-for-c-programming/72619
**Category:** Help
**Created:** [November 28, 2025, 5:40am UTC](https://discourse.nixos.org/t/how-to-create-a-nix-shell-for-c-programming/72619 "2025-11-28T05:40:27Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![Inarizxc](https://discourse.nixos.org/user_avatar/discourse.nixos.org/inarizxc/32/28234_2.png) [@Inarizxc](https://discourse.nixos.org/u/Inarizxc)
#### Post date: [November 28, 2025, 5:40am UTC](https://discourse.nixos.org/t/how-to-create-a-nix-shell-for-c-programming/72619/1 "2025-11-28T05:40:27Z")

</div>

I seem to have installed everything for C++, but lsp still doesn’t see the header files for some reason.

---

<div class="post-metadata">

### Author: ![waffle8946](https://discourse.nixos.org/user_avatar/discourse.nixos.org/waffle8946/32/27221_2.png) [@waffle8946](https://discourse.nixos.org/u/waffle8946)
#### Post date: [November 28, 2025, 3:29pm UTC](https://discourse.nixos.org/t/how-to-create-a-nix-shell-for-c-programming/72619/2 "2025-11-28T15:29:19Z")

</div>

Define “installed”. If you put it in your config, remove it.  
If you made a `shell.nix` or some `mkShell` environment, share that code.

---

<div class="post-metadata">

### Author: ![Inarizxc](https://discourse.nixos.org/user_avatar/discourse.nixos.org/inarizxc/32/28234_2.png) [@Inarizxc](https://discourse.nixos.org/u/Inarizxc)
#### Post date: [November 28, 2025, 4:01pm UTC](https://discourse.nixos.org/t/how-to-create-a-nix-shell-for-c-programming/72619/3 "2025-11-28T16:01:24Z")

</div>

My `flake.nix`:

```auto
{
  description = "C++ dev";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
  };

  outputs = { self, nixpkgs }:
    let
      system = "x86_64-linux";
      pkgs = nixpkgs.legacyPackages.${system};
    in
    {
      devShells.${system}.default = pkgs.mkShell.override {
      } {
        packages = with pkgs; [
          cmake
          ninja
          pkg-config
          clang
          lld
          lldb
          clang-tools
        ];

        shellHook = ''
          echo "C++ dev environment"
          clang++ --version
        '';
      };
    };
}

```

---

<div class="post-metadata">

### Author: ![waffle8946](https://discourse.nixos.org/user_avatar/discourse.nixos.org/waffle8946/32/27221_2.png) [@waffle8946](https://discourse.nixos.org/u/waffle8946)
#### Post date: [November 28, 2025, 5:05pm UTC](https://discourse.nixos.org/t/how-to-create-a-nix-shell-for-c-programming/72619/4 "2025-11-28T17:05:50Z")

</div>

> [@Clang, clang++, and clangd can't find headers, even with compile\_commands.json](https://discourse.nixos.org/t/clang-clang-and-clangd-cant-find-headers-even-with-compile-commands-json/54657/6):
>
> What you’re meant to do is override the stdenv if you want it to use clang: pkgs.mkShell.override { stdenv = pkgs.clang19Stdenv; } { packages = [pkgs.cmake # ... whatever else, but NOT C compilers though!]; } (or inherit (pkgs.llvmPackages\_19) stdenv;, if you prefer) and instead of the deprecated devShell.\<system\>, use devShells.\<system\>.default.

---

<div class="post-metadata">

### Author: ![Inarizxc](https://discourse.nixos.org/user_avatar/discourse.nixos.org/inarizxc/32/28234_2.png) [@Inarizxc](https://discourse.nixos.org/u/Inarizxc)
#### Post date: [November 28, 2025, 5:22pm UTC](https://discourse.nixos.org/t/how-to-create-a-nix-shell-for-c-programming/72619/5 "2025-11-28T17:22:22Z")

</div>

```auto
{
  description = "C++ dev";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
  };

  outputs = { self, nixpkgs }:
    let
      system = "x86_64-linux";
      pkgs = nixpkgs.legacyPackages.${system};
    in
    {
      devShells.${system}.default = pkgs.mkShell.override {
        stdenv = pkgs.clang19Stdenv;
      } {
        packages = with pkgs; [
          cmake
        ];
        shellHook = ''
          echo "C++ dev environment"
        '';
      };
    };
}

```

Still not working

---

<div class="post-metadata">

### Author: ![NobbZ](https://discourse.nixos.org/user_avatar/discourse.nixos.org/nobbz/32/7022_2.png) [@NobbZ](https://discourse.nixos.org/u/NobbZ)
#### Post date: [November 28, 2025, 5:37pm UTC](https://discourse.nixos.org/t/how-to-create-a-nix-shell-for-c-programming/72619/6 "2025-11-28T17:37:58Z")

</div>

What exactly does “not working” mean?

---

<div class="post-metadata">

### Author: ![Inarizxc](https://discourse.nixos.org/user_avatar/discourse.nixos.org/inarizxc/32/28234_2.png) [@Inarizxc](https://discourse.nixos.org/u/Inarizxc)
#### Post date: [November 28, 2025, 5:52pm UTC](https://discourse.nixos.org/t/how-to-create-a-nix-shell-for-c-programming/72619/7 "2025-11-28T17:52:20Z")

</div>

The program is now being compiled, but the code editors (I tried in `helix` and `zed-editor`) show the error `'iostream' file not found (clang pp_file_not_found)`

---

<div class="post-metadata">

### Author: ![NobbZ](https://discourse.nixos.org/user_avatar/discourse.nixos.org/nobbz/32/7022_2.png) [@NobbZ](https://discourse.nixos.org/u/NobbZ)
#### Post date: [November 28, 2025, 5:58pm UTC](https://discourse.nixos.org/t/how-to-create-a-nix-shell-for-c-programming/72619/8 "2025-11-28T17:58:35Z")

</div>

Do you have a `compile_commands.json`?

---

<div class="post-metadata">

### Author: ![Inarizxc](https://discourse.nixos.org/user_avatar/discourse.nixos.org/inarizxc/32/28234_2.png) [@Inarizxc](https://discourse.nixos.org/u/Inarizxc)
#### Post date: [November 28, 2025, 6:13pm UTC](https://discourse.nixos.org/t/how-to-create-a-nix-shell-for-c-programming/72619/9 "2025-11-28T18:13:57Z")

</div>

No, but how do I create it? (sorry, I’m just a newbie and I haven’t figured it out yet)

---

<div class="post-metadata">

### Author: ![InOnesGraveDed](https://discourse.nixos.org/user_avatar/discourse.nixos.org/inonesgraveded/32/34886_2.png) [@InOnesGraveDed](https://discourse.nixos.org/u/InOnesGraveDed)
#### Post date: [November 28, 2025, 6:14pm UTC](https://discourse.nixos.org/t/how-to-create-a-nix-shell-for-c-programming/72619/10 "2025-11-28T18:14:58Z")

</div>

Hi there,  
I use Zed Editor with C++ too and ran into the same issue with header files. I found a workaround in some discussions and while it’s definitely not ideal - it’s a nice temporary fix, at least for me, who still learning NixOS 😅.

In your CMakeLists.txt, add this:

```auto
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")
if(CMAKE_EXPORT_COMPILE_COMMANDS)
    set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES
      ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
endif()

```

Then, run:

```auto
cmake -S . -B build/
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1

```

---

<div class="post-metadata">

### Author: ![Inarizxc](https://discourse.nixos.org/user_avatar/discourse.nixos.org/inarizxc/32/28234_2.png) [@Inarizxc](https://discourse.nixos.org/u/Inarizxc)
#### Post date: [December 12, 2025, 2:17pm UTC](https://discourse.nixos.org/t/how-to-create-a-nix-shell-for-c-programming/72619/11 "2025-12-12T14:17:54Z")

</div>

Sorry to come back here after all this time, but I’ve already gone through everything, and it doesn’t help, the editors don’t see the header files.

---

<div class="post-metadata">

### Author: ![mark](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@mark](https://discourse.nixos.org/u/mark)
#### Post date: [December 12, 2025, 2:45pm UTC](https://discourse.nixos.org/t/how-to-create-a-nix-shell-for-c-programming/72619/12 "2025-12-12T14:45:24Z")

</div>

Have you opened the editors AFER you cd to the directory and opend them from the command line there?

---

<div class="post-metadata">

### Author: ![Inarizxc](https://discourse.nixos.org/user_avatar/discourse.nixos.org/inarizxc/32/28234_2.png) [@Inarizxc](https://discourse.nixos.org/u/Inarizxc)
#### Post date: [December 12, 2025, 2:57pm UTC](https://discourse.nixos.org/t/how-to-create-a-nix-shell-for-c-programming/72619/13 "2025-12-12T14:57:34Z")

</div>

I open the editor on the command line in nix-shell
