feat: add go template

This commit is contained in:
Leon Schwarzäugl 2024-12-31 17:34:37 +01:00
parent f4f98b248d
commit 6da0fcbb1b
Signed by: swarsel
GPG key ID: 26A54C31F2A4FD84
9 changed files with 75 additions and 3 deletions

1
templates/go/.envrc Normal file
View file

@ -0,0 +1 @@
use flake

52
templates/go/flake.nix Normal file
View file

@ -0,0 +1,52 @@
# heavily inspired by https://github.com/nulladmin1/nix-flake-templates/blob/main/go-nix/flake.nix
{
description = "Go 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}.nixpkgs-fmt);
devShells = forEachSystem (system: {
default = pkgsFor.${system}.mkShell {
packages = with pkgsFor.${system}; [
go
gopls
go-tools
gotools
];
};
});
packages = forEachSystem (system: {
default = pkgsFor.${system}.buildGoModule {
inherit pname;
version = "0.1.0";
src = ./.;
vendorHash = null;
};
});
apps = forEachSystem (system: {
default = {
type = "app";
program = "${self.packages.${system}.default}/bin/${pname}";
};
});
};
}

3
templates/go/go.mod Normal file
View file

@ -0,0 +1,3 @@
module name
go 1.22.7

View file

@ -0,0 +1,9 @@
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello, World!")
}