diff options
Diffstat (limited to 'templates/go/flake.nix')
-rw-r--r-- | templates/go/flake.nix | 83 |
1 files changed, 83 insertions, 0 deletions
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}; + }; + }; +} |