From 7ae6c99f31f27958842a61a90aaede6923298eb1 Mon Sep 17 00:00:00 2001 From: Spencer Brower <6729162+sbrow@users.noreply.github.com> Date: Mon, 23 Feb 2026 12:33:12 -0500 Subject: [PATCH] feat: Added `go` template. --- flake.nix | 4 ++ templates/go/.envrc | 1 + templates/go/.gitignore | 3 ++ templates/go/Caddyfile | 11 ++++ templates/go/flake.lock | 113 ++++++++++++++++++++++++++++++++++++++++ templates/go/flake.nix | 97 ++++++++++++++++++++++++++++++++++ 6 files changed, 229 insertions(+) create mode 100644 templates/go/.envrc create mode 100644 templates/go/.gitignore create mode 100644 templates/go/Caddyfile create mode 100644 templates/go/flake.lock create mode 100644 templates/go/flake.nix diff --git a/flake.nix b/flake.nix index b81602c..9dfa51e 100644 --- a/flake.nix +++ b/flake.nix @@ -14,6 +14,10 @@ path = ./templates/default; description = "A simple boilerplate for running Laravel with nix run."; }; + go = { + path = ./templates/go; + description = "A simple boilerplate for building Go apps."; + }; nodejs = { path = ./templates/nodejs; description = diff --git a/templates/go/.envrc b/templates/go/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/templates/go/.envrc @@ -0,0 +1 @@ +use flake diff --git a/templates/go/.gitignore b/templates/go/.gitignore new file mode 100644 index 0000000..4a8461c --- /dev/null +++ b/templates/go/.gitignore @@ -0,0 +1,3 @@ +.direnv +node_modules +vendor diff --git a/templates/go/Caddyfile b/templates/go/Caddyfile new file mode 100644 index 0000000..22ebb16 --- /dev/null +++ b/templates/go/Caddyfile @@ -0,0 +1,11 @@ +go.localhost { + encode zstd gzip + + # root * . + # file_server + + reverse_proxy :8888 + + tls internal +} + diff --git a/templates/go/flake.lock b/templates/go/flake.lock new file mode 100644 index 0000000..d8707ee --- /dev/null +++ b/templates/go/flake.lock @@ -0,0 +1,113 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1751413152, + "narHash": "sha256-Tyw1RjYEsp5scoigs1384gIg6e0GoBVjms4aXFfRssQ=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "77826244401ea9de6e3bac47c2db46005e1f30b5", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1751949589, + "narHash": "sha256-mgFxAPLWw0Kq+C8P3dRrZrOYEQXOtKuYVlo9xvPntt8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9b008d60392981ad674e04016d25619281550a9d", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1751159883, + "narHash": "sha256-urW/Ylk9FIfvXfliA1ywh75yszAbiTEVgpPeinFyVZo=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "14a40a1d7fb9afa4739275ac642ed7301a9ba1ab", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "nixpkgs-unstable": { + "locked": { + "lastModified": 1751949589, + "narHash": "sha256-mgFxAPLWw0Kq+C8P3dRrZrOYEQXOtKuYVlo9xvPntt8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9b008d60392981ad674e04016d25619281550a9d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "process-compose-flake": { + "locked": { + "lastModified": 1749418557, + "narHash": "sha256-wJHHckWz4Gvj8HXtM5WVJzSKXAEPvskQANVoRiu2w1w=", + "owner": "Platonic-Systems", + "repo": "process-compose-flake", + "rev": "91dcc48a6298e47e2441ec76df711f4e38eab94e", + "type": "github" + }, + "original": { + "owner": "Platonic-Systems", + "repo": "process-compose-flake", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs", + "nixpkgs-unstable": "nixpkgs-unstable", + "process-compose-flake": "process-compose-flake", + "treefmt-nix": "treefmt-nix" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1752055615, + "narHash": "sha256-19m7P4O/Aw/6+CzncWMAJu89JaKeMh3aMle1CNQSIwM=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "c9d477b5d5bd7f26adddd3f96cfd6a904768d4f9", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/templates/go/flake.nix b/templates/go/flake.nix new file mode 100644 index 0000000..5404f63 --- /dev/null +++ b/templates/go/flake.nix @@ -0,0 +1,97 @@ +{ + description = "A dev environment"; + + inputs = { + # nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05"; + nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + + flake-parts.url = "github:hercules-ci/flake-parts"; + process-compose-flake.url = "github:Platonic-Systems/process-compose-flake"; + treefmt-nix.url = "github:numtide/treefmt-nix"; + treefmt-nix.inputs.nixpkgs.follows = "nixpkgs"; + }; + + outputs = + inputs@{ self + , flake-parts + , nixpkgs + , nixpkgs-unstable + , process-compose-flake + , treefmt-nix + }: + flake-parts.lib.mkFlake { inherit inputs; } { + imports = [ + inputs.treefmt-nix.flakeModule + inputs.process-compose-flake.flakeModule + ]; + systems = [ "x86_64-linux" ]; + + perSystem = + { pkgs, system, inputs', ... }: { + _module.args.pkgs = import nixpkgs { + inherit system; + config.allowUnfree = true; + + overlays = [ + (final: prev: { unstable = inputs'.nixpkgs-unstable.legacyPackages; }) + ]; + }; + + treefmt = { + # Used to find the project root + projectRootFile = "flake.nix"; + settings.global.excludes = [ + ".direnv/**" + ".jj/**" + ".env" + ".envrc" + ".env.local" + ]; + + + # Format nix files + programs.nixpkgs-fmt.enable = true; + programs.deadnix.enable = true; + + # Format js, json, and yaml files + programs.prettier.enable = true; + settings.formatter.prettier = + { + excludes = [ + "public/**" + "resources/js/modernizr.js" + "storage/app/caniuse.json" + "*.md" + ]; + }; + }; + + process-compose.default.settings.processes = { + mail.command = "${pkgs.mailhog}/bin/MailHog"; + web.command = "${pkgs.air}/bin/air --"; + }; + + devShells.default = pkgs.mkShell + { + buildInputs = with pkgs; [ + go + # Extra Packages go here. + + # tools + air + tailwindcss_4 + goose + + # IDE + gopls + gotools + golangci-lint + + unstable.helix + typescript-language-server + vscode-langservers-extracted + ]; + }; + }; + }; +}