-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathflake.nix
115 lines (110 loc) · 3.74 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
{
description = "Python application managed with poetry2nix";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
poetry2nix = {
url = "github:nix-community/poetry2nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
flake-utils = { url = "github:numtide/flake-utils"; };
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};
outputs = { self, nixpkgs, flake-utils, poetry2nix, flake-compat }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
poetry2nix.overlays.default
];
};
python = pkgs.python311;
packageName = "label-approved";
packageVersion = "0.1.0";
in
{
packages = rec {
label-approved = python.pkgs.buildPythonApplication {
pname = packageName;
version = packageVersion;
format = "pyproject";
nativeBuildInputs = with python.pkgs; [ poetry-core ];
propagatedBuildInputs = with python.pkgs; [ pygithub python-dateutil requests ];
src = ./.;
nativeCheckInputs = with python.pkgs; [ mypy types-dateutil types-requests ];
checkPhase = ''
export MYPYPATH=$PWD/src
mypy --strict .
'';
};
default = label-approved;
};
devShells = {
default = pkgs.mkShell {
buildInputs = with pkgs; [
pyright
(pkgs.poetry.override { python3 = python; })
(pkgs.poetry2nix.mkPoetryEnv {
inherit python;
projectDir = ./.;
overrides = pkgs.poetry2nix.overrides.withDefaults (self: super: { });
editablePackageSources = {
label-approved = ./src;
};
extraPackages = (ps: with ps; [
]);
})
] ++ (with python.pkgs; [
black
pylint
mypy
]);
shellHook = ''
export MYPYPATH=$PWD/src
'';
};
};
}) // {
nixosModules.default = { config, lib, pkgs, ... }: let
cfg = config.services.label-approved;
in {
options.services.label-approved = with lib; {
enable = mkEnableOption "Enables the approved PRs labeler service.";
interval = mkOption {
default = "*:0/30";
type = types.str;
description = "systemd-timer OnCalendar config";
};
environmentFile = mkOption {
type = types.path;
example = "/run/secrets/label-approved.env";
description = ''
Environment file to source before running the service. This
should contain a GITHUB_TOKEN or GITHUB_BOT_TOKEN variable.
'';
};
};
config = lib.mkIf cfg.enable {
systemd.timers.label-approved = {
wantedBy = [ "timers.target" ];
after = [ "multi-user.target" ];
timerConfig.OnCalendar = cfg.interval;
};
systemd.services.label-approved = {
description = "label-approved service";
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
serviceConfig = {
DynamicUser = true;
EnvironmentFile = cfg.environmentFile;
ExecStart = "${self.packages.${pkgs.system}.label-approved}/bin/label-approved";
};
};
};
};
};
}