feat(templates): add cmake-c

This commit is contained in:
2026-03-21 13:48:30 +01:00
parent e2b91a9d30
commit 0b2e349268
6 changed files with 94 additions and 0 deletions

1
templates/cmake-c/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
build

View File

@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.15)
project(Hello
DESCRIPTION "Hello World"
LANGUAGES C
)
add_executable(hello src/main.c)
install(TARGETS hello)

View File

@@ -0,0 +1,56 @@
{
description = "Cmake C Flake";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
};
outputs = inputs @ {
self,
flake-parts,
...
}:
flake-parts.lib.mkFlake {inherit inputs;} (
top: {
imports = [];
flake = {
overlays.default = final: prev: {
my-derivation = final.callPackage ./nix/derivation.nix {};
};
};
systems = [
"x86_64-linux"
];
perSystem = {
self',
pkgs,
system,
...
}: {
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
overlays = [self.overlays.default];
};
packages.default = pkgs.my-derivation;
devShells.default = pkgs.mkShell {
packages = [
pkgs.cmake-language-server
pkgs.cmake-format
pkgs.clang-tools
pkgs.gdb
];
inputsFrom = [self'.packages.default];
shellHook = ''
export CMAKE_EXPORT_COMPILE_COMMANDS=ON
'';
};
};
}
);
}

View File

@@ -0,0 +1,17 @@
{
cmake,
stdenv,
...
}:
stdenv.mkDerivation (finalAttrs: {
pname = "my-derivation";
version = "0.1.0";
src = ../.;
nativeBuildInputs = [cmake];
buildInputs = [];
meta = {
description = "Hello World Binary";
mainProgram = "hello";
};
})

View File

@@ -0,0 +1,6 @@
#include <stdio.h>
int main() {
puts("Hello, Flake!");
return 0;
}