-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
99 lines (86 loc) · 3.36 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
{
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.flake-parts.url = "github:hercules-ci/flake-parts";
inputs.process-compose-flake.url = "github:Platonic-Systems/process-compose-flake";
inputs.services-flake.url = "github:juspay/services-flake";
outputs = inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
inputs.process-compose-flake.flakeModule
];
systems = [
"x86_64-linux"
];
perSystem = { self', pkgs, lib, ... }: let
dotnet-ef = pkgs.callPackage ./nix/dotnet-ef.nix {};
in {
# 3. Create the process-compose configuration, importing services-flake
process-compose."christofel-services" = {
imports = [
inputs.services-flake.processComposeModules.default
];
services.mysql."christofel-db" = {
enable = true;
package = pkgs.mysql80;
initialDatabases = [
{ name = "christofel"; }
];
ensureUsers = [
{
name = "christofel";
password = "christofel";
ensurePermissions = {
"christofel.*" = "ALL PRIVILEGES";
};
}
];
};
settings.processes.christofel-migrator = {
depends_on."christofel-db-configure".condition = "process_completed_successfully";
command = ''
echo $(date): Migrating database...
${lib.getExe self'.packages.christofel-migrate}
echo $(date): Done.
'';
};
};
packages.christofel-migrate = let
configFile = pkgs.writers.writeJSON "config.json" {
ConnectionStrings = {
"ChristofelBase" = "Server=localhost;Database=christofel;Uid=christofel;Pwd=christofel";
};
};
in pkgs.writeShellApplication {
name = "christofel-migrate";
runtimeInputs = [
pkgs.dotnet-sdk_8
];
text = ''
set -euox pipefail
export CHRISTOFEL_CONFIG_PATH=${configFile}
dotnet tool restore
dotnet ef database --startup-project=./src/Tools/Christofel.Design/ update --context ChristofelBaseContext -p ./src/Core/Christofel.Common
dotnet ef database --startup-project=./src/Tools/Christofel.Design/ update --context ManagementContext -p ./src/Plugins/Christofel.Management
dotnet ef database --startup-project=./src/Tools/Christofel.Design/ update --context ReactHandlerContext -p ./src/Plugins/Christofel.ReactHandler
dotnet ef database --startup-project=./src/Tools/Christofel.Design/ update --context ApiCacheContext -p ./src/Plugins/Christofel.Api
dotnet ef database --startup-project=./src/Tools/Christofel.Design/ update --context CoursesContext -p ./src/Libs/Christofel.CoursesLib
'';
};
devShells.default = pkgs.mkShell {
name = "christofel-dev";
packages = [
# Dotnet deps
pkgs.dotnet-sdk_8
pkgs.dotnet-runtime_8
# Services
pkgs.mysql80
# Development, debugging
pkgs.csharp-ls
pkgs.netcoredbg
pkgs.dotnet-outdated
dotnet-ef
];
};
};
};
}