feat: C templates

This commit is contained in:
Kiana Sheibani 2026-01-19 14:10:56 -05:00
parent e5faf58ba8
commit f5427d28a9
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
15 changed files with 236 additions and 0 deletions

2
c/basic/nixpkgs/.envrc Normal file
View file

@ -0,0 +1,2 @@
#!/usr/bin/env bash
use flake

43
c/basic/nixpkgs/flake.lock generated Normal file
View file

@ -0,0 +1,43 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1768783163,
"narHash": "sha256-tLj4KcRDLakrlpvboTJDKsrp6z2XLwyQ4Zmo+w8KsY4=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "bde09022887110deb780067364a0818e89258968",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
"systems": "systems"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

23
c/basic/nixpkgs/flake.nix Normal file
View file

@ -0,0 +1,23 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
systems.url = "github:nix-systems/default";
};
outputs = { self, nixpkgs, systems, ... }:
let eachSystem = nixpkgs.lib.genAttrs (import systems);
in {
packages = eachSystem (system:
let pkgs = nixpkgs.legacyPackages.${system};
in {
hello = pkgs.callPackage ./package.nix {};
default = self.packages.${system}.hello;
});
devShells = eachSystem (system:
let pkgs = nixpkgs.legacyPackages.${system};
in {
default = import ./shell.nix { inherit pkgs; };
});
};
}

View file

@ -0,0 +1,23 @@
{
stdenv
}:
let
source = "src/hello.c";
exec = "hello";
in stdenv.mkDerivation {
pname = "hello";
version = "0.1";
src = ./.;
buildPhase = ''
runHook preBuild
gcc ${source} -o ${exec}.bin
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/bin
install ${exec}.bin $out/bin/${exec}
runHook postInstall
'';
}

View file

@ -0,0 +1,8 @@
{ pkgs ? import <nixpkgs> {} }:
let inherit (pkgs)
mkShell
llvmPackages_21
;
in mkShell {
packages = [ llvmPackages_21.clang-tools ];
}

View file

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