-
-
Notifications
You must be signed in to change notification settings - Fork 239
Expand file tree
/
Copy pathflake.nix
More file actions
175 lines (150 loc) · 5.53 KB
/
flake.nix
File metadata and controls
175 lines (150 loc) · 5.53 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
{
description = "Fresh - A lightweight, fast terminal-based text editor with LSP support and TypeScript plugins";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
crane.url = "github:ipetkov/crane";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-compat = {
url = "github:NixOS/flake-compat";
flake = false;
};
};
outputs =
inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = inputs.nixpkgs.lib.systems.flakeExposed;
imports = [
inputs.flake-parts.flakeModules.easyOverlay
];
perSystem =
{
self',
pkgs,
lib,
system,
...
}:
let
pname = "fresh";
rust-manifest = pkgs.fetchurl {
url = "https://static.rust-lang.org/dist/channel-rust-1.92.0.toml";
hash = "sha256-sqSWJDUxc+zaz1nBWMAJKTAGBuGWP25GCftIOlCEAtA=";
};
rustToolchain = inputs.fenix.packages.${system}.fromManifestFile rust-manifest;
craneLib = (inputs.crane.mkLib pkgs).overrideToolchain rustToolchain.defaultToolchain;
# Source filtering: include Cargo files plus additional files
unfilteredRoot = ./.; # The original, unfiltered source
src = lib.fileset.toSource {
root = unfilteredRoot;
fileset = lib.fileset.unions [
# Default files from crane (Rust and cargo files)
(craneLib.fileset.commonCargoSources unfilteredRoot)
# Also keep any javascript files
(lib.fileset.fileFilter (file: file.hasExt "js") unfilteredRoot)
# Keep Python files (used by include_str! in remote/mod.rs)
(lib.fileset.fileFilter (file: file.hasExt "py") unfilteredRoot)
# Keep sublime-syntax grammar files (used by include_str! in grammar_registry.rs)
(lib.fileset.fileFilter (file: file.hasExt "sublime-syntax") unfilteredRoot)
# Font files (used by include_bytes! in fresh-gui and fresh-editor)
(lib.fileset.fileFilter (file: file.hasExt "ttf") unfilteredRoot)
# Icon files (used by include_bytes! in fresh-gui)
(lib.fileset.fileFilter (file: file.hasExt "png") unfilteredRoot)
# Runtime assets in crates/fresh-editor
./crates/fresh-editor/docs
./crates/fresh-editor/keymaps
./crates/fresh-editor/locales
./crates/fresh-editor/plugins
./crates/fresh-editor/queries
./crates/fresh-editor/themes
./crates/fresh-editor/types
# Test files
./crates/fresh-editor/tests
# Documentation
./docs
];
};
cargoToml = lib.importTOML "${src}/Cargo.toml";
version = cargoToml.workspace.package.version;
# Common arguments for crane builds
commonArgs = {
inherit src pname version;
strictDeps = true;
nativeBuildInputs = with pkgs; [
pkg-config
rustPlatform.bindgenHook
];
doCheck = false;
};
# Build dependencies separately for better caching
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
# Build the actual package
fresh = craneLib.buildPackage (
commonArgs
// {
inherit cargoArtifacts;
# Include runtime assets
postInstall = ''
mkdir -p $out/share/fresh-editor
cp -r crates/fresh-editor/queries $out/share/fresh-editor/
cp -r crates/fresh-editor/themes $out/share/fresh-editor/
cp -r crates/fresh-editor/keymaps $out/share/fresh-editor/
cp -r crates/fresh-editor/plugins $out/share/fresh-editor/
'';
meta.mainProgram = "fresh";
}
);
in
{
checks = {
# Build the package as a check
inherit fresh;
# Run clippy
fresh-clippy = craneLib.cargoClippy (
commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
}
);
# Run tests
fresh-test = craneLib.cargoTest (
commonArgs
// {
inherit cargoArtifacts;
}
);
# Check formatting
fresh-fmt = craneLib.cargoFmt {
inherit src;
};
};
packages = {
inherit fresh;
default = self'.packages.fresh;
};
overlayAttrs = builtins.removeAttrs self'.packages [ "default" ];
devShells.default = craneLib.devShell (
commonArgs
// {
inherit (self') checks;
# Additional development tools
buildInputs = with pkgs; [
rustToolchain.rust-analyzer
rustToolchain.rust-src
cargo-watch
cargo-edit
vscode-json-languageserver
tree-sitter
# Useful for debugging
lldb
];
RUST_SRC_PATH = "${rustToolchain.rust-src}/lib/rustlib/src/rust/library";
}
);
};
};
}