-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
109 lines (105 loc) · 2.84 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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
poetry2nix.url = "github:nix-community/poetry2nix";
};
outputs = {
self,
nixpkgs,
poetry2nix,
...
}: let
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;};
inherit (poetry2nix.lib.mkPoetry2Nix {inherit pkgs;}) mkPoetryApplication defaultPoetryOverrides;
in {
default = mkPoetryApplication {
projectDir = ./.;
python = pkgs.python311;
doCheck = false;
overrides = defaultPoetryOverrides.extend (self: super: {
frozenlist = super.frozenlist.overridePythonAttrs (old: {
buildInputs = (old.buildInputs or []) ++ [super.expandvars];
});
});
};
});
nixosModules.default = {
config,
lib,
pkgs,
...
}: let
settingsFormat = pkgs.formats.keyValue {};
in {
options.academy.backend.jobs = with lib; {
enable = mkEnableOption "Bootstrap Academy Jobs Microservice";
environmentFiles = mkOption {
type = types.listOf types.path;
};
settings = mkOption {
inherit (settingsFormat) type;
};
};
config = let
cfg = config.academy.backend.jobs;
in
lib.mkIf cfg.enable {
systemd.services = {
academy-jobs = {
wantedBy = ["multi-user.target"];
serviceConfig = {
User = "academy-jobs";
Group = "academy-jobs";
DynamicUser = true;
EnvironmentFile = cfg.environmentFiles ++ [(settingsFormat.generate "config" cfg.settings)];
};
preStart = ''
cd ${lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./alembic
./alembic.ini
];
}}
${self.packages.${pkgs.system}.default}/bin/alembic upgrade head
'';
script = ''
${self.packages.${pkgs.system}.default}/bin/api
'';
};
};
};
};
devShells = eachDefaultSystem (system: let
pkgs = import nixpkgs {inherit system;};
in {
default = pkgs.mkShell {
packages = with pkgs; [
python311
poetry
poethepoet
pyright
python311.pkgs.greenlet
];
shellHook = ''
poe setup
source .venv/bin/activate
'';
};
});
};
}