-
Notifications
You must be signed in to change notification settings - Fork 3
/
flake.nix
124 lines (117 loc) · 3.42 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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
fenix.url = "github:nix-community/fenix";
};
outputs = {
self,
nixpkgs,
fenix,
...
}: let
inherit (nixpkgs) lib;
defaultSystems = [
"x86_64-linux"
"x86_64-darwin"
"aarch64-linux"
"aarch64-darwin"
];
eachDefaultSystem = lib.genAttrs defaultSystems;
in {
packages = eachDefaultSystem (system: let
pkgs = import nixpkgs {inherit system;};
toolchain = fenix.packages.${system}.stable;
cargoNix = pkgs.callPackage ./Cargo.nix {
pkgs = pkgs.extend (final: prev: {
inherit (toolchain) cargo;
# workaround for https://github.com/NixOS/nixpkgs/blob/d80a3129b239f8ffb9015473c59b09ac585b378b/pkgs/build-support/rust/build-rust-crate/default.nix#L19-L23
rustc = toolchain.rustc // {unwrapped.configureFlags = ["--target="];};
});
};
in {
default = self.packages.${system}.challenges;
challenges = pkgs.symlinkJoin {
name = "academy-challenges";
paths = [
cargoNix.workspaceMembers.challenges.build
cargoNix.workspaceMembers.migration.build
];
};
generate = pkgs.writeShellScriptBin "generate" ''
${lib.getExe pkgs.crate2nix} generate
'';
});
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
crate2nix
self.packages.${system}.generate
];
RUST_LOG = "info,difft=off,poem_ext,lib,entity,migration,challenges=trace";
};
in {
default = devShell true;
noRust = devShell false;
});
};
}