-
-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathflake.nix
More file actions
297 lines (283 loc) · 9.35 KB
/
Copy pathflake.nix
File metadata and controls
297 lines (283 loc) · 9.35 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
{
description = "Ratty: a GPU-rendered terminal emulator with inline 3D graphics";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
crane.url = "github:ipetkov/crane";
};
outputs =
{
self,
nixpkgs,
crane,
}:
let
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forEachSystem = nixpkgs.lib.genAttrs supportedSystems;
# Shared module options — used by both HM and NixOS modules
rattyOptions =
{
config,
lib,
pkgs,
...
}:
let
cfg = config.programs.ratty;
tomlFormat = pkgs.formats.toml { };
in
{
options.programs.ratty = {
enable = lib.mkEnableOption "Ratty, a GPU-rendered terminal emulator";
package = lib.mkOption {
type = lib.types.package;
default = pkgs.ratty;
defaultText = lib.literalExpression "pkgs.ratty";
description = "The ratty package to install.";
};
settings = lib.mkOption {
type = tomlFormat.type;
default = { };
description = "Ratty configuration (ratty.toml).";
example = lib.literalExpression ''
{
window = {
opacity = 0.8;
};
shell = {
program = "bash";
};
}
'';
};
gpuBackend = lib.mkOption {
type = lib.types.nullOr (
lib.types.enum (
if pkgs.stdenv.isDarwin then
[
"metal"
"gl"
"gles"
]
else
[
"vulkan"
"gl"
"gles"
]
)
);
default = null;
description = ''
Force the wgpu backend.
Set to null (default) for auto-detection.
Useful when the Vulkan ICD loader selects an incompatible driver
or when running in headless/VNC environments where OpenGL is preferred.
'';
example = "vulkan";
};
gpuAdapter = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = ''
Substring match to select a specific GPU adapter name.
Set to null (default) to use the system default.
Useful on multi-GPU systems (e.g. integrated + discrete)
or when wgpu picks the wrong adapter.
'';
example = "RTX 3060";
};
defaultShell = lib.mkOption {
type = lib.types.nullOr lib.types.package;
default = null;
description = ''
Default shell to use when no -e/--command flag is passed.
Set to null to use the package's built-in default (bash).
'';
example = lib.literalExpression "pkgs.zsh";
};
};
};
in
{
packages = forEachSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
craneLib = crane.mkLib pkgs;
in
{
ratty = pkgs.callPackage ./nix/default.nix {
inherit craneLib;
# Pass Darwin frameworks when on Darwin
darwinFrameworks = pkgs.lib.optionals pkgs.stdenv.isDarwin (
with pkgs.darwin.apple_sdk.frameworks;
[
Cocoa
CoreFoundation
CoreGraphics
CoreText
CoreVideo
Metal
QuartzCore
]
);
};
default = self.packages.${system}.ratty;
}
);
devShells = forEachSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
default = pkgs.mkShell {
inputsFrom = [ self.packages.${system}.default ];
packages = with pkgs; [
rust-analyzer
cargo
clippy
rustfmt
];
};
}
);
formatter = forEachSystem (system: nixpkgs.legacyPackages.${system}.nixfmt-rfc-style);
# Overlay — adds pkgs.ratty for use with the NixOS/HM modules.
overlays.default = final: prev: {
ratty = self.packages.${final.stdenv.hostPlatform.system}.ratty;
};
checks = forEachSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
# Build + run tests (cargo test via cargoCheckHook)
ratty = self.packages.${system}.ratty;
}
);
# Home Manager module — declarative user-level config
#
# Usage in home.nix:
# programs.ratty = {
# enable = true;
# settings = {
# window = { opacity = 0.9; };
# shell = { program = "zsh"; };
# };
# # Optional: force wgpu backend / adapter selection
# gpuBackend = "vulkan"; # "vulkan" | "gl" | "gles"
# gpuAdapter = "RTX 3060"; # substring match
# };
#
# Config is written to $XDG_CONFIG_HOME/ratty/ratty.toml
# GPU env vars are set via home.sessionVariables.
# ratty discovers the config path automatically.
homeManagerModules.default =
args@{
config,
lib,
pkgs,
...
}:
let
cfg = config.programs.ratty;
tomlFormat = pkgs.formats.toml { };
opts = rattyOptions args;
in
{
inherit (opts) options;
config = lib.mkIf cfg.enable {
assertions = [
{
assertion = cfg.package != null;
message = "programs.ratty.package must not be null when programs.ratty.enable is true";
}
];
home.packages = [ cfg.package ];
xdg.configFile."ratty/ratty.toml" = lib.mkIf (cfg.settings != { }) {
source = tomlFormat.generate "ratty.toml" cfg.settings;
};
home.sessionVariables = lib.mkMerge [
(lib.mkIf (cfg.gpuBackend != null) { WGPU_BACKEND = cfg.gpuBackend; })
(lib.mkIf (cfg.gpuAdapter != null) { WGPU_ADAPTER_NAME = cfg.gpuAdapter; })
(lib.mkIf (cfg.defaultShell != null) { SHELL = lib.getExe cfg.defaultShell; })
];
};
};
# NixOS module — declarative system-level config
#
# Usage in configuration.nix:
# programs.ratty = {
# enable = true;
# settings = {
# window = { opacity = 0.9; };
# shell = { program = "zsh"; };
# };
# # Optional: force wgpu backend / adapter selection
# gpuBackend = "vulkan"; # "vulkan" | "gl" | "gles"
# gpuAdapter = "RTX 3060"; # substring match
# };
#
# Config is written to /etc/ratty/ratty.toml
# Binary is wrapped with --config-file and GPU env vars when set.
nixosModules.default =
args@{
config,
lib,
pkgs,
...
}:
let
cfg = config.programs.ratty;
tomlFormat = pkgs.formats.toml { };
opts = rattyOptions args;
in
{
inherit (opts) options;
config = lib.mkIf cfg.enable {
assertions = [
{
assertion = cfg.package != null;
message = "programs.ratty.package must not be null when programs.ratty.enable is true";
}
];
environment.systemPackages = [
(
let
hasSettings = cfg.settings != { };
hasGpuOpts = cfg.gpuBackend != null || cfg.gpuAdapter != null;
in
if !(hasSettings || hasGpuOpts) then
cfg.package
else
pkgs.symlinkJoin {
name = "ratty-system-wrapped";
paths = [ cfg.package ];
nativeBuildInputs = [ pkgs.makeWrapper ];
postBuild = ''
rm -f $out/bin/ratty
makeWrapper ${lib.getExe cfg.package} $out/bin/ratty \
${lib.optionalString hasSettings "--add-flags \"--config-file /etc/ratty/ratty.toml\""} \
${lib.optionalString (cfg.gpuBackend != null) "--set WGPU_BACKEND '${cfg.gpuBackend}'"} \
${lib.optionalString (cfg.gpuAdapter != null) "--set WGPU_ADAPTER_NAME '${cfg.gpuAdapter}'"} \
${lib.optionalString (
cfg.defaultShell != null
) "--set-default SHELL '${lib.getExe cfg.defaultShell}'"}
'';
}
)
];
environment.etc."ratty/ratty.toml" = lib.mkIf (cfg.settings != { }) {
source = tomlFormat.generate "ratty.toml" cfg.settings;
};
};
};
};
}