Advent of Code 2025, done in C++
1{
2 description = "Flake-based development environment for C++.";
3
4 inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; # unstable Nixpkgs
5
6 outputs =
7 { self, ... }@inputs:
8
9 let
10 supportedSystems = [
11 "x86_64-linux"
12 "aarch64-linux"
13 "x86_64-darwin"
14 "aarch64-darwin"
15 ];
16 forEachSupportedSystem =
17 f:
18 inputs.nixpkgs.lib.genAttrs supportedSystems (
19 system:
20 f {
21 pkgs = import inputs.nixpkgs { inherit system; };
22 }
23 );
24 in
25 {
26 devShells = forEachSupportedSystem (
27 { pkgs }:
28 {
29 default =
30 pkgs.mkShell.override
31 {
32 # Override stdenv in order to change compiler:
33 stdenv = pkgs.clangStdenv;
34 # Comment the line above if you want GCC
35 }
36 {
37 packages =
38 with pkgs;
39 [
40 clang-tools # IMPORTANT - it **always** MUST stay right above clang
41 clang
42
43 codespell
44 cppcheck
45 doxygen
46 gtest
47 lcov
48 vcpkg
49 vcpkg-tool
50
51 # BUILD
52 pkg-config
53 meson
54 ninja
55 just
56
57 # LIBRARIES
58 libcxx
59
60 # DEBUGGERS
61 lldb
62 ]
63 ++ (if system == "aarch64-darwin" then [ ] else [ gdb ]);
64
65 env = {
66 # Tell clangd to use the real clang wrapper that *knows* about include paths.
67 CLANGD_FLAGS = "--query-driver=${pkgs.clang}/bin/clang*";
68
69 # Ensure Meson picks clang instead of GCC.
70 CC = "${pkgs.clang}/bin/clang";
71 CXX = "${pkgs.clang}/bin/clang++";
72 };
73 };
74 }
75 );
76
77 # Feel free to delete this once the project is initialized.
78 templates.default = {
79 path = ./.;
80 description = "Meson-based C++ project template";
81 };
82 };
83}