-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
132 lines (109 loc) · 3.55 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
{
description = "LilLil LogLog - simple replicated binary log";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
crane.url = "github:ipetkov/crane";
crane.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, flake-utils, crane }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
};
craneLib = (crane.mkLib pkgs);
commonArgs = {
src = craneLib.cleanCargoSource (craneLib.path ./.);
buildInputs = [
];
nativeBuildInputs = [
pkgs.pkgconfig
];
};
workspaceDeps = craneLib.buildDepsOnly (commonArgs // {
pname = "loglog-workspace-deps";
});
workspaceAll = craneLib.cargoBuild (commonArgs // {
cargoArtifacts = workspaceDeps;
doCheck = true;
});
# a function to define both package and container build for a given binary
pkg = { bin, cargoToml }: rec {
package =
let
meta = craneLib.crateNameFromCargoToml { inherit cargoToml; };
in
craneLib.buildPackage (commonArgs // {
pname = builtins.trace meta.pname meta.pname;
version = meta.version;
cargoExtraArgs = "--bin ${bin}";
doCheck = false;
});
container = pkgs.dockerTools.buildLayeredImage {
name = bin;
contents = [ package ];
config = {
Cmd = [
"${package}/bin/${bin}"
];
ExposedPorts = {
"8000/tcp" = { };
};
};
};
};
loglogd = pkg { bin = "loglogd"; cargoToml = ./server/Cargo.toml; };
in
{
packages = {
default = loglogd.package;
loglogd = loglogd.package;
deps = workspaceDeps;
ci = workspaceAll;
};
devShells = {
default =
pkgs.mkShell {
buildInputs = workspaceDeps.buildInputs;
nativeBuildInputs = workspaceDeps.nativeBuildInputs ++ [
# extra binaries here
pkgs.rust-analyzer
pkgs.rustc
pkgs.cargo
pkgs.clippy
# Bench
pkgs.gnuplot
# Lints
pkgs.rustfmt
pkgs.rnix-lsp
pkgs.nodePackages.bash-language-server
# Nix
pkgs.nixpkgs-fmt
pkgs.shellcheck
# Utils
pkgs.git
pkgs.gh
pkgs.cargo-udeps
];
shellHook = ''
# auto-install git hooks
dot_git="$(git rev-parse --git-common-dir)"
if [[ ! -d "$dot_git/hooks" ]]; then mkdir "$dot_git/hooks"; fi
for hook in misc/git-hooks/* ; do ln -sf "$(pwd)/$hook" "$dot_git/hooks/" ; done
${pkgs.git}/bin/git config commit.template misc/git-hooks/commit-template.txt
'';
};
# this shell is used only in CI lints, so it should contain minimum amount
# of stuff to avoid building and caching things we don't need
lint = pkgs.mkShell {
nativeBuildInputs = [
pkgs.rustfmt
pkgs.nixpkgs-fmt
pkgs.shellcheck
pkgs.git
];
};
};
});
}