Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

darwin configs #3

Merged
merged 5 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ ... }:
{ hostName, ... }:
{
imports = [
./atuin
Expand All @@ -19,7 +19,7 @@
virtualisation.docker.enable = true;

services.self-hosted.o11y = {
hostName = "aws-lightsail-0";
inherit hostName;
enable = true;
};

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ ... }:
{ hostName, ... }:
{
imports = [
./caddy
Expand All @@ -8,8 +8,8 @@
virtualisation.docker.enable = false;

services.self-hosted.o11y = {
inherit hostName;
enable = true;
hostName = "gcp-instance-0";
};

services.self-hosted.cloud.sing-box.enable = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{ config, ... }:
{ config, hostName, ... }:
{
virtualisation.docker.enable = true;

services.self-hosted.o11y = {
inherit hostName;
enable = true;
hostName = "gcp-instance-2";
};

services.self-hosted.cloud.sing-box = {
Expand Down
112 changes: 112 additions & 0 deletions bastions/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 bastions/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 bastions/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"])]
)
75 changes: 75 additions & 0 deletions bastions/iosmanthus-macmini/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
config,
pkgs,
hostName,
...
}:
{
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 = ''
experimental-features = nix-command flakes
keep-going = true
download-attempts = 2
connect-timeout = 5
'';
optimise = {
automatic = true;
};
gc = {
automatic = true;
options = "--delete-older-than 2d";
};
};

programs.zsh.enable = true;
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 ];
};

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

services.sing-box = {
enable = true;
configPath = config.sops.secrets.sing-box.path;
};
}
33 changes: 33 additions & 0 deletions bastions/iosmanthus-macmini/homebrew/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
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"
"telegram"
"wechat"
];
};
}
Loading
Loading