1
1
mirror of https://github.com/LnL7/nix-darwin.git synced 2024-07-14 16:00:36 +03:00

module: add spacebar service

This commit is contained in:
cmacrae 2020-05-14 15:09:40 +01:00
parent c5f7cee0ed
commit 7ebda10e40
4 changed files with 103 additions and 0 deletions

View File

@ -51,6 +51,7 @@
./services/privoxy
./services/redis
./services/skhd
./services/spacebar
./services/synapse-bt.nix
./services/synergy
./services/yabai

View File

@ -0,0 +1,74 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.spacebar;
toSpacebarConfig = opts:
concatStringsSep "\n" (mapAttrsToList
(p: v: "spacebar -m config ${p} ${toString v}") opts);
configFile = mkIf (cfg.config != {} || cfg.extraConfig != "")
"${pkgs.writeScript "spacebarrc" (
(if (cfg.config != {})
then "${toSpacebarConfig cfg.config}"
else "")
+ optionalString (cfg.extraConfig != "") cfg.extraConfig)}";
in
{
options = with types; {
services.spacebar.enable = mkOption {
type = bool;
default = false;
description = "Whether to enable the spacebar spacebar.";
};
services.spacebar.package = mkOption {
type = path;
description = "The spacebar package to use.";
};
services.spacebar.config = mkOption {
type = attrs;
default = {};
example = literalExample ''
{
clock_format = "%R";
background_color = "0xff202020";
foreground_color = "0xffa8a8a8";
}
'';
description = ''
Key/Value pairs to pass to spacebar's 'config' domain, via the configuration file.
'';
};
services.spacebar.extraConfig = mkOption {
type = str;
default = "";
example = literalExample ''
echo "spacebar config loaded..."
'';
description = ''
Extra arbitrary configuration to append to the configuration file.
'';
};
};
config = mkIf (cfg.enable) {
environment.systemPackages = [ cfg.package ];
launchd.user.agents.spacebar = {
serviceConfig.ProgramArguments = [ "${cfg.package}/bin/spacebar" ]
++ optionals (cfg.config != {} || cfg.extraConfig != "") [ "-c" configFile ];
serviceConfig.KeepAlive = true;
serviceConfig.RunAtLoad = true;
serviceConfig.EnvironmentVariables = {
PATH = "${cfg.package}/bin:${config.environment.systemPath}";
};
};
};
}

View File

@ -121,6 +121,7 @@ let
tests.services-offlineimap = makeTest ./tests/services-offlineimap.nix;
tests.services-privoxy = makeTest ./tests/services-privoxy.nix;
tests.services-skhd = makeTest ./tests/services-skhd.nix;
tests.services-spacebar = makeTest ./tests/services-spacebar.nix;
tests.services-synapse-bt = makeTest ./tests/services-synapse-bt.nix;
tests.services-synergy = makeTest ./tests/services-synergy.nix;
tests.services-yabai = makeTest ./tests/services-yabai.nix;

View File

@ -0,0 +1,27 @@
{ config, lib, pkgs, ... }:
with lib;
let
spacebar = pkgs.runCommand "spacebar-0.0.0" {} "mkdir $out";
in
{
services.spacebar.enable = true;
services.spacebar.package = spacebar;
services.spacebar.config = { background_color = "0xff202020"; };
services.spacebar.extraConfig = ''echo "spacebar config loaded..."'';
test = ''
echo >&2 "checking spacebar service in ~/Library/LaunchAgents"
grep "org.nixos.spacebar" ${config.out}/user/Library/LaunchAgents/org.nixos.spacebar.plist
grep "${spacebar}/bin/spacebar" ${config.out}/user/Library/LaunchAgents/org.nixos.spacebar.plist
conf=`sed -En '/<string>-c<\/string>/{n; s/\s+?<\/?string>//g; p;}' \
${config.out}/user/Library/LaunchAgents/org.nixos.spacebar.plist`
echo >&2 "checking config in $conf"
grep "spacebar -m config background_color 0xff202020" $conf
grep "spacebar config loaded..." $conf
'';
}