feat(c): init c template

This commit is contained in:
Artur Manuel 2025-02-06 23:35:40 +00:00
commit 01bc222af3
7 changed files with 108 additions and 0 deletions

3
.gitignore vendored
View file

@ -4,3 +4,6 @@
**/result-*
**/.direnv
**/dist
**/*.*~
**/.\#*
**/\#*\#

27
templates/c/flake.lock generated Normal file
View file

@ -0,0 +1,27 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1738680400,
"narHash": "sha256-ooLh+XW8jfa+91F1nhf9OF7qhuA/y1ChLx6lXDNeY5U=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "799ba5bffed04ced7067a91798353d360788b30d",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

28
templates/c/flake.nix Normal file
View file

@ -0,0 +1,28 @@
{
description = "REPLACE_DESC";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = {
self,
nixpkgs,
}: let
inherit (nixpkgs) lib;
forAllSystems = f:
lib.genAttrs ["x86_64-linux" "aarch64-linux"] (system:
f {
pkgs = import nixpkgs {
inherit system;
};
});
in {
packages = forAllSystems ({pkgs}: {
default = pkgs.callPackage ./flake/default.nix {};
REPLACE_ME = self.packages.${pkgs.system}.default;
});
formatter = forAllSystems ({pkgs}: pkgs.callPackage ./flake/formatter.nix {});
};
}

View file

@ -0,0 +1,25 @@
{
stdenv,
lib,
meson,
ninja,
}:
stdenv.mkDerivation {
pname = "REPLACE_ME";
version = "1";
src = lib.cleanSourceWith {
src = ../.;
filter = path: _type: baseNameOf path != ".git";
};
nativeBuildInputs = [
meson
ninja
];
installPhase = ''
mkdir -p $out/bin
mv timesave $out/bin
'';
}

View file

@ -0,0 +1,20 @@
{
writeShellApplication,
alejandra,
llvmPackages_19,
fd,
}:
writeShellApplication {
name = "formatter";
runtimeInputs = [
alejandra
llvmPackages_19.clang-tools
fd
];
text = ''
fd --extension nix -X alejandra -- {}
fd --extension nix -X deadnix -e -- {}
fd --extension nix -x statix fix -- {}
fd --extension c -X clang-format --verbose -i -- {}
'';
}

3
templates/c/main.c Normal file
View file

@ -0,0 +1,3 @@
#include <stdio.h>
int main(void) { printf("Hello, world!\n"); }

2
templates/c/meson.build Normal file
View file

@ -0,0 +1,2 @@
project('REPLACE_ME', 'c')
executable('REPLACE_ME', 'main.c')