Skip to content

Commit

Permalink
darwin configuration GA
Browse files Browse the repository at this point in the history
Signed-off-by: iosmanthus <[email protected]>
  • Loading branch information
iosmanthus committed Dec 1, 2024
1 parent db2af57 commit 4dcbdb3
Show file tree
Hide file tree
Showing 41 changed files with 766 additions and 327 deletions.
112 changes: 112 additions & 0 deletions darwin/iosmanthus-macmini/aerospace/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{ pkgs, ... }:
let
nextAppWin = pkgs.writers.writePython3 "nextAppWin" {
libraries = [ ];
flakeIgnore = [ "E501" ];
} (builtins.readFile ./next_app_win.py);
searchWin = pkgs.writers.writePython3 "searchWin" {
libraries = [ ];
flakeIgnore = [ "E501" ];
} (builtins.readFile ./search_win.py);
in
{
services.aerospace = {
enable = true;
settings = {
enable-normalization-flatten-containers = false;
enable-normalization-opposite-orientation-for-nested-containers = false;
default-root-container-layout = "accordion";
exec = {
inherit-env-vars = true;
};
on-window-detected = [
# Termainal
{
"if".app-id = "net.kovidgoyal.kitty";
run = [ "move-node-to-workspace 1" ];
}
# Browsers
{
"if".app-id = "org.mozilla.firefox";
run = [ "move-node-to-workspace 1" ];
}
# Mail
{
"if".app-id = "com.apple.mail";
run = [ "move-node-to-workspace 3" ];
}
# Music
{
"if".app-id = "com.apple.Music";
run = [ "move-node-to-workspace 4" ];
}
# IMs
{
"if".app-id = "ru.keepcoder.Telegram";
run = [ "move-node-to-workspace 2" ];
}
{
"if".app-id = "com.hnc.Discord";
run = [ "move-node-to-workspace 2" ];
}
{
"if".app-id = "com.tencent.xinWeChat";
run = [ "move-node-to-workspace 2" ];
}
{
"if".app-id = "com.electron.lark";
run = [ "move-node-to-workspace 2" ];
}
# Notes
{
"if".app-id = "com.electron.logseq";
run = [ "move-node-to-workspace 5" ];
}
];
mode.main.binding = {
alt-s = "layout v_accordion"; # "layout stacking" in i3
alt-w = "layout h_accordion"; # "layout tabbed" in i3
alt-e = "layout tiles horizontal vertical"; # "layout toggle split" in i3
alt-shift-space = "layout floating tiling"; # 'floating toggle' in i3

alt-v = "split vertical";
alt-shift-v = "split horizontal";

alt-f = "fullscreen";
alt-shift-f = "macos-native-fullscreen";
alt-q = "close --quit-if-last-window";

alt-h = "focus left";
alt-j = "focus down";
alt-k = "focus up";
alt-l = "focus right";
alt-shift-h = "move left";
alt-shift-j = "move down";
alt-shift-k = "move up";
alt-shift-l = "move right";

alt-leftSquareBracket = "exec-and-forget ${nextAppWin} prev";
alt-rightSquareBracket = "exec-and-forget ${nextAppWin} next";
alt-p = "exec-and-forget ${searchWin}";

alt-1 = "workspace 1";
alt-2 = "workspace 2";
alt-3 = "workspace 3";
alt-4 = "workspace 4";
alt-5 = "workspace 5";
alt-shift-1 = "move-node-to-workspace 1";
alt-shift-2 = "move-node-to-workspace 2";
alt-shift-3 = "move-node-to-workspace 3";
alt-shift-4 = "move-node-to-workspace 4";
alt-shift-5 = "move-node-to-workspace 5";

alt-tab = "workspace-back-and-forth";

alt-b = "exec-and-forget open /Applications/Firefox.app";
alt-c = "exec-and-forget open ${pkgs.vscode}/Applications/Visual\\ Studio\\ Code.app";
alt-enter = "exec-and-forget open ${pkgs.kitty}/Applications/kitty.app";
alt-m = "exec-and-forget open /System/Applications/Music.app";
};
};
};
}
38 changes: 38 additions & 0 deletions darwin/iosmanthus-macmini/aerospace/next_app_win.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import subprocess
import sys
import json


def get_focused_window():
return json.loads(
subprocess.check_output(
["aerospace", "list-windows", "--focused", "--json"]
).decode("utf-8")
)[0]


def get_all_windows_in_workspace():
return json.loads(
subprocess.check_output(
["aerospace", "list-windows", "--workspace", "focused", "--json"]
).decode("utf-8")
)


def move_to_window(window_id):
subprocess.run(["aerospace", "focus", "--window-id", str(window_id)])


