Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
107 lines (102 loc) · 3.17 KB
/
Copy pathflake.nix
File metadata and controls
107 lines (102 loc) · 3.17 KB
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
102
103
104
105
106
107
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
devshell = {
url = "github:numtide/devshell";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
inputs.devshell.flakeModule
inputs.treefmt-nix.flakeModule
];
systems = [
"x86_64-linux"
"aarch64-linux"
];
perSystem =
{ config, pkgs, ... }:
let
go = pkgs.callPackage ./nix/go.nix { };
nixfmt = pkgs.callPackage ./nix/tools/nixfmt.nix { };
statix = pkgs.callPackage ./nix/tools/statix.nix { };
deadnix = pkgs.callPackage ./nix/tools/deadnix.nix { };
# The golangci-lint go.mod pins, so its gofumpt and golines are the
# ones `task lint` checks with; nixpkgs' build would be another version.
golangciFmt = pkgs.writeShellApplication {
name = "golangci-lint-fmt";
runtimeInputs = [ go ];
text = ''
export GOWORK=off GOTOOLCHAIN=local CGO_ENABLED=0
exec "$(go tool -n golangci-lint)" fmt "$@"
'';
};
in
{
# `nix fmt`, `treefmt` in the devshell and `task fmt`.
treefmt = {
projectRootFile = "flake.nix";
# The Go formatter builds golangci-lint from the module cache, which
# the sandbox of a flake check cannot reach; CI runs `nix fmt -- --ci`.
flakeCheck = false;
programs.nixfmt = {
enable = true;
package = nixfmt;
};
settings.formatter.golangci-lint = {
command = "${golangciFmt}/bin/golangci-lint-fmt";
includes = [ "*.go" ];
};
};
checks.nix-lint =
pkgs.runCommandLocal "check-nix-lint"
{
nativeBuildInputs = [
statix
deadnix
];
}
''
cd ${./.}
statix check .
deadnix --fail .
touch $out
'';
devshells.default = {
env = [
{
name = "CGO_ENABLED";
value = 0;
}
# The default, `auto`, downloads whatever toolchain go.mod asks
# for and would hide a mismatch with nix/go.nix.
{
name = "GOTOOLCHAIN";
value = "local";
}
];
packages = with pkgs; [
# The let-bound pin from nix/go.nix, not `pkgs.go`.
go
gopls
go-task
nixfmt
statix
deadnix
config.treefmt.build.wrapper
jq
# headless: the end-to-end suite drives ffmpeg and ffprobe.
ffmpeg-headless
];
};
};
};
}