-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
executable file
·161 lines (145 loc) · 5.32 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
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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
naersk = {
url = "github:nix-community/naersk";
inputs.nixpkgs.follows = "nixpkgs";
};
utils = {
url = "github:numtide/flake-utils";
};
fenix = {
url = "github:nix-community/fenix";
};
pnpm2nix = {
url = "github:nzbr/pnpm2nix-nzbr";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "utils";
};
};
outputs = inputs@{ self, nixpkgs, naersk, utils, fenix, pnpm2nix, ... }:
utils.lib.eachDefaultSystem
(system:
let
pkgs = nixpkgs.legacyPackages.${system};
makeTest = pkgs.callPackage "${nixpkgs}/nixos/tests/make-test-python.nix";
toolchain = with fenix.packages.${system}; combine [
stable.cargo
stable.rustc
];
migration = pkgs.callPackage ./pkgs/migration.nix {
buildPackage = (naersk.lib.${system}.override {
cargo = toolchain;
rustc = toolchain;
}).buildPackage;
};
backend = pkgs.callPackage ./pkgs/backend.nix {
buildPackage = (naersk.lib.${system}.override {
cargo = toolchain;
rustc = toolchain;
}).buildPackage;
};
frontend = pkgs.callPackage ./pkgs/frontend.nix {
mkPnpmPackage = pnpm2nix.packages."${system}".mkPnpmPackage;
domain = "science.tanneberger.me";
};
in
rec {
checks.test-sea-orm-cli-migration =
let
username = "postgres";
password = "password";
database = "database";
migrations_dir = ./migration;
in
makeTest
{
name = "test-sea-orm-cli-migration";
nodes = {
server = { lib, config, pkgs, ... }: {
services.postgresql = {
enable = true;
ensureDatabases = [ database ];
ensureUsers = [{
name = username;
ensurePermissions = {
"DATABASE ${database}" = "ALL PRIVILEGES";
};
}];
initialScript = pkgs.writeScript "initScript" ''
ALTER USER postgres WITH PASSWORD '${password}';
'';
};
systemd.services.postgresql.postStart = lib.mkAfter ''
${migration}/bin/migration refresh --database-url postgresql://${username}:${password}@localhost/${database}
'';
};
};
testScript = ''
start_all()
server.wait_for_unit("postgresql.service")
server.execute("${pkgs.sea-orm-cli}/bin/sea-orm-cli generate entity --database-url postgresql://${username}:${password}@localhost/${database} --date-time-crate time --with-serde both --output-dir /tmp/out")
server.copy_from_vm("/tmp/out", "")
'';
}
{
inherit pkgs;
inherit (pkgs) system;
};
packages = {
update-schema = pkgs.writeScriptBin "update-schema" ''
nix build ${self}#checks.${system}.test-sea-orm-cli-migration
BUILD_DIR=$(nix build ${self}#checks.${system}.test-sea-orm-cli-migration --no-link --print-out-paths)
rm -rf entity/src/models/*
mkdir -p entity/src/models
cp -r $BUILD_DIR/out/* ./entity/src/models/
chmod -R 644 ./entity/src/models/*
${pkgs.cargo}/bin/cargo fmt
'';
run-migration-based = pkgs.writeScriptBin "run-migration" ''
${pkgs.sea-orm-cli}/bin/sea-orm-cli migration run --migration-dir ${self}/migrations-based
'';
doubleblind-backend = backend;
doubleblind-frontend = frontend;
default = backend;
};
devShells.default = pkgs.mkShell {
nativeBuildInputs = (with packages.default; nativeBuildInputs ++ buildInputs) ++ [
# python for running test scripts
(pkgs.python3.withPackages (p: with p; [
requests
]))
];
};
}
) // {
overlays.default = final: prev: {
inherit (self.packages.${prev.system})
doubleblind-backend doubleblind-frontend;
};
nixosModules = rec {
doubleblind = import ./nixos-module/doubleblind.nix;
default = doubleblind;
};
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;
};
}