Skip to content

Commit 955572f

Browse files
committed
Add nix flakes to go repo template
Signed-off-by: Milos Gajdos <[email protected]>
1 parent 06b0132 commit 955572f

File tree

5 files changed

+165
-0
lines changed

5 files changed

+165
-0
lines changed

default.nix

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{ pkgs ? (
2+
let
3+
inherit (builtins) fetchTree fromJSON readFile;
4+
inherit ((fromJSON (readFile ./flake.lock)).nodes) nixpkgs gomod2nix;
5+
in
6+
import (fetchTree nixpkgs.locked) {
7+
overlays = [
8+
(import "${fetchTree gomod2nix.locked}/overlay.nix")
9+
];
10+
}
11+
)
12+
, buildGoApplication ? pkgs.buildGoApplication
13+
}:
14+
15+
buildGoApplication {
16+
pname = "go-app";
17+
version = "0.1";
18+
pwd = ./.;
19+
src = ./.;
20+
modules = ./gomod2nix.toml;
21+
doCheck = false;
22+
}

flake.lock

Lines changed: 85 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
description = "A basic gomod2nix flake";
3+
4+
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
5+
inputs.flake-utils.url = "github:numtide/flake-utils";
6+
inputs.gomod2nix.url = "github:nix-community/gomod2nix";
7+
inputs.gomod2nix.inputs.nixpkgs.follows = "nixpkgs";
8+
inputs.gomod2nix.inputs.flake-utils.follows = "flake-utils";
9+
10+
outputs = { self, nixpkgs, flake-utils, gomod2nix }:
11+
(flake-utils.lib.eachDefaultSystem
12+
(system:
13+
let
14+
pkgs = nixpkgs.legacyPackages.${system};
15+
16+
# The current default sdk for macOS fails to compile go projects, so we use a newer one for now.
17+
# This has no effect on other platforms.
18+
callPackage = pkgs.darwin.apple_sdk_11_0.callPackage or pkgs.callPackage;
19+
in
20+
{
21+
packages.default = callPackage ./. {
22+
inherit (gomod2nix.legacyPackages.${system}) buildGoApplication;
23+
};
24+
devShells.default = callPackage ./shell.nix {
25+
inherit (gomod2nix.legacyPackages.${system}) mkGoEnv gomod2nix;
26+
};
27+
})
28+
);
29+
}

gomod2nix.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
schema = 3
2+
3+
[mod]

shell.nix

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{ pkgs ? (
2+
let
3+
inherit (builtins) fetchTree fromJSON readFile;
4+
inherit ((fromJSON (readFile ./flake.lock)).nodes) nixpkgs gomod2nix;
5+
in
6+
import (fetchTree nixpkgs.locked) {
7+
overlays = [
8+
(import "${fetchTree gomod2nix.locked}/overlay.nix")
9+
];
10+
}
11+
)
12+
, mkGoEnv ? pkgs.mkGoEnv
13+
, gomod2nix ? pkgs.gomod2nix
14+
, golangci-lint ? pkgs.golangci-lint
15+
}:
16+
17+
let
18+
goEnv = mkGoEnv { pwd = ./.; };
19+
in
20+
pkgs.mkShell {
21+
packages = [
22+
goEnv
23+
gomod2nix
24+
golangci-lint
25+
];
26+
}

0 commit comments

Comments
 (0)