-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
131 lines (118 loc) · 4.38 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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
naersk = {
url = "github:nix-community/naersk";
inputs.nixpkgs.follows = "nixpkgs";
};
utils = {
url = "github:numtide/flake-utils";
};
fenix = {
url = "github:nix-community/fenix";
};
};
outputs = { self, nixpkgs, naersk, utils, fenix, ... }:
utils.lib.eachSystem ["x86_64-linux" "aarch64-linux" ]
(system:
let
pkgs = nixpkgs.legacyPackages.${system};
toolchain = with fenix.packages.${system}; combine [
latest.cargo
latest.rustc
];
package = pkgs.callPackage ./derivation.nix {
buildPackage = (naersk.lib.${system}.override {
cargo = toolchain;
rustc = toolchain;
}).buildPackage;
};
makeTest = pkgs.callPackage "${nixpkgs}/nixos/tests/make-test-python.nix";
in rec {
checks.test-diesel-migration =
let
username = "postgres";
password = "password";
database = "database";
in
(makeTest
{
name = "test-diesel-migration";
nodes = {
server = { lib, config, pkgs, ... }: {
services.postgresql = {
enable = true;
ensureDatabases = [ database ];
ensureUsers = [{
name = username;
}];
initialScript = pkgs.writeScript "initScript" ''
ALTER USER postgres WITH PASSWORD '${password}';
'';
};
systemd.services.postgresql.postStart = lib.mkAfter ''
${pkgs.diesel-cli}/bin/diesel migration run --database-url "postgres://${username}:${password}@localhost/${database}" --migration-dir ${self}/migrations
${pkgs.diesel-cli}/bin/diesel migration redo --database-url "postgres://${username}:${password}@localhost/${database}" --migration-dir ${self}/migrations
${pkgs.diesel-cli}/bin/diesel migration run --database-url "postgres://${username}:${password}@localhost/${database}" --migration-dir ${self}/migrations
'';
};
};
testScript = ''
start_all()
server.wait_for_unit("postgresql.service")
server.succeed("sudo -u postgres -- ${pkgs.diesel-cli}/bin/diesel print-schema --database-url postgres://${username}:${password}@localhost/${database} > schema.rs")
server.copy_from_vm("schema.rs", "")
'';
}{
inherit pkgs;
inherit (pkgs) system;
});
packages = {
borzoi = package;
default = package;
update-schema = pkgs.writeScriptBin "update-schema" ''
#!/usr/bin/env bash
nix build ${self}#checks.${system}.test-diesel-migration
BUILD_DIR=$(nix build ${self}#checks.${system}.test-diesel-migration --no-link --print-out-paths)
rm -rf src/schema.rs
cp $BUILD_DIR/schema.rs src/schema.rs
'';
run-migration-borzoi = pkgs.writeScriptBin "run-migration" ''
${pkgs.diesel-cli}/bin/diesel migration run --migration-dir ${self}/migrations
'';
};
devShells.default = pkgs.mkShell {
nativeBuildInputs = (with packages.borzoi; buildInputs ++ nativeBuildInputs);
};
}
) // {
overlays.default = final: prev: {
inherit (self.packages.${prev.system})
borzoi run-migration-borzoi;
};
nixosModules = rec {
default = borzoi;
borzoi = import ./nixos-module;
};
hydraJobs =
let
hydraSystems = [
"x86_64-linux"
"aarch64-linux"
];
in
builtins.foldl'
(hydraJobs: system:
builtins.foldl'
(hydraJobs: pkgName:
nixpkgs.lib.recursiveUpdate hydraJobs {
${pkgName}.${system} = self.packages.${system}.${pkgName};
}
)
hydraJobs
(builtins.attrNames self.packages.${system})
)
{ }
hydraSystems;
};
}