summaryrefslogtreecommitdiff
path: root/nix/module.nix
diff options
context:
space:
mode:
authorseth <[email protected]>2024-05-27 04:55:45 -0400
committerseth <[email protected]>2024-05-27 04:56:48 -0400
commitc69eea2f4823da476628742fbbec600ee95ac049 (patch)
tree7cf3d87f5f202e6049ba44a06ac6fe9d3558826b /nix/module.nix
initial commit
Diffstat (limited to 'nix/module.nix')
-rw-r--r--nix/module.nix82
1 files changed, 82 insertions, 0 deletions
diff --git a/nix/module.nix b/nix/module.nix
new file mode 100644
index 0000000..ec9da78
--- /dev/null
+++ b/nix/module.nix
@@ -0,0 +1,82 @@
+self: {
+ config,
+ lib,
+ pkgs,
+ ...
+}: let
+ cfg = config.services.nixpkgs-tracker-bot;
+
+ inherit
+ (lib)
+ getExe
+ literalExpression
+ mkEnableOption
+ mkIf
+ mkOption
+ mkPackageOption
+ types
+ ;
+
+ inherit (pkgs.stdenv.hostPlatform) system;
+in {
+ options.services.nixpkgs-tracker-bot = {
+ enable = mkEnableOption "nixpkgs-tracker-bot";
+ package = mkPackageOption (
+ self.packages.${system} or (throw "${system} is not supported!")
+ ) "nixpkgs-tracker-bot" {};
+
+ environmentFile = mkOption {
+ description = ''
+ Environment file as defined in {manpage}`systemd.exec(5)`
+ '';
+ type = types.nullOr types.path;
+ default = null;
+ example = literalExpression ''
+ "/run/agenix.d/1/nixpkgs-tracker-bot"
+ '';
+ };
+ };
+
+ config = mkIf cfg.enable {
+ systemd.services.nixpkgs-tracker-bot = {
+ enable = true;
+ wantedBy = ["multi-user.target"];
+ after = ["network.target"];
+
+ script = ''
+ ${getExe cfg.package}
+ '';
+
+ serviceConfig = {
+ Type = "simple";
+ Restart = "on-failure";
+
+ EnvironmentFile = mkIf (cfg.environmentFile != null) cfg.environmentFile;
+
+ # hardening
+ DynamicUser = true;
+ NoNewPrivileges = true;
+ PrivateDevices = true;
+ PrivateTmp = true;
+ PrivateUsers = true;
+ ProtectClock = true;
+ ProtectControlGroups = true;
+ ProtectHome = true;
+ ProtectHostname = true;
+ ProtectKernelLogs = true;
+ ProtectKernelModules = true;
+ ProtectKernelTunables = true;
+ ProtectSystem = "strict";
+ RestrictNamespaces = "uts ipc pid user cgroup";
+ RestrictSUIDSGID = true;
+ SystemCallArchitectures = "native";
+ SystemCallFilter = [
+ "@system-service"
+ "~@resources"
+ "~@privileged"
+ ];
+ Umask = "0007";
+ };
+ };
+ };
+}