-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
101 lines (91 loc) · 2.76 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
{
description = "My new awesome go app.";
nixConfig = {
substituters = [
"https://cache.nixos.org"
"https://nix-community.cachix.org"
];
trusted-public-keys = [
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
];
};
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
devshell = {
url = "github:numtide/devshell";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
pre-commit-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
inputs.flake-utils.follows = "flake-utils";
};
};
outputs = {
self,
devshell,
nixpkgs,
flake-utils,
pre-commit-hooks,
...
} @ inputs:
with (flake-utils.lib);
eachDefaultSystem
(system: let
pkgs = import nixpkgs {
inherit system;
overlays = [
devshell.overlay
];
};
inherit (pkgs) dockerTools buildGoModule;
inherit (pkgs.stdenv) isLinux;
inherit (pkgs.lib) lists fakeSha256 licenses platforms;
inherit (pkgs.devshell) mkShell;
linters = with pkgs; [
alejandra # https://github.com/kamadorueda/alejandra
gofumpt # https://github.com/mvdan/gofumpt
nodePackages.prettier # https://prettier.io/
treefmt # https://github.com/numtide/treefmt
];
# devshell command categories
pkgWithCategory = category: package: {inherit package category;};
linter = pkgWithCategory "linters";
formatter = pkgWithCategory "formatters";
util = pkgWithCategory "utils";
in {
# nix develop
devShells.default = mkShell {
packages = with pkgs;
[
gcc
delve # https://github.com/go-delve/delve
go_1_19 # https://go.dev/
gotools # https://go.googlesource.com/tools
]
++ linters;
commands = with pkgs; [
(formatter alejandra)
(formatter gofumpt)
(formatter nodePackages.prettier)
(linter golangci-lint)
(util just)
];
};
# nix flake check
checks = {
format =
pkgs.runCommandNoCC "treefmt" {
nativeBuildInputs = linters;
} ''
# keep timestamps so that treefmt is able to detect mtime changes
cp --no-preserve=mode --preserve=timestamps -r ${self} source
cd source
HOME=$TMPDIR treefmt --fail-on-change
touch $out
'';
};
});
}