Something went wrong. Try again.
A Tour of C++ for experienced programmers, as if C++26 is the only version that ever existed.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120{ description = "A Tour of C++26 — book build environment (Clang 22+ with -Wlifetime-safety, libc++, mdBook)";
# Indirect reference: resolves through the user's flake registry (nixpkgs) # and pins the resolved revision in flake.lock. At lock time (2026-08): # llvmPackages_latest = LLVM 22.1.8, mdbook = 0.5.4, cmake = 4.3.4. inputs.nixpkgs.url = "nixpkgs";
outputs = { self, nixpkgs }: let systems = [ "aarch64-darwin" "x86_64-darwin" "x86_64-linux" "aarch64-linux" ]; forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f (import nixpkgs { inherit system; }));
# Files that make up the book source. Everything else (build output, # VCS metadata, editor state) is excluded so the derivation builds from # a clean tree. srcFiles = [ "book" "examples" "cmake" "scripts" "CMakeLists.txt" "CMakePresets.json" "book.toml" ".clang-tidy" ".clang-format" "flake.nix" "flake.lock" ]; excluded = [ "build" "html" ".git" ".jj" ".direnv" ".omp" ]; cleanSource = path: builtins.filterSource (name: type: let base = baseNameOf name; rel = builtins.substring (builtins.stringLength (toString path) + 1) (builtins.stringLength (toString name)) (toString name); isExcluded = builtins.elem base excluded; isIncluded = builtins.any (s: s == base || builtins.match "${s}/.*" rel != null) srcFiles; in !isExcluded && (type == "directory" || isIncluded)) path; in { devShells = forAllSystems (pkgs: let # LLVM latest (22.x): required for the lifetime-safety analysis # flag -Wlifetime-safety (Clang >= 22). libc++ is the C++26 library. llvm = pkgs.llvmPackages_latest; # Python with markdown-it-py: runs scripts/chapter_lint.py, which # parses chapters with a real Markdown parser. lintPython = pkgs.python3.withPackages (ps: [ ps.markdown-it-py ]); in { default = (pkgs.mkShell.override { stdenv = llvm.libcxxStdenv; }) { packages = [ llvm.clang-tools # clang-tidy, clangd, clang-format for the pinned LLVM pkgs.cmake pkgs.ninja pkgs.mdbook lintPython # python3 + markdown-it-py for scripts/chapter_lint.py llvm.lldb ]; shellHook = '' export CC=clang CXX=clang++ ''; }; });
packages = forAllSystems (pkgs: let llvm = pkgs.llvmPackages_latest; # Python with markdown-it-py: runs scripts/chapter_lint.py during the # buildPhase prose gate. lintPython = pkgs.python3.withPackages (ps: [ ps.markdown-it-py ]); in { # Cross-platform build target: renders the book with mdBook, and the # derivation only succeeds when every example builds (with -Werror, # clang-tidy, and sanitizers) and each test output matches its EXPECT # regex. A single `nix build .#website` therefore runs the whole # acceptance gate in a clean sandbox. website = llvm.libcxxStdenv.mkDerivation { pname = "tour-cpp26-website"; version = "0.1.0"; src = cleanSource ./.; nativeBuildInputs = [ pkgs.cmake pkgs.ninja llvm.clang-tools # clang-tidy is part of the compile gate pkgs.mdbook lintPython # python3 + markdown-it-py for scripts/lint-book.sh ]; # The default cmake setup hook would run its own configure into # build/ and clash with the dev preset. Drive cmake by hand instead. dontConfigure = true; buildPhase = '' runHook preBuild cmake --preset dev cmake --build build -j ctest --test-dir build --output-on-failure bash scripts/lint-book.sh mdbook build runHook postBuild ''; installPhase = '' runHook preInstall mkdir -p "$out" cp -r html/. "$out/" runHook postInstall ''; }; html = self.packages.${pkgs.stdenv.hostPlatform.system}.website; }); };}