Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
149 lines (140 loc) · 4.6 KB
/
Copy pathflake.nix
File metadata and controls
149 lines (140 loc) · 4.6 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
{
description = "cv";
inputs = {
# 26.05 is the last nixpkgs release that supports x86_64-darwin (until the end of 2026).
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-26.05";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
crane.url = "github:ipetkov/crane";
};
outputs =
{
self,
nixpkgs,
rust-overlay,
crane,
}:
let
inherit (nixpkgs) lib;
defaultSystems = [
"aarch64-darwin"
"aarch64-linux"
"x86_64-darwin"
"x86_64-linux"
];
forAllSystems =
fn:
lib.genAttrs defaultSystems (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
config.allowDeprecatedx86_64Darwin = true;
};
rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
craneLib = (crane.mkLib pkgs).overrideToolchain (_: rustToolchain);
in
fn { inherit pkgs rustToolchain craneLib; }
);
in
{
packages = forAllSystems (
{ pkgs, craneLib, ... }:
{
default = craneLib.buildPackage {
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
(craneLib.fileset.commonCargoSources ./.)
./migrations
# Golden files that are not Cargo sources.
./src/facts/c
./src/facts/python
./src/facts/rust
];
};
strictDeps = true;
# Git serves the mirror tests' fixture repository.
nativeCheckInputs = [
pkgs.git
pkgs.postgresql_18
];
# A Postgres of the build's own, reachable only through a socket, as `#[sqlx::test]`
# expects.
preCheck = ''
export PGDATA="$TMPDIR/postgres" PGHOST="$TMPDIR/postgres"
export DATABASE_URL="postgres:///postgres?host=$PGHOST&user=postgres"
initdb --username=postgres --auth=trust --no-locale --encoding=UTF8 >/dev/null
pg_ctl start --silent --log="$PGDATA/log" -o "-c listen_addresses= -k $PGHOST"
'';
meta.mainProgram = "cv";
};
}
);
devShells = forAllSystems (
{ pkgs, rustToolchain, ... }:
let
inherit (rustToolchain.availableComponents) rust-analyzer rust-src;
in
rec {
# What builds need, and nothing more.
ci = pkgs.mkShell {
name = "cv-ci";
packages = [
rustToolchain
pkgs.git
pkgs.postgresql_18
];
};
# Adds editor support, from the same Rust release.
default = pkgs.mkShell {
name = "cv-dev";
inputsFrom = [ ci ];
packages = [ rust-analyzer ];
RUST_SRC_PATH = "${rust-src}/lib/rustlib/src/rust/library";
};
}
);
nixosModules.default = import ./nix/module.nix self;
checks = forAllSystems (
{ pkgs, ... }:
let
cv = self.packages.${pkgs.stdenv.hostPlatform.system}.default;
flags = "grep -o -- '--[a-z-]*' | grep -vx -- '--help\\|--version' | sort -u";
in
{
# Builds `cv`, running its tests, then fails unless `nix/module.nix` passes exactly the
# flags `cv` takes.
module-in-sync = pkgs.runCommand "module-in-sync" { } ''
diff -u <(${lib.getExe cv} --help | ${flags}) <(< ${./nix/module.nix} ${flags})
touch $out
'';
# The alert rules a host gets from the module, against `nix/alerts.test.yml`.
alerts =
let
host = lib.nixosSystem {
modules = [
self.nixosModules.default
{
nixpkgs.pkgs = pkgs;
services.cv.enable = true;
services.prometheus.enable = true;
}
];
};
rules = lib.head host.config.services.prometheus.ruleFiles;
in
pkgs.runCommand "alerts" { nativeBuildInputs = [ pkgs.prometheus.cli ]; } ''
ln -s ${rules} cv-alerts.json
cp ${./nix/alerts.test.yml} alerts.test.yml
promtool check rules cv-alerts.json
promtool test rules alerts.test.yml
touch $out
'';
}
);
};
}