aboutsummaryrefslogtreecommitdiff
path: root/templates/go
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2023-02-21 12:55:28 -0800
committerFranck Cuny <franck@fcuny.net>2023-02-21 12:59:13 -0800
commitd6971f6d7a03142ea6e391d7c37532b3aa4792e7 (patch)
treef60d9d3fcdd37075bc81b9a1116afa7ce74d286d /templates/go
parentfeat(home/fish): move fish's code to external files (diff)
downloadinfra-d6971f6d7a03142ea6e391d7c37532b3aa4792e7.tar.gz
feat(templates/go): add flake template for go projects
Diffstat (limited to 'templates/go')
-rw-r--r--templates/go/.drone.yml32
-rw-r--r--templates/go/.envrc1
-rw-r--r--templates/go/LICENSE20
-rw-r--r--templates/go/README.md0
-rw-r--r--templates/go/flake.nix83
-rw-r--r--templates/go/go.mod3
-rw-r--r--templates/go/main.go7
7 files changed, 146 insertions, 0 deletions
diff --git a/templates/go/.drone.yml b/templates/go/.drone.yml
new file mode 100644
index 0000000..13b4026
--- /dev/null
+++ b/templates/go/.drone.yml
@@ -0,0 +1,32 @@
+---
+kind: pipeline
+type: docker
+name: checks
+
+trigger:
+ event:
+ - push
+ - pull_request
+
+steps:
+ - name: Run checks
+ image: nixpkgs/nix-flakes:nixos-22.11
+ commands:
+ - nix develop --command pre-commit run --verbose --hook-stage commit --all-files --show-diff-on-failure
+
+---
+kind: pipeline
+type: docker
+name: build
+
+trigger:
+ event:
+ - push
+ - pull_request
+
+steps:
+ - name: Run tests and build
+ image: nixpkgs/nix-flakes:nixos-22.11
+ commands:
+ - nix develop --command go test -race ./...
+ - nix build
diff --git a/templates/go/.envrc b/templates/go/.envrc
new file mode 100644
index 0000000..a5dbbcb
--- /dev/null
+++ b/templates/go/.envrc
@@ -0,0 +1 @@
+use flake .
diff --git a/templates/go/LICENSE b/templates/go/LICENSE
new file mode 100644
index 0000000..c27fed0
--- /dev/null
+++ b/templates/go/LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) Franck Cuny
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/templates/go/README.md b/templates/go/README.md
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/templates/go/README.md
diff --git a/templates/go/flake.nix b/templates/go/flake.nix
new file mode 100644
index 0000000..9038975
--- /dev/null
+++ b/templates/go/flake.nix
@@ -0,0 +1,83 @@
+{
+ description = "Go project template";
+
+ inputs = {
+ futils.url = "github:numtide/flake-utils";
+ nixpkgs.url = "github:NixOS/nixpkgs";
+ pre-commit-hooks = {
+ url = "github:cachix/pre-commit-hooks.nix";
+ inputs = {
+ flake-utils.follows = "futils";
+ nixpkgs.follows = "nixpkgs";
+ };
+ };
+ };
+
+ outputs =
+ { self
+ , futils
+ , nixpkgs
+ , pre-commit-hooks
+ }:
+ futils.lib.eachDefaultSystem
+ (system:
+ let
+ pkgs = import nixpkgs {
+ inherit system;
+ };
+ pname = "project-name";
+ version = "0.0.1";
+ tools = with pkgs; [
+ # https://github.com/golang/vscode-go/blob/master/docs/tools.md
+ delve
+ golangci-lint
+ gopls
+ ];
+ in
+ rec {
+ # `nix build`
+ packages."${pname}" = pkgs.buildGoModule {
+ inherit pname version;
+ src = ./.;
+ vendorSha256 = null;
+ };
+ defaultPackage = packages."${pname}";
+
+ # `nix run`
+ apps = {
+ "${pname}" = futils.lib.mkApp {
+ drv = packages."${pname}";
+ exePath = "/bin/changeme";
+ };
+ default = apps."${pname}";
+ };
+
+ # `nix develop`
+ checks = {
+ pre-commit = pre-commit-hooks.lib.${system}.run {
+ src = ./.;
+ hooks = {
+ nixpkgs-fmt.enable = true;
+ yamllint.enable = true;
+ govet.enable = true;
+ gotest.enable = true;
+ gofmt.enable = true;
+ staticcheck.enable = true;
+ };
+ settings = {
+ yamllint.relaxed = true;
+ };
+ };
+ };
+
+ devShell = pkgs.mkShell {
+ buildInputs = with pkgs; [ go ] ++ tools;
+ inherit (self.checks.${system}.pre-commit) shellHook;
+ };
+ })
+ // {
+ overlay = final: prev: {
+ XXX = self.defaultPackage.${prev.system};
+ };
+ };
+}
diff --git a/templates/go/go.mod b/templates/go/go.mod
new file mode 100644
index 0000000..736d11c
--- /dev/null
+++ b/templates/go/go.mod
@@ -0,0 +1,3 @@
+module go.fcuny.net/changeme
+
+go 1.18
diff --git a/templates/go/main.go b/templates/go/main.go
new file mode 100644
index 0000000..7776ec8
--- /dev/null
+++ b/templates/go/main.go
@@ -0,0 +1,7 @@
+package main
+
+import "fmt"
+
+func main() {
+ fmt.Println("hello world!")
+}