Skip to content

Commit 8999b95

Browse files
committed
database: Build with nix
There are quite a few finer detailed points worth exploring. * Ignoring .git and nix directories, as well as any gitignored files ensures that the null-db binary is not built more than necessary when iterating in development. * RUSTC_BOOTSTRAP is a workaround - you can use an unstable toolchain if you want to using some other overlay or something, but caveat emptor. * The layout with a default.nix in the top-level directory is a personal idiom, not exactly worldwide. I like to expose the whole package set from the top-level and use the --attr flag to access things in there.
1 parent 62ec3c1 commit 8999b95

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ ENV/
3333
env.bak/
3434
venv.bak/
3535

36+
# nix creates symlinks like these after nix-build or nix build.
37+
# They can be nice to have for reference
38+
result*
39+
result*/

database/default.nix

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{ lib, nix-gitignore, rustPlatform, openssl, pkg-config, protobuf }:
2+
3+
let
4+
version = "0.1.0";
5+
in
6+
7+
rustPlatform.buildRustPackage {
8+
name = "null-db-${version}";
9+
inherit version;
10+
src = nix-gitignore.gitignoreSourcePure [
11+
''
12+
nix/*
13+
.git/*
14+
''
15+
# I think this is a workaround for a bug in gitignoreSourcePure
16+
../.gitignore
17+
] ../.;
18+
19+
cargoHash = "sha256-J5YJhxqOwub/k17RYsIhu5iZSz5AUmOSeEBWLRcU7Ck=";
20+
21+
# disk_io uses some unstable feature for some reason - workaround
22+
# here by pretending to be compiling rustc
23+
RUSTC_BOOTSTRAP = 1;
24+
25+
nativeBuildInputs = [ pkg-config protobuf ];
26+
buildInputs = [ openssl ];
27+
28+
cargoBuildHook = "cd database";
29+
30+
# Don't compile atm
31+
doCheck = false;
32+
33+
postInstall = ''
34+
mkdir -p $out/libexec
35+
mv $out/bin/null-db $out/libexec
36+
'';
37+
}

default.nix

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{ system ? builtins.currentSystem }:
2+
3+
let
4+
rev = "2d2a9ddbe3f2c00747398f3dc9b05f7f2ebb0f53";
5+
6+
nixpkgs = builtins.fetchTarball {
7+
url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz";
8+
sha256 = "sha256-B5WRZYsRlJgwVHIV6DvidFN7VX7Fg9uuwkRW9Ha8z+w=";
9+
};
10+
in
11+
12+
import nixpkgs {
13+
inherit system;
14+
# If `config` is not provided, things in $HOME or other places get
15+
# picked up, causing nondeterminism :(
16+
#
17+
# This is an unfortunate historical wart that might even eventually
18+
# get fixed.
19+
config = { };
20+
overlays = [ (import ./nix/overlay.nix) ];
21+
}

nix/overlay.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
final: prev: {
2+
null-db = final.callPackage ../database { };
3+
}

0 commit comments

Comments
 (0)