From 3bf16c0fd141c28312be52945d1543f9ce557bb1 Mon Sep 17 00:00:00 2001 From: Philipp Mildenberger Date: Sun, 5 Jun 2022 13:39:26 +0200 Subject: [PATCH] udiskie: add option settings Adds option settings, which writes settings to .config/udiskie/config.yml. Note, the option takes precedence against other options like notify, automount or tray if they are configured in settings.program_options. --- modules/services/udiskie.nix | 57 ++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/modules/services/udiskie.nix b/modules/services/udiskie.nix index 331e65ff..d445178e 100644 --- a/modules/services/udiskie.nix +++ b/modules/services/udiskie.nix @@ -4,17 +4,11 @@ with lib; let - cfg = config.services.udiskie; + mergeSets = sets: lists.fold attrsets.recursiveUpdate { } sets; - commandArgs = concatStringsSep " " (map (opt: "-" + opt) [ - (if cfg.automount then "a" else "A") - (if cfg.notify then "n" else "N") - ({ - always = "t"; - auto = "s"; - never = "T"; - }.${cfg.tray}) - ] ++ optional config.xsession.preferStatusNotifierItems "--appindicator"); + yaml = pkgs.formats.yaml { }; + + cfg = config.services.udiskie; in { meta.maintainers = [ maintainers.rycee ]; @@ -33,6 +27,27 @@ in { services.udiskie = { enable = mkEnableOption "udiskie mount daemon"; + settings = mkOption { + type = yaml.type; + default = { }; + example = literalExpression '' + { + program_options = { + udisks_version = 2; + tray = true; + }; + icon_names.media = [ "media-optical" ]; + } + ''; + description = '' + Configuration written to + $XDG_CONFIG_HOME/udiskie/config.toml. + + See + for the full list of options. + ''; + }; + automount = mkOption { type = types.bool; default = true; @@ -74,6 +89,23 @@ in { }; config = mkIf config.services.udiskie.enable { + xdg.configFile."udiskie/config.yml".source = + yaml.generate "udiskie-config.yml" (mergeSets [ + { + program_options = { + automount = cfg.automount; + tray = if cfg.tray == "always" then + true + else if cfg.tray == "never" then + false + else + "auto"; + notify = cfg.notify; + }; + } + cfg.settings + ]); + systemd.user.services.udiskie = { Unit = { Description = "udiskie mount daemon"; @@ -82,9 +114,10 @@ in { PartOf = [ "graphical-session.target" ]; }; - Service = { ExecStart = "${pkgs.udiskie}/bin/udiskie ${commandArgs}"; }; + Service.ExecStart = toString ([ "${pkgs.udiskie}/bin/udiskie" ] + ++ optional config.xsession.preferStatusNotifierItems "--appindicator"); - Install = { WantedBy = [ "graphical-session.target" ]; }; + Install.WantedBy = [ "graphical-session.target" ]; }; }; }