-
Notifications
You must be signed in to change notification settings - Fork 3
/
flake.nix
110 lines (98 loc) · 3.4 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
{
description = "Setup for testing Atmosphere";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
systems.url = "github:nix-systems/default";
process-compose-flake.url = "github:Platonic-Systems/process-compose-flake";
services-flake.url = "github:juspay/services-flake";
flake-utils = {
url = "github:numtide/flake-utils";
inputs.systems.follows = "systems";
};
rust-overlay = {
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
url = "github:oxalica/rust-overlay";
};
};
outputs = inputs @ { rust-overlay, nixpkgs, ... }:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = import inputs.systems;
imports = [
inputs.process-compose-flake.flakeModule
];
perSystem = { self', system, lib, ... }:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
dbName = "atmosphere";
mySqlPort = 3310;
ifDarwin = lib.optionals pkgs.stdenv.isDarwin;
in
{
apps.lint.program = pkgs.writeShellApplication {
name = "cargo.lint";
runtimeInputs = with pkgs; [
rust-bin.stable.latest.default
typos
] ++ ifDarwin [
darwin.apple_sdk.frameworks.SystemConfiguration
];
text = ''
set -eux
cargo fmt --all
cargo clippy
typos
'';
};
process-compose."default" = { config, ... }: {
imports = [
inputs.services-flake.processComposeModules.default
];
settings.processes.test =
let
pgconf = config.services.postgres.pg;
in
{
command = pkgs.writeShellApplication {
name = "cargo.test.postgres";
runtimeInputs = with pkgs; [
rust-bin.stable.latest.default
] ++ ifDarwin [
darwin.apple_sdk.frameworks.SystemConfiguration
];
text = ''
set -eux
mkdir -p data
DATABASE_URL=${pgconf.connectionURI { inherit dbName; }} cargo test -F postgres
DATABASE_URL=localhost:${toString mySqlPort} cargo test -F mysql
DATABASE_URL=data/test.db cargo test -F sqlite
'';
};
depends_on = {
"pg".condition = "process_healthy";
"mysql".condition = "process_healthy";
};
};
services.postgres."pg" = {
enable = true;
initialDatabases = [
{ name = dbName; }
];
};
services.mysql."mysql" = {
enable = true;
initialDatabases = [
{ name = dbName; }
];
settings.mysqld.port = mySqlPort;
};
# avoid both processes trying to create `data` directory at the same time
settings.processes."mysql-configure".depends_on."pg-init".condition = "process_completed_successfully";
};
};
};
}