tags:
- ready
- online
- golang
- nixos
- flake
- tutorial
- setup
- go
- nix
golang-nixos-with-flake
Contents
- [ tutorial ] (https://haseebmajid.dev/posts/2023-10-26-how-to-setup-a-go-development-shell-with-nix-flakes/)
Setup a non existing project from scratch in nixos
Init the project
-
Add
main.gofile with the following content:
package main
import (
"fmt"
)
func main() {
fmt.Println("hello")
}
-
Add a initial
shell.nixfile with the following content:
# shell.nix
let
# We pin to a specific nixpkgs commit for reproducibility.
# Check for new commits at https://status.nixos.org.
pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/d04953086551086b44b6f3c6b7eeb26294f207da.tar.gz") {};
in pkgs.mkShell {
packages = [
# select Go packages here
pkgs.go_1_23 # desired version
];
}
-
Configure environment to use nix, create
.envrcfile with the following content:
use nix- Start go mod init
go mod init <project>
- Add module requirements and sums
go mod tidy
-
Delete the
shell.nixfile
Follow the tutorial
- Follow the tutorial on haseebmajid.dev