-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
177 lines (161 loc) · 5.59 KB
/
Copy pathflake.nix
File metadata and controls
177 lines (161 loc) · 5.59 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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
{
description = "Scatterer Herdr plugin";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
lefthook-nix = {
url = "github:sudosubin/lefthook.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
treefmt-nix,
lefthook-nix,
...
}:
let
systems = [
"aarch64-darwin"
"x86_64-darwin"
"aarch64-linux"
"x86_64-linux"
];
forAllSystems =
function:
nixpkgs.lib.genAttrs systems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
# One formatter config shared by `nix fmt`, the pre-commit hook,
# and `nix flake check`.
treefmtEval = treefmt-nix.lib.evalModule pkgs {
projectRootFile = "flake.nix";
programs.rustfmt.enable = true;
programs.nixfmt.enable = true;
programs.taplo.enable = true;
programs.shfmt.enable = true;
};
treefmt = treefmtEval.config.build.wrapper;
# Git hooks are generated from this config and installed by the
# devshell's shellHook (via direnv, entering the repo is enough).
lefthook = lefthook-nix.lib.${system}.run {
src = self;
config = {
pre-commit.commands.treefmt = {
# --fail-on-change blocks the commit; fixed files are left
# in the working tree to stage and retry.
run = "${pkgs.lib.getExe treefmt} --fail-on-change --no-cache {staged_files}";
};
};
};
in
function {
inherit
pkgs
system
treefmtEval
treefmt
lefthook
;
}
);
in
{
packages = forAllSystems (
{ pkgs, ... }:
let
inherit (pkgs) lib;
scatterer = pkgs.rustPlatform.buildRustPackage {
pname = "scatterer";
version = (lib.importTOML ./Cargo.toml).package.version;
src = self;
cargoLock.lockFile = ./Cargo.lock;
buildInputs = lib.optionals pkgs.stdenv.isDarwin [ pkgs.libiconv ];
# The git module's tests exercise real `git init/commit` in temp dirs.
nativeCheckInputs = [ pkgs.git ];
meta = {
description = "Daniel's Herdr workflow/layout plugin";
homepage = "https://github.com/RestartDK/scatterer";
mainProgram = "scatterer";
};
};
# The checked-in manifest targets a development checkout: actions run
# `bash scripts/scatterer.sh …`, which rebuilds stale binaries via
# cargo. None of that applies to an immutable store path, so the
# plugin package rewrites the manifest as data: every command invokes
# the built binary directly and the cargo build hook is dropped.
manifest = lib.importTOML ./herdr-plugin.toml;
storeCommand = command: [ (lib.getExe scatterer) ] ++ lib.drop 2 command;
storeManifest = (pkgs.formats.toml { }).generate "herdr-plugin.toml" (
builtins.removeAttrs manifest [ "build" ]
// {
actions = map (action: action // { command = storeCommand action.command; }) manifest.actions;
panes = map (pane: pane // { command = storeCommand pane.command; }) manifest.panes;
}
);
plugin = pkgs.runCommand "scatterer-herdr-plugin-${manifest.version}" { } ''
mkdir -p $out/bin $out/share/herdr/plugins/scatterer
ln -s ${lib.getExe scatterer} $out/bin/scatterer
ln -s ${storeManifest} $out/share/herdr/plugins/scatterer/herdr-plugin.toml
'';
in
{
inherit scatterer plugin;
default = scatterer;
}
);
formatter = forAllSystems ({ treefmt, ... }: treefmt);
checks = forAllSystems (
{ system, treefmtEval, ... }:
{
build = self.packages.${system}.default;
plugin = self.packages.${system}.plugin;
# Same treefmt config as `nix fmt` and the pre-commit hook, run
# against a writable copy of the tree.
formatting = treefmtEval.config.build.check self;
}
);
devShells = forAllSystems (
{
pkgs,
treefmt,
lefthook,
...
}:
{
default = pkgs.mkShell {
# Installs the generated git hooks on shell entry.
inherit (lefthook) shellHook;
packages =
with pkgs;
[
cargo
clippy
pkg-config
rustc
rustfmt
treefmt
]
++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
libiconv
];
# Run hooks with TERM=dumb: lefthook's TUI library probes the
# terminal with OSC escape sequences, which garbles modern
# terminal emulators when git fires the hook. Scoped to the hook
# invocation only; interactive `lefthook` keeps normal output.
LEFTHOOK_BIN = toString (
pkgs.writeShellScript "lefthook-dumb-term" ''
exec env TERM=dumb ${pkgs.lib.getExe pkgs.lefthook} "$@"
''
);
};
}
);
};
}