-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathflake.nix
More file actions
179 lines (159 loc) · 6.33 KB
/
Copy pathflake.nix
File metadata and controls
179 lines (159 loc) · 6.33 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
{
description = "DBFlux - A fast, keyboard-first database client";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
crane.url = "github:ipetkov/crane";
flake-utils.url = "github:numtide/flake-utils";
};
outputs =
{
self,
nixpkgs,
rust-overlay,
crane,
flake-utils,
...
}:
let
releaseInfo = import ./nix/release-info.nix;
# Systems that ship a prebuilt binary in the matching GitHub Release.
# Other systems can still use the source build.
prebuiltSystems = builtins.attrNames releaseInfo.artifacts;
# Per-system outputs (packages, devShells, apps).
perSystem = flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
};
rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
# OpenSSL built with static libraries for portable binaries.
# The default nixpkgs openssl only ships shared objects; this override
# enables the static output so OPENSSL_STATIC=1 works at build time.
opensslStatic = pkgs.openssl.override { static = true; };
# Import default.nix with crane support
dbflux = import ./default.nix {
inherit pkgs craneLib;
version = "0.8.0-dev.0";
};
# Source build (current behavior, compiles locally via crane).
dbfluxSource = dbflux.buildWithCrane craneLib;
# Prebuilt-binary build, only when an artifact exists for this system.
hasPrebuilt = builtins.elem system prebuiltSystems;
dbfluxBin =
if hasPrebuilt then
pkgs.callPackage ./nix/binary.nix { }
else
null;
# Rolling nightly prebuilt — pinned on the `nightly` ref.
# On `main` the hashes in nightly-info.nix are placeholders; always
# consume this via `github:0xErwin1/dbflux/nightly#dbflux-nightly`.
dbfluxNightly =
if hasPrebuilt then
pkgs.callPackage ./nix/binary.nix { infoFile = ./nix/nightly-info.nix; }
else
null;
# Default package: prefer the prebuilt binary when available
# (fast install for end users), fall back to the source build.
dbfluxDefault = if hasPrebuilt then dbfluxBin else dbfluxSource;
in
{
# Development shell
devShells.default = pkgs.mkShell {
nativeBuildInputs = dbflux.nativeBuildInputs ++ [
rustToolchain
pkgs.rust-analyzer
opensslStatic.dev
# Faster, process-isolated test runner for the large workspace.
# Run with `cargo nextest run` (doctests still need `cargo test --doc`).
# mold is inherited from dbflux.nativeBuildInputs (see default.nix).
pkgs.cargo-nextest
# Detects unused dependency declarations (DEP-2 regression guard).
pkgs.cargo-machete
];
buildInputs = dbflux.buildInputs;
LD_LIBRARY_PATH = dbflux.runtimeLibraryPath;
ZSTD_SYS_USE_PKG_CONFIG = "1";
# Link OpenSSL statically so the binary runs outside the Nix store
# (e.g. on Arch Linux without /nix/store available at runtime).
OPENSSL_STATIC = "1";
OPENSSL_LIB_DIR = "${opensslStatic.out}/lib";
OPENSSL_INCLUDE_DIR = "${opensslStatic.dev}/include";
shellHook = ''
echo "DBFlux development environment loaded (Nix flake)"
echo "Run 'cargo build' to build the project"
echo "Run 'nix build' to build the default package"
echo "Run 'nix flake check' to run all checks"
'';
};
# Packages:
# .default -> prebuilt when available, source otherwise
# .dbflux -> alias for .default
# .dbflux-bin -> explicit prebuilt (only on supported systems)
# .dbflux-source -> explicit source build
# .dbflux-nightly -> rolling nightly prebuilt (pin to nightly ref)
packages = {
default = dbfluxDefault;
dbflux = dbfluxDefault;
dbflux-source = dbfluxSource;
} // (if hasPrebuilt then {
dbflux-bin = dbfluxBin;
dbflux-nightly = dbfluxNightly;
} else { });
formatter = pkgs.nixpkgs-fmt;
# Apps
apps = {
default = flake-utils.lib.mkApp {
drv = dbfluxDefault;
exePath = "/bin/dbflux";
};
dbflux = flake-utils.lib.mkApp {
drv = dbfluxDefault;
exePath = "/bin/dbflux";
};
} // (if hasPrebuilt then {
dbflux-nightly = flake-utils.lib.mkApp {
drv = dbfluxNightly;
exePath = "/bin/dbflux-nightly";
};
} else { });
}
);
in
perSystem // {
# Overlay for downstream consumers:
#
# nixpkgs.overlays = [ inputs.dbflux.overlays.default ];
# environment.systemPackages = [ pkgs.dbflux ];
#
# `pkgs.dbflux` -> prebuilt binary (fast)
# `pkgs.dbflux-source` -> built from source via crane
# `pkgs.dbflux-bin` -> explicit prebuilt (only on prebuilt systems)
# `pkgs.dbflux-nightly` -> rolling nightly prebuilt (only on prebuilt systems)
overlays.default = final: prev:
let
system = prev.stdenv.hostPlatform.system;
hasSystem = perSystem.packages ? ${system};
sysPkgs = perSystem.packages.${system};
in
if hasSystem then
{
dbflux = sysPkgs.dbflux;
dbflux-source = sysPkgs.dbflux-source;
}
// nixpkgs.lib.optionalAttrs (sysPkgs ? dbflux-nightly) {
dbflux-nightly = sysPkgs.dbflux-nightly;
}
// nixpkgs.lib.optionalAttrs (sysPkgs ? dbflux-bin) {
dbflux-bin = sysPkgs.dbflux-bin;
}
else
{ };
};
}