From e42daf3404ffb1fe31efbf582c8d68fe66c0d9a2 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Wed, 19 Jul 2023 07:38:08 +0800 Subject: [PATCH] services/distant: init home-manager module --- modules/home-manager/default.nix | 1 + modules/home-manager/services/distant.nix | 65 +++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 modules/home-manager/services/distant.nix diff --git a/modules/home-manager/default.nix b/modules/home-manager/default.nix index 7e374e19..7f1de8ae 100644 --- a/modules/home-manager/default.nix +++ b/modules/home-manager/default.nix @@ -10,6 +10,7 @@ let ./programs/pop-launcher.nix ./services/archivebox.nix ./services/bleachbit.nix + ./services/distant.nix ./services/gallery-dl.nix ./services/plover.nix ./services/yt-dlp.nix diff --git a/modules/home-manager/services/distant.nix b/modules/home-manager/services/distant.nix new file mode 100644 index 00000000..368d992f --- /dev/null +++ b/modules/home-manager/services/distant.nix @@ -0,0 +1,65 @@ +{ config, options, lib, pkgs, ... }: + +let + cfg = config.services.distant; + + settingsFormat = pkgs.formats.toml {}; + settingsFile = settingsFormat.generate "distant-settings-${config.home.username}" cfg.settings; + + hasCustomSocketPath = cfg.settings.manager.unix_socket != null; + defaultSocketPath = "%t/distant/%u.distant.sock"; +in +{ + options.services.distant = { + enable = lib.mkEnableOption "Distant manager"; + + package = lib.mkOption { + description = lib.mkDoc "The package containing the `distant` executable."; + type = lib.types.package; + default = pkgs.distant; + defaultText = "pkgs.distant"; + }; + + settings = lib.mkOption { + description = lib.mkDoc '' + The configuration settings to be passed to the service. + ''; + types = settingsFormat.type; + default = { }; + defaultText = "{}"; + example = lib.literalExpression '' + { + manager.unix_socket = "/path/to/socket.sock"; + } + ''; + }; + }; + + config = lib.mkIf cfg.enable { + systemd.user.services.distant-manager = { + Unit = { + Description = "Distant manager daemon"; + Documentation = [ "https://distant.dev" ]; + }; + + Service = { + ExecStart = '' + ${lib.getBin cfg.package}/bin/distant manager listen --config ${settingsFile} ${lib.optionalString (!hasCustomSocketPath) "--unix-socket ${defaultSocketPath}"} + ''; + Restart = "on-failure"; + StandardInput = "socket"; + }; + + Install.WantedBy = "default.target"; + }; + + systemd.user.sockets.distant-manager = { + Unit = { + Description = "Distant manager daemon"; + Documentation = [ "https://distant.dev" ]; + }; + + Socket.ListenStream = if hasCustomSocketPath then cfg.settings.manager.unix_socket else defaultSocketPath; + }; + }; +}