136 lines
3.4 KiB
Nix
136 lines
3.4 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}:
|
|
with lib; let
|
|
cfg = config.services.hyprmonitors;
|
|
|
|
hyprmonitors = pkgs.rustPlatform.buildRustPackage {
|
|
pname = "hyprmonitors";
|
|
version = "0.1.0";
|
|
|
|
src = ./.;
|
|
|
|
cargoLock = {
|
|
lockFile = ./Cargo.lock;
|
|
};
|
|
|
|
nativeBuildInputs = with pkgs; [
|
|
pkg-config
|
|
];
|
|
|
|
buildInputs = with pkgs; [
|
|
openssl
|
|
];
|
|
|
|
meta = with lib; {
|
|
description = "Hyprland monitor control server";
|
|
homepage = "https://github.com/your-username/hyprmonitors";
|
|
license = licenses.mit;
|
|
maintainers = [];
|
|
platforms = platforms.linux;
|
|
};
|
|
};
|
|
in {
|
|
options.services.hyprmonitors = {
|
|
enable = mkEnableOption "Hyprland monitor control server";
|
|
|
|
package = mkOption {
|
|
type = types.package;
|
|
default = hyprmonitors;
|
|
defaultText = literalExpression "pkgs.hyprmonitors";
|
|
description = "The hyprmonitors package to use.";
|
|
};
|
|
|
|
host = mkOption {
|
|
type = types.str;
|
|
default = "127.0.0.1";
|
|
description = "Host address to bind the server to.";
|
|
};
|
|
|
|
port = mkOption {
|
|
type = types.port;
|
|
default = 3000;
|
|
description = "Port to bind the server to.";
|
|
};
|
|
|
|
logLevel = mkOption {
|
|
type = types.enum ["error" "warn" "info" "debug" "trace"];
|
|
default = "info";
|
|
description = "Log level for the server.";
|
|
};
|
|
|
|
environmentVariables = mkOption {
|
|
type = types.attrsOf types.str;
|
|
default = {};
|
|
example = {
|
|
HYPRLAND_INSTANCE_SIGNATURE = "your-signature";
|
|
};
|
|
description = "Additional environment variables to set for the service.";
|
|
};
|
|
|
|
settings = mkOption {
|
|
type = types.attrs;
|
|
default = {};
|
|
example = {
|
|
cors_origins = ["http://localhost:8080"];
|
|
timeout_seconds = 30;
|
|
};
|
|
description = "Additional configuration settings (if supported by future versions).";
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
assertions = [
|
|
{
|
|
assertion = config.wayland.windowManager.hyprland.enable or false;
|
|
message = "hyprmonitors requires Hyprland to be enabled. Set wayland.windowManager.hyprland.enable = true;";
|
|
}
|
|
];
|
|
|
|
systemd.user.services.hyprmonitors = {
|
|
Unit = {
|
|
Description = "Hyprland Monitor Control Server";
|
|
Documentation = "https://github.com/your-username/hyprmonitors";
|
|
After = ["graphical-session.target" "hyprland-session.target"];
|
|
Wants = ["graphical-session.target"];
|
|
PartOf = ["hyprland-session.target"];
|
|
};
|
|
|
|
Service = {
|
|
Type = "simple";
|
|
ExecStart = "${cfg.package}/bin/hyprmonitors";
|
|
Restart = "always";
|
|
RestartSec = 5;
|
|
|
|
# Environment variables
|
|
Environment =
|
|
[
|
|
"RUST_LOG=${cfg.logLevel}"
|
|
"HYPRMONITORS_HOST=${cfg.host}"
|
|
"HYPRMONITORS_PORT=${toString cfg.port}"
|
|
"HYPRMONITORS_LOG_LEVEL=${cfg.logLevel}"
|
|
]
|
|
++ (mapAttrsToList (name: value: "${name}=${value}") cfg.environmentVariables);
|
|
|
|
# Security settings
|
|
NoNewPrivileges = true;
|
|
PrivateTmp = true;
|
|
ProtectHome = "read-only";
|
|
ProtectSystem = "strict";
|
|
ReadWritePaths = ["/tmp"];
|
|
|
|
# Resource limits
|
|
LimitNOFILE = 1024;
|
|
MemoryMax = "128M";
|
|
};
|
|
|
|
Install = {
|
|
WantedBy = ["hyprland-session.target"];
|
|
};
|
|
};
|
|
};
|
|
}
|