From 01bc222af322a2534b9047f3113fce98e8d96adb Mon Sep 17 00:00:00 2001 From: Artur Manuel Date: Thu, 6 Feb 2025 23:35:40 +0000 Subject: [PATCH] feat(c): init c template --- .gitignore | 3 +++ templates/c/flake.lock | 27 +++++++++++++++++++++++++++ templates/c/flake.nix | 28 ++++++++++++++++++++++++++++ templates/c/flake/default.nix | 25 +++++++++++++++++++++++++ templates/c/flake/formatter.nix | 20 ++++++++++++++++++++ templates/c/main.c | 3 +++ templates/c/meson.build | 2 ++ 7 files changed, 108 insertions(+) create mode 100644 templates/c/flake.lock create mode 100644 templates/c/flake.nix create mode 100644 templates/c/flake/default.nix create mode 100644 templates/c/flake/formatter.nix create mode 100644 templates/c/main.c create mode 100644 templates/c/meson.build diff --git a/.gitignore b/.gitignore index 0b1da5b..550798e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ **/result-* **/.direnv **/dist +**/*.*~ +**/.\#* +**/\#*\# \ No newline at end of file diff --git a/templates/c/flake.lock b/templates/c/flake.lock new file mode 100644 index 0000000..7e36e53 --- /dev/null +++ b/templates/c/flake.lock @@ -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 +} diff --git a/templates/c/flake.nix b/templates/c/flake.nix new file mode 100644 index 0000000..c8044b1 --- /dev/null +++ b/templates/c/flake.nix @@ -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 {}); + }; +} diff --git a/templates/c/flake/default.nix b/templates/c/flake/default.nix new file mode 100644 index 0000000..59a80a3 --- /dev/null +++ b/templates/c/flake/default.nix @@ -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 + ''; +} diff --git a/templates/c/flake/formatter.nix b/templates/c/flake/formatter.nix new file mode 100644 index 0000000..02b734f --- /dev/null +++ b/templates/c/flake/formatter.nix @@ -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 -- {} + ''; +} diff --git a/templates/c/main.c b/templates/c/main.c new file mode 100644 index 0000000..f1b76e5 --- /dev/null +++ b/templates/c/main.c @@ -0,0 +1,3 @@ +#include + +int main(void) { printf("Hello, world!\n"); } diff --git a/templates/c/meson.build b/templates/c/meson.build new file mode 100644 index 0000000..6f516d8 --- /dev/null +++ b/templates/c/meson.build @@ -0,0 +1,2 @@ +project('REPLACE_ME', 'c') +executable('REPLACE_ME', 'main.c') \ No newline at end of file