From d6971f6d7a03142ea6e391d7c37532b3aa4792e7 Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Tue, 21 Feb 2023 12:55:28 -0800 Subject: feat(templates/go): add flake template for go projects --- templates/default.nix | 5 +++ templates/go/.drone.yml | 32 +++++++++++++++++++ templates/go/.envrc | 1 + templates/go/LICENSE | 20 ++++++++++++ templates/go/README.md | 0 templates/go/flake.nix | 83 +++++++++++++++++++++++++++++++++++++++++++++++++ templates/go/go.mod | 3 ++ templates/go/main.go | 7 +++++ 8 files changed, 151 insertions(+) create mode 100644 templates/go/.drone.yml create mode 100644 templates/go/.envrc create mode 100644 templates/go/LICENSE create mode 100644 templates/go/README.md create mode 100644 templates/go/flake.nix create mode 100644 templates/go/go.mod create mode 100644 templates/go/main.go (limited to 'templates') diff --git a/templates/default.nix b/templates/default.nix index 38c4877..1307ad7 100644 --- a/templates/default.nix +++ b/templates/default.nix @@ -3,4 +3,9 @@ description = "Simple rust package"; path = ./rust; }; + + go = { + description = "go template"; + path = ./go; + }; } 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 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!") +} -- cgit 1.4.1