All of this information is also included in the README.md
Initialize using
nix flake init --template "github:nulladmin1/nix-flake-templates#go-nix"
This is how the structure of the template looks like:
📦 go-gomod2nix
├─ 📁 src
│ └─ 🐹 hello.go
├─ 🔒 flake.lock
├─ ⚙️ flake.nix
├─ 🐹 go.mod
└─ 📃 README.md
It includes a basic Go project that prints Hello World!
It contains a devShell
with go
, and an app that prints Hello World
nix run
nix develop
(Optional) Format flake.nix
using Alejandra
nix fmt
-
In
flake.nix
- Edit description
{ description = "Nix Flake Template for Go with builtin Nix Builders"; # ... }
- Change project details in the default packages.
default = pkgsFor.${system}.buildGoModule { pname = "hello"; version = "0.1.0"; src = ./.; # ... };
- Change the hash after finishing a published change
default = pkgsFor.${system}.buildGoModule { #... vendorHash = null; };
-
In
go.mod
- Change modules and Go version
module hello go 1.22.7
-
For structure and code
- Add necessary code for the program in the src/ directory. Reflect changes in
go.mod
- Be sure to change the
vendorHash
(like previously stated)
- Add necessary code for the program in the src/ directory. Reflect changes in