forked from Bootstrap-Academy/challenges-ms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
120 lines (118 loc) · 3.17 KB
/
flake.nix
File metadata and controls
120 lines (118 loc) · 3.17 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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};
outputs = {
self,
nixpkgs,
...
}: let
inherit (nixpkgs) lib;
defaultSystems = [
"x86_64-linux"
"x86_64-darwin"
"aarch64-linux"
"aarch64-darwin"
];
eachDefaultSystem = f:
builtins.listToAttrs (map (system: {
name = system;
value = f system;
})
defaultSystems);
in {
packages = eachDefaultSystem (system: let
pkgs = import nixpkgs {inherit system;};
in {
default = self.packages.${system}.challenges;
challenges = pkgs.rustPlatform.buildRustPackage {
inherit ((fromTOML (builtins.readFile ./challenges/Cargo.toml)).package) version;
pname = "academy-challenges";
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./Cargo.toml
./Cargo.lock
./migration
./entity
./lib
./schemas
./challenges
];
};
cargoLock.lockFile = ./Cargo.lock;
doCheck = false;
};
});
nixosModules.default = {
config,
lib,
pkgs,
...
}: let
settingsFormat = pkgs.formats.toml {};
in {
options.academy.backend.challenges = with lib; {
enable = mkEnableOption "Bootstrap Academy Challenges Microservice";
RUST_LOG = mkOption {
type = types.str;
default = "info";
};
environmentFiles = mkOption {
type = types.listOf types.path;
};
settings = mkOption {
inherit (settingsFormat) type;
};
};
config = let
cfg = config.academy.backend.challenges;
in
lib.mkIf cfg.enable {
systemd.services = {
academy-challenges = {
wantedBy = ["multi-user.target"];
serviceConfig = {
User = "academy-challenges";
Group = "academy-challenges";
DynamicUser = true;
EnvironmentFile = cfg.environmentFiles;
};
environment = {
inherit (cfg) RUST_LOG;
CONFIG_PATH = settingsFormat.generate "config.toml" cfg.settings;
};
preStart = ''
${self.packages.${pkgs.system}.default}/bin/migration
'';
script = ''
${self.packages.${pkgs.system}.default}/bin/challenges
'';
};
};
};
};
devShells = eachDefaultSystem (system: let
inherit (nixpkgs) lib;
pkgs = import nixpkgs {inherit system;};
devShell = withRust:
pkgs.mkShell {
packages = with pkgs;
lib.optionals withRust [rustc cargo clippy rust-analyzer]
++ [
just
postgresql
redis
bacon
sea-orm-cli
yq
gnused
];
RUST_LOG = "info,difft=off,poem_ext,lib,entity,migration,challenges=trace";
};
in {
default = devShell true;
noRust = devShell false;
});
};
}