This commit is contained in:
Robin Appelman 2025-06-09 18:05:39 +02:00
commit d4ce62a42c
19 changed files with 2724 additions and 1988 deletions

69
nix/module.nix Normal file
View file

@ -0,0 +1,69 @@
{
config,
lib,
pkgs,
...
}:
with lib; let
cfg = config.services.shortcutd;
in {
options.services.shortcutd = {
enable = mkEnableOption "Enables the shortcutd service";
log = mkOption rec {
type = types.str;
default = "WARN";
example = "INFO";
description = "log level";
};
};
config = mkIf cfg.enable {
services.dbus.packages = [self.packages.${pkgs.system}.default];
users.users.shortcutd = {
isSystemUser = true;
group = "shortcutd";
};
users.groups.shortcutd = {};
systemd.services."shortcutd" = {
wantedBy = ["multi-user.target"];
environment = {
RUST_LOG = cfg.log;
};
serviceConfig = let
pkg = self.packages.${pkgs.system}.default;
in {
User = "shortcutd";
Restart = "on-failure";
ExecStart = "${pkg}/bin/shortcutd";
PrivateTmp = true;
ProtectSystem = "strict";
ProtectHome = true;
NoNewPrivileges = true;
CapabilityBoundingSet = true;
ProtectKernelLogs = true;
ProtectControlGroups = true;
SystemCallArchitectures = "native";
ProtectKernelModules = true;
RestrictNamespaces = true;
MemoryDenyWriteExecute = true;
ProtectHostname = true;
LockPersonality = true;
ProtectKernelTunables = true;
RestrictRealtime = true;
SystemCallFilter = ["@system-service" "~@resources" "~@privileged"];
RestrictAddressFamilies = ["AF_UNIX"];
IPAddressDeny = "any";
PrivateUsers = true;
RestrictSUIDSGID = true;
PrivateNetwork = true;
UMask = "0077";
SupplementaryGroups = ["input"];
};
};
};
}

3
nix/overlay.nix Normal file
View file

@ -0,0 +1,3 @@
final: prev: {
shortcutd = final.callPackage ./package.nix {};
}

27
nix/package.nix Normal file
View file

@ -0,0 +1,27 @@
{
rustPlatform,
lib,
}: let
inherit (lib.sources) sourceByRegex;
inherit (builtins) fromTOML readFile;
in
rustPlatform.buildRustPackage rec {
pname = "shortcutd";
version = (fromTOML (readFile ../server/Cargo.toml)).package.version;
src = sourceByRegex ../server ["Cargo.*" "(src)(/.*)?"];
postPatch = ''
cp ${../Cargo.lock} Cargo.lock
chmod 0755 Cargo.lock
'';
postInstall = ''
mkdir -p $out/etc/dbus-1/system.d/
cp ${../nixos-nl.icewind.shortcutd.conf} $out/etc/dbus-1/system.d/nl.icewind.shortcutd.conf
'';
cargoLock = {
lockFile = ../Cargo.lock;
};
}