Compare commits

..

3 Commits

Author SHA1 Message Date
Oystein Kristoffer Tveit 9934b11766
nix: use unwrapped program by default in module 2024-10-20 23:06:32 +02:00
Oystein Kristoffer Tveit cfb6bbd7a7
default.nix: better source filtering 2024-10-20 23:06:32 +02:00
Oystein Kristoffer Tveit b1f8cf9ba2
systemd integration
- Add watchdog timeout support
- Add native journald logging support
- Add application state notifications
- Add verbosity flag
2024-10-20 23:06:32 +02:00
4 changed files with 11 additions and 4 deletions

View File

@ -4,6 +4,7 @@
, rustPlatform
, makeWrapper
, mpv
, wrapped ? false
}:
rustPlatform.buildRustPackage rec {
@ -36,7 +37,7 @@ rustPlatform.buildRustPackage rec {
};
};
postInstall = ''
postInstall = lib.optionalString wrapped ''
wrapProgram $out/bin/greg-ng \
--prefix PATH : '${lib.makeBinPath [ mpv ]}'
'';

View File

@ -35,7 +35,7 @@
apps = forAllSystems (system: pkgs: _: {
default = self.apps.${system}.greg-ng;
greg-ng = let
package = self.packages.${system}.greg-ng;
package = self.packages.${system}.greg-ng-wrapped;
in {
type = "app";
program = lib.getExe package;
@ -63,6 +63,9 @@
packages = forAllSystems (system: pkgs: _: {
default = self.packages.${system}.greg-ng;
greg-ng = pkgs.callPackage ./default.nix { };
greg-ng-wrapped = pkgs.callPackage ./default.nix {
wrapped = true;
};
});
} // {
nixosModules.default = ./module.nix;

View File

@ -109,7 +109,8 @@ in
Restart = "always";
RestartSec = 3;
WatchdogSec = 15;
WatchdogSec = lib.mkDefault 15;
TimeoutStartSec = lib.mkDefault 30;
RestrictAddressFamilies = [ "AF_UNIX" "AF_INET" "AF_INET6" ];
AmbientCapabilities = [ "" ];

View File

@ -89,6 +89,8 @@ async fn setup_systemd_watchdog_thread() -> anyhow::Result<()> {
async fn shutdown(mpv: Mpv, proc: Option<tokio::process::Child>) {
log::info!("Shutting down");
sd_notify::notify(false, &[sd_notify::NotifyState::Stopping])
.unwrap_or_else(|e| log::warn!("Failed to notify systemd that the service is stopping: {}", e));
mpv.disconnect()
.await
@ -167,7 +169,7 @@ async fn main() -> anyhow::Result<()> {
};
if systemd_mode {
match sd_notify::notify(true, &[sd_notify::NotifyState::Ready])
match sd_notify::notify(false, &[sd_notify::NotifyState::Ready])
.context("Failed to notify systemd that the service is ready")
{
Ok(_) => log::trace!("Notified systemd that the service is ready"),