diff --git a/SwarselSystems.org b/SwarselSystems.org index 10d7caa..4d429f4 100644 --- a/SwarselSystems.org +++ b/SwarselSystems.org @@ -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 diff --git a/templates/cpp/.envrc b/templates/cpp/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/templates/cpp/.envrc @@ -0,0 +1 @@ +use flake diff --git a/templates/cpp/.gitignore b/templates/cpp/.gitignore new file mode 100644 index 0000000..11c7643 --- /dev/null +++ b/templates/cpp/.gitignore @@ -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 diff --git a/templates/cpp/CMakeLists.txt b/templates/cpp/CMakeLists.txt new file mode 100644 index 0000000..538be9a --- /dev/null +++ b/templates/cpp/CMakeLists.txt @@ -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) diff --git a/templates/cpp/flake.nix b/templates/cpp/flake.nix new file mode 100644 index 0000000..8a662ab --- /dev/null +++ b/templates/cpp/flake.nix @@ -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}"; + }; + }); + }; +} diff --git a/templates/cpp/src/CMakeLists.txt b/templates/cpp/src/CMakeLists.txt new file mode 100644 index 0000000..841969c --- /dev/null +++ b/templates/cpp/src/CMakeLists.txt @@ -0,0 +1 @@ +add_executable(name name.cpp name.cpp) diff --git a/templates/cpp/src/name.cpp b/templates/cpp/src/name.cpp new file mode 100644 index 0000000..3fa18c5 --- /dev/null +++ b/templates/cpp/src/name.cpp @@ -0,0 +1,7 @@ +#include +using namespace std; + +int main() { + cout << "Hello, world!" << endl; + return 0; +} diff --git a/templates/cpp_flake.nix b/templates/cpp_flake.nix deleted file mode 100644 index d58b0d7..0000000 --- a/templates/cpp_flake.nix +++ /dev/null @@ -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 - ''; - # ... - }; - }; -} diff --git a/templates/cu_flake.nix b/templates/cu_flake.nix deleted file mode 100644 index 4a8c690..0000000 --- a/templates/cu_flake.nix +++ /dev/null @@ -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" ]; - # ... - }; - }; -} diff --git a/templates/default.nix b/templates/default.nix index 1eaff7b..a97ad93 100644 --- a/templates/default.nix +++ b/templates/default.nix @@ -4,6 +4,7 @@ let "python" "rust" "go" + "cpp" ]; in lib.swarselsystems.mkTemplates templateNames