feat: add cpp template

This commit is contained in:
Leon Schwarzäugl 2024-12-31 17:48:23 +01:00
parent 6da0fcbb1b
commit baeb65234b
Signed by: swarsel
GPG key ID: 26A54C31F2A4FD84
10 changed files with 94 additions and 86 deletions

View file

@ -487,6 +487,7 @@ This file defines the templates that are being exposed by the flake. These can b
"python"
"rust"
"go"
"cpp"
];
in
lib.swarselsystems.mkTemplates templateNames

1
templates/cpp/.envrc Normal file
View file

@ -0,0 +1 @@
use flake

12
templates/cpp/.gitignore vendored Normal file
View file

@ -0,0 +1,12 @@
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
CMakeUserPresets.json

View file

@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.20)
project(name)
set(CMAKE_CXX_STANDARD 23)
add_subdirectory(src)
install(TARGETS name DESTINATION bin)

62
templates/cpp/flake.nix Normal file
View file

@ -0,0 +1,62 @@
# heavily inspired by https://github.com/nulladmin1/nix-flake-templates/blob/main/cpp-cmake/flake.nix
{
description = "C++ Flake";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
systems.url = "github:nix-systems/default";
};
outputs =
{ self
, nixpkgs
, systems
, ...
}:
let
forEachSystem = nixpkgs.lib.genAttrs (import systems);
pkgsFor = forEachSystem (system: import nixpkgs { inherit system; });
pname = "name";
in
{
formatter = forEachSystem (system: pkgsFor.${system}.nixpgks-fmt);
devShells = forEachSystem (system: {
default = pkgsFor.${system}.mkShell {
packages = with pkgsFor.${system}; [
libllvm
cmake
gtest
cppcheck
valgrind
doxygen
clang-tools
# cudatoolkit
];
};
});
packages = forEachSystem (system: {
default = pkgsFor.${system}.stdenv.mkDerivation {
inherit pname;
version = "0.1.0";
src = ./.;
nativeBuildInputs = with pkgsFor.${system}; [
cmake
];
buildInputs = with pkgsFor.${system}; [
gtest
];
};
});
apps = forEachSystem (system: {
default = {
type = "app";
program = "${self.packages.${system}.default}/bin/${pname}";
};
});
};
}

View file

@ -0,0 +1 @@
add_executable(name name.cpp name.cpp)

View file

@ -0,0 +1,7 @@
#include <iostream>
using namespace std;
int main() {
cout << "Hello, world!" << endl;
return 0;
}

View file

@ -1,38 +0,0 @@
# flake.nix
{
description = "C/C++ environment";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = { nixpkgs, ... }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
llvm = pkgs.llvmPackages_latest;
in
{
devShells.${system}.default = pkgs.mkShell {
packages = with pkgs; [
gcc
#builder
cmake
gnumake
#headers
clang-tools
#lsp
llvm.libstdcxxClang
#tools
cppcheck
valgrind
doxygen
];
hardeningDisable = [ "all" ];
# direnv does not allow aliases, use scripts as a workaround
shellHook = ''
PATH_add ~/.dotfiles/scripts/devShell
'';
# ...
};
};
}

View file

@ -1,48 +0,0 @@
# flake.nix
{
description = "CUDA environment";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = { nixpkgs, ... }:
let
system = "x86_64-linux";
pkgs = import nixpkgs {
system = "x86_64-linux";
config.allowUnfree = true;
};
in
{
devShells.${system}.default = pkgs.mkShell {
packages = with pkgs; [
# gcc
#builder
# cmake
# gnumake
#headers
clang-tools
#lsp
# llvm.libstdcxxClang
# cudaPackages.cuda_nvcc
#tools
cppcheck
valgrind
doxygen
cudatoolkit
(pkgs.python3.withPackages (python-pkgs: [
python-pkgs.numpy
python-pkgs.pandas
python-pkgs.scipy
python-pkgs.matplotlib
python-pkgs.requests
python-pkgs.debugpy
python-pkgs.python-lsp-server
]))
];
hardeningDisable = [ "all" ];
# ...
};
};
}

View file

@ -4,6 +4,7 @@ let
"python"
"rust"
"go"
"cpp"
];
in
lib.swarselsystems.mkTemplates templateNames