Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
180 lines (162 loc) · 5.99 KB
/
Copy pathflake.nix
File metadata and controls
180 lines (162 loc) · 5.99 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
{
description = "AtomicServer: graph database server with real-time Loro sync";
# nixos-unstable ships the exact Rust toolchain pinned in rust-toolchain.toml
# (with the wasm32-unknown-unknown std the browser WASM needs), so no
# rust-overlay is required. The channel tarball (not `github:`) lets
# flake.lock pin it without the GitHub API.
inputs.nixpkgs.url = "https://channels.nixos.org/nixos-unstable/nixexprs.tar.xz";
outputs =
{ self, nixpkgs }:
let
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f nixpkgs.legacyPackages.${system});
lib = nixpkgs.lib;
# Keep the Nix toolchain in step with `rust-toolchain.toml`.
pinnedRust = (builtins.fromTOML (builtins.readFile ./rust-toolchain.toml)).toolchain.channel;
version = (builtins.fromTOML (builtins.readFile ./server/Cargo.toml)).package.version;
# Stands in for the data browser (`browser/`), which needs network
# access to build and so can't be built in the Nix sandbox yet. The
# server embeds whatever `dist` it is given; swap in the real bundle with
# `.override { dataBrowser = <dist directory>; }`.
placeholderDataBrowser =
pkgs:
pkgs.writeTextDir "index.html" ''
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>AtomicServer</title>
<!-- { inject_html_head } -->
</head>
<body>
<p>
This AtomicServer was built without the data browser. The API
works; request resources with <code>Accept: application/ad+json</code>.
</p>
<!-- { inject_script } -->
</body>
</html>
'';
atomicServer =
pkgs:
pkgs.callPackage (
{
rustPlatform,
pkg-config,
cmake,
clang,
protobuf,
dataBrowser ? placeholderDataBrowser pkgs,
}:
rustPlatform.buildRustPackage {
pname = "atomic-server";
inherit version;
# Only the Rust workspace: editing docs or the frontend sources
# must not rebuild the server.
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./Cargo.toml
./Cargo.lock
./server
./lib
./cli
./desktop
./wasm
./atomic-plugin
./plugin-runtime
./plugin-examples
./tools
./testdata
];
};
cargoLock.lockFile = ./Cargo.lock;
cargoBuildFlags = [
"--package"
"atomic-server"
];
# The test suite needs a browser, a network and a running server;
# CI covers it.
doCheck = false;
nativeBuildInputs = [
pkg-config
cmake
clang
protobuf
];
# `server/build.rs` embeds `../browser/data-browser/dist`. It
# would run `pnpm` to build it; hand it the finished bundle.
ATOMICSERVER_SKIP_JS_BUILD = "true";
# The plugin runtime is a wasm32-wasip2 component, and nixpkgs
# has no std for that target. The server builds without it
# (server-side plugins are unavailable).
ATOMICSERVER_SKIP_PLUGIN_RUNTIME = "true";
preBuild = ''
mkdir -p browser/data-browser
cp -r ${dataBrowser} browser/data-browser/dist
chmod -R u+w browser/data-browser/dist
'';
meta = {
description = "Graph database server with real-time sync, built on Atomic Data and Loro";
homepage = "https://atomicserver.eu/";
license = lib.licenses.mit;
mainProgram = "atomic-server";
platforms = systems;
};
}
) { };
in
{
packages = forAllSystems (pkgs: rec {
atomic-server = atomicServer pkgs;
default = atomic-server;
});
apps = forAllSystems (pkgs: {
default = {
type = "app";
program = lib.getExe self.packages.${pkgs.stdenv.hostPlatform.system}.atomic-server;
};
});
# `nix develop`: everything `cargo run` in server/ and `pnpm` in
# browser/ expect on PATH. On NixOS the prebuilt tools those would
# download (wasm-bindgen, wasm-opt) can't run, so they come from nixpkgs.
devShells = forAllSystems (pkgs: {
default = pkgs.mkShell {
packages = [
(lib.warnIf (pkgs.rustc.version != pinnedRust)
"flake: nixpkgs has Rust ${pkgs.rustc.version}, rust-toolchain.toml pins ${pinnedRust}"
pkgs.rustc
)
pkgs.cargo
pkgs.clippy
pkgs.rustfmt
pkgs.rust-analyzer
pkgs.nodejs_22
pkgs.pnpm_10
# build:wasm. wasm-pack reuses wasm-bindgen / wasm-opt from PATH
# when the version matches `wasm-bindgen` in Cargo.lock.
pkgs.wasm-pack
pkgs.wasm-bindgen-cli_0_2_122
pkgs.binaryen
pkgs.pkg-config
pkgs.cmake
pkgs.clang
pkgs.protobuf
pkgs.openssl
];
# Rust std sources for rust-analyzer.
RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}";
# Native node modules (@parcel/watcher, @swc/core) load libstdc++.
shellHook = lib.optionalString pkgs.stdenv.hostPlatform.isLinux ''
export LD_LIBRARY_PATH="${lib.makeLibraryPath [ pkgs.stdenv.cc.cc.lib ]}''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
'';
};
});
formatter = forAllSystems (pkgs: pkgs.nixfmt);
};
}