diff options
| author | Michael Hoang <Enzime@users.noreply.github.com> | 2024-10-24 10:50:04 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-24 10:50:04 +1100 |
| commit | 5f05c2c3d296c358dbdee8591528959d5360c247 (patch) | |
| tree | b125822662a1cb75aeead1b154042c3ed1a51f10 | |
| parent | d99f9ae9fdfbcc36b81d264678bf58004464892e (diff) | |
| parent | 7ebf95a73e3b54e0f9c48f50fde29e96257417ac (diff) | |
Merge pull request #1106 from NickHu/aerospace
module: add aerospace service
| -rw-r--r-- | modules/module-list.nix | 1 | ||||
| -rw-r--r-- | modules/services/aerospace/default.nix | 163 | ||||
| -rw-r--r-- | release.nix | 1 | ||||
| -rw-r--r-- | tests/services-aerospace.nix | 36 |
4 files changed, 201 insertions, 0 deletions
diff --git a/modules/module-list.nix b/modules/module-list.nix index 3280682..6604eb9 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -52,6 +52,7 @@ ./fonts ./launchd ./services/activate-system + ./services/aerospace ./services/autossh.nix ./services/buildkite-agents.nix ./services/chunkwm.nix diff --git a/modules/services/aerospace/default.nix b/modules/services/aerospace/default.nix new file mode 100644 index 0000000..50d47b3 --- /dev/null +++ b/modules/services/aerospace/default.nix @@ -0,0 +1,163 @@ +{ + config, + lib, + pkgs, + ... +}: + +let + cfg = config.services.aerospace; + + format = pkgs.formats.toml { }; + configFile = format.generate "aerospace.toml" cfg.settings; +in + +{ + options = { + services.aerospace = with lib.types; { + enable = lib.mkEnableOption "AeroSpace window manager"; + + package = lib.mkPackageOption pkgs "aerospace" { }; + + settings = lib.mkOption { + type = submodule { + freeformType = format.type; + options = { + start-at-login = lib.mkOption { + type = bool; + default = false; + description = "Do not start AeroSpace at login. (Managed by launchd instead)"; + }; + after-login-command = lib.mkOption { + type = listOf str; + default = [ ]; + description = "Do not use AeroSpace to run commands after login. (Managed by launchd instead)"; + }; + after-startup-command = lib.mkOption { + type = listOf str; + default = [ ]; + description = "Do not use AeroSpace to run commands after startup. (Managed by launchd instead)"; + }; + enable-normalization-flatten-containers = lib.mkOption { + type = bool; + default = true; + description = "Containers that have only one child are \"flattened\"."; + }; + enable-normalization-opposite-orientation-for-nested-containers = lib.mkOption { + type = bool; + default = true; + description = "Containers that nest into each other must have opposite orientations."; + }; + accordion-padding = lib.mkOption { + type = int; + default = 30; + description = "Padding between windows in an accordion container."; + }; + default-root-container-layout = lib.mkOption { + type = enum [ + "tiles" + "accordion" + ]; + default = "tiles"; + description = "Default layout for the root container."; + }; + default-root-container-orientation = lib.mkOption { + type = enum [ + "horizontal" + "vertical" + "auto" + ]; + default = "auto"; + description = "Default orientation for the root container."; + }; + on-window-detected = lib.mkOption { + type = listOf str; + default = [ ]; + description = "Commands to run every time a new window is detected."; + }; + on-focus-changed = lib.mkOption { + type = listOf str; + default = [ ]; + description = "Commands to run every time focused window or workspace changes."; + }; + on-focused-monitor-changed = lib.mkOption { + type = listOf str; + default = [ "move-mouse monitor-lazy-center" ]; + description = "Commands to run every time focused monitor changes."; + }; + exec-on-workspace-change = lib.mkOption { + type = listOf str; + default = [ ]; + example = [ + "/bin/bash" + "-c" + "sketchybar --trigger aerospace_workspace_change FOCUSED=$AEROSPACE_FOCUSED_WORKSPACE" + ]; + description = "Commands to run every time workspace changes."; + }; + key-mapping.preset = lib.mkOption { + type = enum [ + "qwerty" + "dvorak" + ]; + default = "qwerty"; + description = "Keymapping preset."; + }; + }; + }; + default = { }; + example = lib.literalExpression '' + { + gaps = { + outer.left = 8; + outer.bottom = 8; + outer.top = 8; + outer.right = 8; + }; + mode.main.binding = { + alt-h = "focus left"; + alt-j = "focus down"; + alt-k = "focus up"; + alt-l = "focus right"; + }; + } + ''; + description = '' + AeroSpace configuration, see + <link xlink:href="https://nikitabobko.github.io/AeroSpace/guide#configuring-aerospace"/> + for supported values. + ''; + }; + }; + }; + + config = ( + lib.mkIf (cfg.enable) { + assertions = [ + { + assertion = !cfg.settings.start-at-login; + message = "AeroSpace started at login is managed by home-manager and launchd instead of itself via this option."; + } + { + assertion = cfg.settings.after-login-command == [ ]; + message = "AeroSpace will not run these commands as it does not start itself."; + } + { + assertion = cfg.settings.after-startup-command == [ ]; + message = "AeroSpace will not run these commands as it does not start itself."; + } + ]; + environment.systemPackages = [ cfg.package ]; + + launchd.user.agents.aerospace = { + command = + "${cfg.package}/Applications/AeroSpace.app/Contents/MacOS/AeroSpace" + + (lib.optionalString (cfg.settings != { }) " --config-path ${configFile}"); + serviceConfig = { + KeepAlive = true; + RunAtLoad = true; + }; + }; + } + ); +} diff --git a/release.nix b/release.nix index ac0e31a..0d754fc 100644 --- a/release.nix +++ b/release.nix @@ -129,6 +129,7 @@ let tests.services-lorri = makeTest ./tests/services-lorri.nix; tests.services-nix-daemon = makeTest ./tests/services-nix-daemon.nix; tests.sockets-nix-daemon = makeTest ./tests/sockets-nix-daemon.nix; + tests.services-aerospace = makeTest ./tests/services-aerospace.nix; tests.services-dnsmasq = makeTest ./tests/services-dnsmasq.nix; tests.services-eternal-terminal = makeTest ./tests/services-eternal-terminal.nix; tests.services-nix-gc = makeTest ./tests/services-nix-gc.nix; diff --git a/tests/services-aerospace.nix b/tests/services-aerospace.nix new file mode 100644 index 0000000..8cbd292 --- /dev/null +++ b/tests/services-aerospace.nix @@ -0,0 +1,36 @@ +{ config, pkgs, ... }: + +let + aerospace = pkgs.runCommand "aerospace-0.0.0" { } "mkdir $out"; +in + +{ + services.aerospace.enable = true; + services.aerospace.package = aerospace; + services.aerospace.settings = { + gaps = { + outer.left = 8; + outer.bottom = 8; + outer.top = 8; + outer.right = 8; + }; + mode.main.binding = { + alt-h = "focus left"; + alt-j = "focus down"; + alt-k = "focus up"; + alt-l = "focus right"; + }; + }; + + test = '' + echo >&2 "checking aerospace service in ~/Library/LaunchAgents" + grep "org.nixos.aerospace" ${config.out}/user/Library/LaunchAgents/org.nixos.aerospace.plist + grep "${aerospace}/Applications/AeroSpace.app/Contents/MacOS/AeroSpace" ${config.out}/user/Library/LaunchAgents/org.nixos.aerospace.plist + + conf=`sed -En 's/^[[:space:]]*<string>.*--config-path (.*)<\/string>$/\1/p' \ + ${config.out}/user/Library/LaunchAgents/org.nixos.aerospace.plist` + + echo >&2 "checking config in $conf" + if [ `cat $conf | wc -l` -eq "27" ]; then echo "aerospace.toml config correctly contains 27 lines"; else return 1; fi + ''; +} |
