-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
flake.nix
156 lines (148 loc) · 5.96 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
{
description = "A Tool for tagging PRs of First-Time Contributors with a specified label";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
pre-commit.url = "github:cachix/pre-commit-hooks.nix";
pre-commit.inputs.nixpkgs.follows = "nixpkgs";
pre-commit.inputs.nixpkgs-stable.follows = "";
pre-commit.inputs.flake-utils.follows = "flake-utils";
};
outputs = { self, nixpkgs, flake-utils, pre-commit, ... }:
flake-utils.lib.eachDefaultSystem
(
system:
let
pkgs = import nixpkgs { inherit system; };
in
{
checks = {
pre-commit-check = pre-commit.lib.${system}.run {
src = ./.;
hooks = {
nixpkgs-fmt.enable = true;
isort.enable = true;
black.enable = true;
flake8.enable = true;
};
};
};
defaultPackage = with pkgs.python3Packages; pkgs.python3.pkgs.buildPythonApplication {
pname = "first-time-contribution-tagger";
version = "0.1.1";
pyproject = true;
src = ./.;
nativeBuildInputs = [
poetry-core
];
propagatedBuildInputs = [
requests
];
nativeCheckInputs = [
pytestCheckHook
];
meta = with pkgs.lib; {
license = licenses.agpl3Only;
maintainers = with maintainers; [ janik ];
};
};
devShell = pkgs.mkShell {
inherit (self.checks.${system}.pre-commit-check) shellHook;
buildInputs = with pkgs; [
python3.pkgs.requests
];
};
}
) // {
nixosModule = { config, lib, pkgs, ... }:
let cfg = config.services.first-time-contribution-tagger;
in {
options.services.first-time-contribution-tagger = {
enable = lib.mkEnableOption "Enables the first-time-contribution-tagger service";
interval = lib.mkOption {
default = "*:0/10";
type = lib.types.str;
example = lib.literalExpression "*:0/10";
description = lib.mdDoc "systemd-timer OnCalendar config, the above example starts the unit every 10 minutes";
};
environment = lib.mkOption {
default = { };
type = lib.types.attrsOf lib.types.str;
example = lib.literalExpression ''
{
FIRST_TIME_CONTRIBUTION_LABEL="12. first-time contribution";
FIRST_TIME_CONTRIBUTION_CACHE="/var/lib/first-time-contribution-tagger/cache";
FIRST_TIME_CONTRIBUTION_REPO="nixpkgs";
FIRST_TIME_CONTRIBUTION_ORG="NixOS";
}
'';
description = lib.mdDoc "config envrionment variables, for other options read the [documentation](https://github.com/janik-Haag/first-time-contribution-tagger)";
};
environmentFile = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
example = "/root/first-time-contribution-tagger.env";
description = lib.mdDoc ''
File to load environment variables
from. This is helpful for specifying secrets.
Example content of environmentFile:
```
FIRST_TIME_CONTRIBUTION_GITHUB_TOKEN="ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
```
'';
};
};
config = lib.mkIf cfg.enable {
systemd.timers.first-time-contribution-tagger = {
wantedBy = [ "timers.target" ];
after = [ "multi-user.target" ];
timerConfig = {
OnCalendar = cfg.interval;
};
};
systemd.services.first-time-contribution-tagger = {
description = "first-time-contribution-tagger service";
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
serviceConfig = {
DynamicUser = true;
WorkingDirectory = "%S/first-time-contribution-tagger";
StateDirectory = "first-time-contribution-tagger";
StateDirectoryMode = "0700";
UMask = "0007";
ConfigurationDirectory = "first-time-contribution-tagger";
EnvironmentFile = lib.optional (cfg.environmentFile != null) cfg.environmentFile;
ExecStart = "${self.defaultPackage.${pkgs.system}}/bin/first-time-contribution-tagger";
Restart = "on-failure";
RestartSec = 15;
CapabilityBoundingSet = "";
# Security
NoNewPrivileges = true;
# Sandboxing
ProtectSystem = "strict";
ProtectHome = true;
PrivateTmp = true;
PrivateDevices = true;
PrivateUsers = true;
ProtectHostname = true;
ProtectClock = true;
ProtectKernelTunables = true;
ProtectKernelModules = true;
ProtectKernelLogs = true;
ProtectControlGroups = true;
RestrictAddressFamilies = [ "AF_UNIX AF_INET AF_INET6" ];
LockPersonality = true;
MemoryDenyWriteExecute = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
PrivateMounts = true;
# System Call Filtering
SystemCallArchitectures = "native";
SystemCallFilter = "~@clock @privileged @cpu-emulation @debug @keyring @module @mount @obsolete @raw-io @reboot @setuid @swap";
};
inherit (cfg) environment;
};
};
};
};
}