From 9edd2f7f3ba80a280436ffc5e306fa3ffd93e622 Mon Sep 17 00:00:00 2001 From: Johan Date: Thu, 25 Apr 2024 14:06:31 +0200 Subject: [PATCH] nix: enable creating config file via home-manager (#109) --- nix/README.md | 3 +++ nix/hm-module.nix | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/nix/README.md b/nix/README.md index 3ceebae..26b14a6 100644 --- a/nix/README.md +++ b/nix/README.md @@ -34,6 +34,9 @@ enable lan-mouse enable = true; # systemd = false; # package = inputs.lan-mouse.packages.${pkgs.stdenv.hostPlatform.system}.default + # Optional configuration in nix syntax, see config.toml for available options + # settings = { }; + }; }; } diff --git a/nix/hm-module.nix b/nix/hm-module.nix index 49b6cf2..50bf13e 100644 --- a/nix/hm-module.nix +++ b/nix/hm-module.nix @@ -7,6 +7,7 @@ self: { with lib; let cfg = config.programs.lan-mouse; defaultPackage = self.packages.${pkgs.stdenv.hostPlatform.system}.default; + tomlFormat = pkgs.formats.toml {}; in { options.programs.lan-mouse = with types; { enable = mkEnableOption "Whether or not to enable lan-mouse."; @@ -25,6 +26,17 @@ in { default = pkgs.stdenv.isLinux; description = "Whether to enable to systemd service for lan-mouse."; }; + settings = lib.mkOption { + inherit (tomlFormat) type; + default = {}; + example = builtins.fromTOML (builtins.readFile (self + /config.toml)); + description = '' + Optional configuration written to {file}`$XDG_CONFIG_HOME/lan-mouse/config.toml`. + + See for + available options and documentation. + ''; + }; }; config = mkIf cfg.enable { @@ -46,5 +58,9 @@ in { home.packages = [ cfg.package ]; + + xdg.configFile."lan-mouse/config.toml" = lib.mkIf (cfg.settings != {}) { + source = tomlFormat.generate "config.toml" cfg.settings; + }; }; }