forked from tomnomnom/gron
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflake.nix
134 lines (128 loc) · 4.11 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
{
description = "Nix package, app, and devShell for gron";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
flake-parts.url = "github:hercules-ci/flake-parts";
flake-root.url = "github:srid/flake-root";
gomod2nix.url = "github:nix-community/gomod2nix";
pre-commit-hooks-nix = {
url = "github:cachix/pre-commit-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
inputs.flake-root.flakeModule
inputs.pre-commit-hooks-nix.flakeModule
inputs.treefmt-nix.flakeModule
];
systems = [
"x86_64-linux"
"aarch64-darwin"
];
perSystem =
{
config,
self',
inputs',
system,
...
}:
let
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [
inputs.gomod2nix.overlays.default
(final: prev: { })
];
config = { };
};
version = inputs.self.shortRev or "development";
gron = pkgs.buildGoApplication {
inherit version;
pname = "gron";
src = ./.;
ldflags = [ "-X github.com/lafrenierejm/gron/cmd.Version=${version}" ];
modules = ./gomod2nix.toml;
meta = with pkgs.lib; {
description = "Transform JSON or YAML into discrete assignments to make it easier to `grep` for what you want and see the absolute 'path' to it";
homepage = "https://github.com/lafrenierejm/gron";
license = licenses.mit;
maintainers = with maintainers; [ lafrenierejm ];
};
};
in
{
# Per-system attributes can be defined here. The self' and inputs'
# module parameters provide easy access to attributes of the same
# system.
packages = {
inherit gron;
default = gron;
gronWithFallback = pkgs.writeShellApplication {
name = "gron-with-fallback";
runtimeInputs = [ gron ];
text = builtins.readFile ./gron-with-fallback.sh;
};
};
apps.default = gron;
# Auto formatters. This also adds a flake check to ensure that the
# source tree was auto formatted.
treefmt.config = {
projectRootFile = ".git/config";
flakeCheck = false; # use pre-commit's check instead
programs = {
gofumpt.enable = true;
nixfmt.enable = true;
prettier.enable = true;
};
settings.formatter = {
prettier = {
excludes = [
"README.md"
"internal/gron/testdata/large-line.json"
"internal/gron/testdata/long-stream.json"
"internal/gron/testdata/scalar-stream.json"
"internal/gron/testdata/stream.json"
];
};
};
};
pre-commit = {
check.enable = true;
settings.hooks = {
editorconfig-checker.enable = true;
markdownlint.enable = true;
treefmt.enable = true;
typos = {
enable = true;
excludes = [
"ADVANCED.mkd"
"internal/gron/testdata/.*"
"internal/gron/ungron_test.go"
];
};
};
};
devShells.default = pkgs.mkShell {
inherit (config.pre-commit.devShell) shellHook nativeBuildInputs;
# inputsFrom = builtins.attrValues config.pre-commit.devShell;
packages = with pkgs; [
(mkGoEnv { pwd = ./.; })
cobra-cli
go-tools
godef
gomod2nix
gopls
gotools
];
};
};
};
}