if __name__ == "__main__":
direction = 1
if sys.argv[1] == "prev":
direction = -1
current_win = get_focused_window()
all_win = get_all_windows_in_workspace()
app_wins = list(filter(lambda w: w["app-name"] == current_win["app-name"], all_win))
next_idx = 0
for idx, win in enumerate(app_wins):
if win["window-id"] == current_win["window-id"]:
next_idx = (idx + direction) % len(app_wins)
break
move_to_window(app_wins[next_idx]["window-id"])
20 changes: 20 additions & 0 deletions darwin/iosmanthus-macmini/aerospace/search_win.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import subprocess
import json

if __name__ == "__main__":
wins = json.loads(
subprocess.check_output(
["aerospace", "list-windows", "--all", "--json"]
).decode("utf-8")
)
output = ""
for idx, win in enumerate(wins):
output += f'{idx} | {win["app-name"]} {win['window-title']}\n'

choose = subprocess.Popen(["choose"], stdin=subprocess.PIPE, stdout=subprocess.PIPE)

selected, _ = choose.communicate(bytes(output, "utf-8"))
selected_idx = int(selected.decode("utf-8").split("|")[0].strip())
subprocess.run(
["aerospace", "focus", "--window-id", str(wins[selected_idx]["window-id"])]
)
81 changes: 30 additions & 51 deletions darwin/iosmanthus-macmini/default.nix
Original file line number Diff line number Diff line change
@@ -1,23 +1,42 @@
{
config,
pkgs,
hostName,
...
}:
let
hostName = "iosmanthus-macmini";
in
{
imports = [
./aerospace
./homebrew
./system
];

sops.age.keyFile = "${config.admin.home}/.config/sops/age/keys.txt";

environment.variables = {
SOPS_AGE_KEY_FILE = config.sops.age.keyFile;
};

nixpkgs = {
hostPlatform = "aarch64-darwin";
config = {
allowUnfree = true;
};
};

networking = {
knownNetworkServices = [
"Wi-Fi"
"Ethernet Adaptor"
"Thunderbolt Ethernet"
];
dns = [
"223.5.5.5"
"114.114.114.114"
"119.29.29.29"
];
};

nix = {
package = pkgs.nixVersions.nix_2_22;
extraOptions = ''
Expand All @@ -35,62 +54,22 @@ in
};
};

system = {
stateVersion = 5;
# activationScripts are executed every time you boot the system or run `nixos-rebuild` / `darwin-rebuild`.
activationScripts.postUserActivation.text = ''
# activateSettings -u will reload the settings from the database and apply them to the current session,
# so we do not need to logout and login again to make the changes take effect.
/System/Library/PrivateFrameworks/SystemAdministration.framework/Resources/activateSettings -u
'';
defaults = {
NSGlobalDomain = {
KeyRepeat = 2;
ApplePressAndHoldEnabled = false;
AppleInterfaceStyle = "Dark";

"com.apple.swipescrolldirection" = false;
};
WindowManager = {
GloballyEnabled = true;
AppWindowGroupingBehavior = false;
};
CustomUserPreferences = {
"com.apple.HIToolbox" = {
AppleDictationAutoEnable = false;
};
"com.apple.assistant.support" = {
"Dictation Enabled" = false;
};
};
smb = {
NetBIOSName = hostName;
};
dock = {
autohide = true;
persistent-apps = [
"/System/Applications/Launchpad.app"
"/System/Applications/Music.app"

"/Applications/Firefox.app"
"${pkgs.vscode}/Applications/Visual Studio Code.app"
"/Applications/Telegram.app"
"/Applications/SFM.app"
];
};
};
};

programs.zsh.enable = true;
networking = rec {
networking = {
inherit hostName;
computerName = hostName;
};

users.users.${config.admin.name} = {
inherit (config.admin) shell home;
description = config.admin.name;
openssh.authorizedKeys.keys = [ config.admin.sshPubKey ]; };
openssh.authorizedKeys.keys = [ config.admin.sshPubKey ];
};

nix.settings.trusted-users = [ config.admin.name ];

services.sing-box = {
enable = true;
configPath = config.sops.secrets.sing-box.path;
};
}
11 changes: 11 additions & 0 deletions darwin/iosmanthus-macmini/homebrew/default.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
{
config,
lib,
...
}:
{
environment.systemPath = lib.optionals config.homebrew.enable [
config.homebrew.brewPrefix
];

homebrew = {
enable = true;
caskArgs.no_quarantine = true;
global.brewfile = true;
masApps = { };
brews = [
"choose-gui"
];
casks = [
"discord"
"feishu"
"firefox"
"jetbrains-toolbox"
"logi-options+"
"logseq"
"maccy"
"sfm"
"squirrel"
Expand Down
Loading

0 comments on commit 4dcbdb3

Please sign in to comment.