From e8c09de382d3d58577cbd5e9d8dc99cdcc294394 Mon Sep 17 00:00:00 2001 From: bandithedoge Date: Tue, 21 Jul 2026 18:41:13 +0200 Subject: [PATCH] modules/anyrun: init --- modules/anyrun/check.nix | 13 +++++ modules/anyrun/module.nix | 104 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 modules/anyrun/check.nix create mode 100644 modules/anyrun/module.nix diff --git a/modules/anyrun/check.nix b/modules/anyrun/check.nix new file mode 100644 index 0000000..54dd7de --- /dev/null +++ b/modules/anyrun/check.nix @@ -0,0 +1,13 @@ +{ pkgs, self }: +let + anyrunWrapped = + (self.wrapperModules.anyrun.apply { + inherit pkgs; + "config.ron".path = pkgs.anyrun + "/share/doc/anyrun/examples/config.ron"; + "style.css".path = pkgs.anyrun + "/share/doc/anyrun/examples/style.css"; + }).wrapper; +in +pkgs.runCommand "anyrun-test" { nativeBuildInputs = [ anyrunWrapped ]; } '' + anyrun -V | grep ${anyrunWrapped.version} + touch $out +'' diff --git a/modules/anyrun/module.nix b/modules/anyrun/module.nix new file mode 100644 index 0000000..c781ede --- /dev/null +++ b/modules/anyrun/module.nix @@ -0,0 +1,104 @@ +{ + config, + lib, + wlib, + ... +}: +{ + imports = [ wlib.modules.systemd ]; + + options = + let + fileType = wlib.types.file config.pkgs; + in + { + "config.ron" = lib.mkOption { + type = fileType; + default.content = ""; + }; + + "style.css" = lib.mkOption { + type = fileType; + default.content = ""; + }; + + extraConfigFiles = lib.mkOption { + type = lib.types.attrsOf fileType; + default = { }; + description = "Additional files placed in the configuration directory"; + example = { + "applications.ron".content = '' + Config( + desktop_actions: false, + max_entries: 5, + ) + ''; + }; + }; + + plugins = lib.mkOption { + type = with lib.types; listOf path; + default = [ ]; + description = "List of shared objects that export Anyrun plugins. Overrides the `plugins` field in `config.ron`."; + example = lib.literalExpression '' + [ + "$\{pkgs.anyrun}/lib/libapplications.so" + ] + ''; + }; + }; + + config = + let + configDir = toString ( + config.pkgs.linkFarm "anyrun-config" ( + let + extraConfigFiles = lib.mapAttrsToList (name: file: { + inherit name; + inherit (file) path; + }) config.extraConfigFiles; + in + [ + { + name = "config.ron"; + inherit (config."config.ron") path; + } + { + name = "style.css"; + inherit (config."style.css") path; + } + ] + ++ extraConfigFiles + ) + ); + in + { + package = config.pkgs.anyrun; + + args = [ + "--config-dir" + configDir + ] + ++ lib.flatten ( + map (plugin: [ + "--plugins" + plugin + ]) config.plugins + ); + + systemd = { + description = "Anyrun daemon"; + serviceConfig = { + Type = "simple"; + ExecStart = "${config.exePath} --config-dir ${configDir} daemon"; + Restart = "on-failure"; + KillMode = "process"; + }; + }; + + meta = { + maintainers = [ lib.maintainers.bandithedoge ]; + platforms = lib.platforms.linux; + }; + }; +}