Skip to content

Instantly share code, notes, and snippets.

@cyang-el
Forked from fufexan/cpp-dev-env-flake.nix
Created February 18, 2024 23:05
Show Gist options
  • Save cyang-el/f5ef7f86366cc78dba2eea548d6864a3 to your computer and use it in GitHub Desktop.
Save cyang-el/f5ef7f86366cc78dba2eea548d6864a3 to your computer and use it in GitHub Desktop.

Revisions

  1. @fufexan fufexan revised this gist Apr 19, 2022. 1 changed file with 19 additions and 8 deletions.
    27 changes: 19 additions & 8 deletions cpp-dev-env-flake.nix
    Original file line number Diff line number Diff line change
    @@ -34,27 +34,38 @@
    in
    {
    devShell = p.mkShell.override { stdenv = p.clangStdenv; } rec {
    packages = [
    packages = with p; [
    # builder
    p.gnumake
    p.cmake
    p.bear
    gnumake
    cmake
    bear

    # debugger
    llvm.lldb
    p.gdb
    gdb

    # fix headers not found
    p.clang-tools
    clang-tools

    # LSP and compiler
    llvm.libstdcxxClang

    # other tools
    cppcheck
    llvm.libllvm
    p.valgrind
    valgrind
    mymake

    # stdlib for cpp
    llvm.libcxx

    # libs
    glm
    SDL2
    SDL2_gfx
    ];
    name = "C";
    };
    }
    );
    }
    }
  2. @fufexan fufexan revised this gist Feb 26, 2022. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions cpp-dev-env-flake.nix
    Original file line number Diff line number Diff line change
    @@ -22,39 +22,39 @@
    mymake = p.writeShellScriptBin "mk" ''
    if [ -f "$1.c" ]; then
    i="$1.c"
    c=$CC
    else
    i="$1.cpp"
    c=$CXX
    fi
    o=$1
    shift
    $CC -ggdb $i -o $o -lm -Wall $@
    $c -ggdb $i -o $o -lm -Wall $@
    '';
    in
    {
    devShell = p.mkShell.override { stdenv = p.clangStdenv; } rec {
    nativeBuildInputs = [
    packages = [
    # builder
    p.gnumake
    p.cmake
    p.bear
    # debugger
    llvm.lldb
    p.gdb
    # fix headers not found
    p.clang-tools
    # LSP and compiler
    llvm.clang
    llvm.libstdcxxClang
    # other tools
    llvm.libllvm
    p.valgrind
    mymake
    ];
    buildInputs = [
    # stdlib for cpp
    llvm.libcxx
    ];
    CPATH = nixpkgs.lib.makeSearchPathOutput "dev" "include" buildInputs;
    name = "C";
    };
    }
    );
    }
    }
  3. @fufexan fufexan created this gist Jan 31, 2022.
    60 changes: 60 additions & 0 deletions cpp-dev-env-flake.nix
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,60 @@
    {
    description = "C/C++ environment";

    inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    utils.url = "github:numtide/flake-utils";
    };

    outputs = { self, nixpkgs, utils, ... }@inputs:
    utils.lib.eachDefaultSystem (
    system:
    let
    p = import nixpkgs { inherit system; };
    llvm = p.llvmPackages_latest;

    # simple script which replaces the functionality of make
    # it works with <math.h> and includes debugging symbols by default
    # it will be updated as per needs

    # arguments: outfile
    # basic usage example: mk main [flags]
    mymake = p.writeShellScriptBin "mk" ''
    if [ -f "$1.c" ]; then
    i="$1.c"
    else
    i="$1.cpp"
    fi
    o=$1
    shift
    $CC -ggdb $i -o $o -lm -Wall $@
    '';
    in
    {
    devShell = p.mkShell.override { stdenv = p.clangStdenv; } rec {
    nativeBuildInputs = [
    # builder
    p.gnumake
    p.bear
    # debugger
    llvm.lldb
    p.gdb
    # fix headers not found
    p.clang-tools
    # LSP and compiler
    llvm.clang
    # other tools
    llvm.libllvm
    p.valgrind
    mymake
    ];
    buildInputs = [
    # stdlib for cpp
    llvm.libcxx
    ];
    CPATH = nixpkgs.lib.makeSearchPathOutput "dev" "include" buildInputs;
    name = "C";
    };
    }
    );
    }