An opinionated Nix-based template to ease the development of C++ programs
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

init

bpavuk f51d5d1b

+216
.cache/clangd/index/hello.cxx.8E4D34EC800FA2DC.idx

This is a binary file and will not be displayed.

.cache/clangd/index/hello.h.9CD47C52DAF57F31.idx

This is a binary file and will not be displayed.

.cache/clangd/index/main.cxx.73988AC5EC6AC948.idx

This is a binary file and will not be displayed.

.cache/clangd/index/main.cxx.7FEBC8E2E278760C.idx

This is a binary file and will not be displayed.

.cache/clangd/index/main.cxx.F5BE540AE2F2FF94.idx

This is a binary file and will not be displayed.

.cache/clangd/index/pass_gen.cxx.2FF7552BE40530EA.idx

This is a binary file and will not be displayed.

.cache/clangd/index/pass_gen.h.5B6DAA5DD3EE17E2.idx

This is a binary file and will not be displayed.

+1
.direnv/flake-profile
··· 1 + flake-profile-20-link
+1
.envrc
··· 1 + use flake
+1
.gitignore
··· 1 + build/
+13
Justfile
··· 1 + default: sync build 2 + 3 + # Run this whenever you change build files. This generates the latest build config. 4 + sync: 5 + meson setup --reconfigure build/ 6 + 7 + # Build a program with Meson. Make sure to run sync beforehand! 8 + build: 9 + meson compile -C build/ 10 + 11 + # Clean the build folder. Useful... sometimes. 12 + clean: 13 + meson setup --wipe build/
+43
README.md
··· 1 + # C++ Template 2 + 3 + Meson-based C++ starter with a Nix Flake dev shell that ships Clang, tooling, and a simple `just` workflow so you don't have to worry about Clangd hating the world. 4 + 5 + ## Getting Started 6 + 7 + 1. Create a project from the template: 8 + ```sh 9 + nix flake init --template git@tangled.sh:bpavuk.neocities.org/cxx-template 10 + ``` 11 + 2. Enter the development shell (installs compilers, linters, debuggers): 12 + ```sh 13 + nix develop 14 + ``` 15 + 3. Configure and build: 16 + ```sh 17 + just sync # runs meson setup --reconfigure build/ 18 + just build # runs meson compile -C build/ 19 + ./build/cxx-template 20 + 21 + # or even simpler 22 + 23 + just # runs both sync and build. 24 + ./build/cxx-template 25 + ``` 26 + 27 + You can also use `direnv` to get into the environment upon opening the directory: 28 + ```sh 29 + direnv allow 30 + ``` 31 + 32 + To explore more `just` recipes, run `just -l`. 33 + 34 + ## Project Layout 35 + 36 + - `meson.build`, `src/` - Meson project configuration and sources. 37 + - `Justfile` - Convenience tasks (`sync`, `build`, `clean`). 38 + - `flake.nix` - Dev-shell definition; tweak packages if you need extra tools. 39 + 40 + ## Notes 41 + 42 + - The template intentionally omits tests so you can plug in your preferred framework; add a Meson `test()` target when ready. 43 + - If you prefer GCC, remove the `stdenv = pkgs.clangStdenv` override inside `flake.nix`, and tune the `CC` and `CXX` variables.
+1
compile_commands.json
··· 1 + builddir/compile_commands.json
+27
flake.lock
··· 1 + { 2 + "nodes": { 3 + "nixpkgs": { 4 + "locked": { 5 + "lastModified": 1763464769, 6 + "narHash": "sha256-AJHrsT7VoeQzErpBRlLJM1SODcaayp0joAoEA35yiwM=", 7 + "owner": "NixOS", 8 + "repo": "nixpkgs", 9 + "rev": "6f374686605df381de8541c072038472a5ea2e2d", 10 + "type": "github" 11 + }, 12 + "original": { 13 + "owner": "NixOS", 14 + "ref": "nixpkgs-unstable", 15 + "repo": "nixpkgs", 16 + "type": "github" 17 + } 18 + }, 19 + "root": { 20 + "inputs": { 21 + "nixpkgs": "nixpkgs" 22 + } 23 + } 24 + }, 25 + "root": "root", 26 + "version": 7 27 + }
+83
flake.nix
··· 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 + }
+19
meson.build
··· 1 + project( 2 + 'cxx-template', 3 + 'cpp', 4 + default_options : [ 5 + 'warning_level=3', 6 + 'cpp_std=c++23', 7 + 'implicit_include_directories=false' 8 + ], 9 + ) 10 + 11 + cpp = meson.get_compiler('cpp') 12 + 13 + 14 + subdir('src') 15 + 16 + executable( 17 + 'cxx-template', 18 + sources : project_sources 19 + )
+6
src/hello.cxx
··· 1 + #include "hello.h" 2 + #include <print> 3 + 4 + void hello() { 5 + std::println("Hello!"); 6 + }
+7
src/hello.h
··· 1 + #ifndef HELLO_H 2 + 3 + #define HELLO_H 4 + 5 + void hello(); 6 + 7 + #endif // !HELLO_H
+9
src/main.cxx
··· 1 + #include "hello.h" 2 + #include <cstdlib> 3 + 4 + int main() { 5 + hello(); 6 + 7 + return EXIT_SUCCESS; 8 + } 9 +
+4
src/meson.build
··· 1 + project_sources = files( 2 + 'main.cxx', 3 + 'hello.cxx' 4 + )