Skip to content

Latest commit

 

History

History

go-gomod2nix

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Nix Flake Template for Go using Gomod2nix

All of this information is also included in the README.md

Initialize using

nix flake init --template "github:nulladmin1/nix-flake-templates#go"

or

nix flake init --template "github:nulladmin1/nix-flake-templates#go-gomod2nix"

This is how the structure of the template looks like:

📦 go-gomod2nix
├─ 📁 src
│  └─ 🐹 hello.go
├─ 🙈 .gitignore
├─ 🔒 flake.lock
├─ ⚙️ flake.nix
├─ 🐹 go.mod
├─ ⚙️ gomod2nix.toml
├─ 📃 README.md

It includes a basic Go project that prints Hello World!

It contains a devShells with this projects goEnv and the gomod2nix tool, and an app that prints Hello World

Run using Nix

nix run

Go into Development Shell

nix develop

(Optional) Format flake.nix using Alejandra

nix fmt

To customize it to your own needs:

  • In flake.nix
    • Edit description
          {
              description = "Nix Flake Template for Go using GoMod2Nix";
          # ...
          }
    • Change project details in the default packages
              default = pkgs.${system}.buildGoApplication {
                  pname = "hello";
                  version = "0.1.0";
                  pwd = ./.;
                  src = ./.;
                  modules = ./gomod2nix.toml;
              };
  • 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
    • Generate new gomod2nix.toml by:
      • Going into development shell
              nix develop
      • Running the tool
              gomod2nix generate