forked from kellnr/kellnr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
184 lines (152 loc) · 5.59 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
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
{
description = "Development and build environment for kellnr";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
crane = {
url = "github:ipetkov/crane";
};
};
outputs = { nixpkgs, flake-utils, crane, ... }:
flake-utils.lib.eachSystem [ "aarch64-darwin" "aarch64-linux" "x86_64-linux" ] (system:
let
pkgs = import nixpkgs { inherit system; };
inherit (pkgs) lib;
craneLib = crane.mkLib nixpkgs.legacyPackages.${system};
# Set a filter of files that are included in the build source directory.
# This is used to filter out files that are not needed for the build to
# not rebuild on every file change, e.g. in a Readme.md file.
webuiFilter = path: _type: builtins.match ".*.(js|json|ts|vue|html|png|css|svg)$" path != null;
webuiOrCargo = path: type:
(webuiFilter path type) || (craneLib.filterCargoSources path type);
# Include all Rust and WebUI files in the source directory.
src = lib.cleanSourceWith {
src = craneLib.path ./.;
filter = webuiOrCargo;
};
commonArgs = {
inherit src;
strictDeps = true;
pname = "kellnr";
nativeBuildInputs = [
pkgs.cmake
pkgs.nodejs_22
] ++ lib.optionals pkgs.stdenv.isLinux [
pkgs.pkg-config
pkgs.rustPlatform.bindgenHook
];
buildInputs = [
pkgs.cargo-nextest
pkgs.openssl.dev
] ++ lib.optional pkgs.stdenv.isDarwin [
pkgs.darwin.apple_sdk.frameworks.Cocoa
pkgs.libiconv
pkgs.iconv
pkgs.cacert
pkgs.curl
] ++ lib.optional pkgs.stdenv.isLinux [
];
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
BINDGEN_EXTRA_CLANG_ARGS = "-isystem ${pkgs.llvmPackages.libclang.lib}/lib/clang/${pkgs.lib.getVersion pkgs.clang}/include";
};
# Build *just* the cargo dependencies, so we can reuse
# all of that work (e.g. via cachix) when running in CI
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
# Install the NPM dependencies
nodejs = pkgs.nodejs_22;
node2nixOutput = import ui/nix { inherit pkgs nodejs system; };
nodeDeps = node2nixOutput.nodeDependencies;
# Build the actual crate itself, reusing the dependency
# artifacts from above.
kellnr-crate = craneLib.buildPackage (commonArgs // {
inherit cargoArtifacts nodeDeps;
# Skip test as we run them with cargo-nextest
doCheck = false;
preConfigurePhases = [
"npmBuild"
"debug"
];
debug = ''
echo "---- DEBUG ----"
echo "Path: "
pwd
echo "Directory: "
ls -la
ls -la ui
'';
npmBuild = ''
cd ui;
ln -s ${nodeDeps}/lib/node_modules ./node_modules;
export PATH="${nodeDeps}/bin:$PATH";
npm run build --verbose;
cd ..;
'';
installPhase = ''
# Copy kellnr binary into bin directory
mkdir -p $out/bin;
cp target/release/kellnr $out/bin;
# Copy default config into bin directory
mkdir -p $out/bin/config;
cp config/default.toml $out/bin/config;
# Copy the built UI into the bin directory
mkdir -p $out/bin/static;
cp -r ui/dist/* $out/bin/static;
# Debug output
ls -la $out/bin;
ls -la $out/bin/static;
ls -la $out/bin/config;
'';
# fixupPhase = ''
# '';
});
in
with pkgs;
{
checks = {
inherit kellnr-crate;
# Run the tests with cargo-nextest,
# excluding the database tests and other tests that do not run
# well with the nix sandbox.
# nextest = craneLib.cargoNextest (commonArgs // {
# inherit cargoArtifacts;
# cargoNextestExtraArgs = "--workspace -E 'not (binary_id(db::postgres_test) or binary_id(db::sqlite_test) or test(cratesio_prefetch_api::tests::fetch_cratesio_description_works) or test(cratesio_prefetch_api::tests::fetch_cratesio_prefetch_works))'";
# });
# Check formatting with rustfmt.
fmt = craneLib.cargoFmt (commonArgs // {
inherit src;
});
# Check for clippy warnings.
clippy = craneLib.cargoClippy (commonArgs // {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--workspace --all-targets -- --deny warnings";
});
};
devShells.default = craneLib.devShell (commonArgs // {
inputsFrom = [ kellnr-crate ];
shellHook = ''
alias c=cargo
alias j=just
alias lg=lazygit
'' + lib.optionalString stdenv.isDarwin ''
export DYLD_LIBRARY_PATH="$(rustc --print sysroot)/lib:$DYLD_LIBRARY_PATH"
export RUST_SRC_PATH="$(rustc --print sysroot)/lib/rustlib/src/rust/src"
'';
packages = with pkgs; [
rust-analyzer
cargo-nextest
cargo-machete
lazygit
just
node2nix
jd-diff-patch
];
});
packages = {
default = kellnr-crate;
};
apps.default = flake-utils.lib.mkApp {
drv = kellnr-crate;
};
}
);
}