summaryrefslogtreecommitdiff
path: root/hosts/mac
diff options
context:
space:
mode:
Diffstat (limited to 'hosts/mac')
-rw-r--r--hosts/mac/Karabiner-DriverKit-VirtualHIDDevice/default.nix18
-rw-r--r--hosts/mac/kmonad-daemon-shim/default.nix18
-rw-r--r--hosts/mac/kmonad-daemon-shim/main.c23
-rw-r--r--hosts/mac/m1mba/configuration.nix18
-rw-r--r--hosts/mac/m1mba/keyboard.nix53
-rw-r--r--hosts/mac/m1mba/mac.nix12
-rw-r--r--hosts/mac/m1mba/pkgs.nix68
-rw-r--r--hosts/mac/m1mba/services.nix11
-rw-r--r--hosts/mac/m1mba/users.nix43
-rw-r--r--hosts/mac/mac.nix12
-rw-r--r--hosts/mac/yabai/0001-mouse-follows-swap.patch31
-rw-r--r--hosts/mac/yabai/default.nix5
12 files changed, 312 insertions, 0 deletions
diff --git a/hosts/mac/Karabiner-DriverKit-VirtualHIDDevice/default.nix b/hosts/mac/Karabiner-DriverKit-VirtualHIDDevice/default.nix
new file mode 100644
index 0000000..c08f415
--- /dev/null
+++ b/hosts/mac/Karabiner-DriverKit-VirtualHIDDevice/default.nix
@@ -0,0 +1,18 @@
+{ cpio, Karabiner-DriverKit-VirtualHIDDevice-src, stdenv, xar }:
+
+stdenv.mkDerivation {
+ pname = "Karabiner-DriverKit-VirtualHIDDevice";
+ version = "2.1.0";
+ src = Karabiner-DriverKit-VirtualHIDDevice-src + "/dist/Karabiner-DriverKit-VirtualHIDDevice-2.1.0.pkg";
+ buildInputs = [ cpio xar ];
+ unpackPhase = ''
+ xar -xf $src
+ mv Payload Payload.gz
+ gzip -d Payload.gz
+ mkdir extracted && cd extracted && cpio -i < ../Payload
+ '';
+ dontBuild = true;
+ installPhase = ''
+ cp -r . $out
+ '';
+}
diff --git a/hosts/mac/kmonad-daemon-shim/default.nix b/hosts/mac/kmonad-daemon-shim/default.nix
new file mode 100644
index 0000000..2e53f78
--- /dev/null
+++ b/hosts/mac/kmonad-daemon-shim/default.nix
@@ -0,0 +1,18 @@
+{ Karabiner-DriverKit-VirtualHIDDevice, stdenv }:
+
+stdenv.mkDerivation {
+ pname = "kmonad-daemon-shim";
+ version = "0.1.0";
+ src = ./.;
+ patchPhase = ''
+ substituteInPlace main.c \
+ --subst-var-by client "${Karabiner-DriverKit-VirtualHIDDevice}/Library/Application Support/org.pqrs/Karabiner-DriverKit-VirtualHIDDevice/Applications/Karabiner-DriverKit-VirtualHIDDeviceClient.app/Contents/MacOS/Karabiner-DriverKit-VirtualHIDDeviceClient"
+ '';
+ buildPhase = ''
+ cc main.c -o kmonad-daemon-shim
+ '';
+ installPhase = ''
+ mkdir -p $out/bin
+ cp kmonad-daemon-shim $out/bin
+ '';
+}
diff --git a/hosts/mac/kmonad-daemon-shim/main.c b/hosts/mac/kmonad-daemon-shim/main.c
new file mode 100644
index 0000000..a9f0596
--- /dev/null
+++ b/hosts/mac/kmonad-daemon-shim/main.c
@@ -0,0 +1,23 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+
+char *const kdv_client[] = {"@client@"};
+
+int main(int argc, char *argv[]) {
+ int r = fork();
+ if (r < 0) {
+ perror("kmonad-service-shim: fork");
+ return 1;
+ } else if (r == 0) {
+ r = execvp(kdv_client[0], kdv_client);
+ } else {
+ // To give time for kdv-client to start
+ sleep(1);
+ r = execvp("kmonad", argv);
+ };
+ if (r < 0) {
+ perror("kmonad-service-shim: execvp");
+ return 1;
+ }
+}
diff --git a/hosts/mac/m1mba/configuration.nix b/hosts/mac/m1mba/configuration.nix
new file mode 100644
index 0000000..373f781
--- /dev/null
+++ b/hosts/mac/m1mba/configuration.nix
@@ -0,0 +1,18 @@
+{...}: {
+ imports = [
+ ../../base.nix
+ ../mac.nix
+ ./users.nix
+ ./pkgs.nix
+ ];
+
+ # Auto upgrade nix package and the daemon service.
+ services.nix-daemon.enable = true;
+ # nix.package = pkgs.nix;
+ # Used for backwards compatibility, please read the changelog before changing.
+ # $ darwin-rebuild changelog
+ system.stateVersion = 4;
+
+ # The platform the configuration will be used on.
+ nixpkgs.hostPlatform = "aarch64-darwin";
+}
diff --git a/hosts/mac/m1mba/keyboard.nix b/hosts/mac/m1mba/keyboard.nix
new file mode 100644
index 0000000..f6b164f
--- /dev/null
+++ b/hosts/mac/m1mba/keyboard.nix
@@ -0,0 +1,53 @@
+{ kmonad, config, lib, pkgs, ... }:
+
+let cfg = config.y.kmonad; in
+{
+ options.y.kmonad = {
+ enable = lib.mkEnableOption "kmonad";
+
+ config = lib.mkOption {
+ type = lib.types.lines;
+ };
+ };
+
+ config = lib.mkIf cfg.enable {
+ nixpkgs.overlays = [ kmonad.overlays.default ];
+
+ launchd.daemons.kmonad-default.serviceConfig = {
+ EnvironmentVariables.PATH = "${pkgs.kmonad}/bin:${pkgs.overlays.Karabiner-DriverKit-VirtualHIDDevice}/Library/Application Support/org.pqrs/Karabiner-DriverKit-VirtualHIDDevice/Applications/Karabiner-DriverKit-VirtualHIDDeviceClient.app/Contents/MacOS:${config.environment.systemPath}";
+ KeepAlive = true;
+ Nice = -20;
+ ProgramArguments = [
+ "/Applications/.Karabiner-VirtualHIDDevice-Manager.app/kmonad-daemon-shim"
+ "--input"
+ ''iokit-name "Apple Internal Keyboard / Trackpad"''
+
+ (toString (builtins.toFile "../../kmonad/mac.kbd" ''
+ (defcfg
+ input (iokit-name "Apple Internal Keyboard / Trackpad")
+ output (kext)
+ fallthrough true
+ allow-cmd false
+ )
+
+ ${cfg.config}
+ ''))
+ ];
+ StandardOutPath = "/Library/Logs/KMonad/default-stdout";
+ StandardErrorPath = "/Library/Logs/KMonad/default-stderr";
+ RunAtLoad = true;
+ };
+
+ system.activationScripts.script.applications.text = ''
+ echo copying dext...
+ ${pkgs.rsync}/bin/rsync -a --delete ${pkgs.overlays.Karabiner-DriverKit-VirtualHIDDevice}/Applications/.Karabiner-VirtualHIDDevice-Manager.app/ /Applications/.Karabiner-VirtualHIDDevice-Manager.app
+ echo copying shim...
+ cp --no-preserve mode ${pkgs.overlays.kmonad-daemon-shim}/bin/kmonad-daemon-shim /Applications/.Karabiner-VirtualHIDDevice-Manager.app/kmonad-daemon-shim
+ chown root /Applications/.Karabiner-VirtualHIDDevice-Manager.app/kmonad-daemon-shim
+ chmod u=rx,og= /Applications/.Karabiner-VirtualHIDDevice-Manager.app/kmonad-daemon-shim
+ echo activating dext...
+ /Applications/.Karabiner-VirtualHIDDevice-Manager.app/Contents/MacOS/Karabiner-VirtualHIDDevice-Manager activate
+ printf '\x1b[0;31mPlease grant Input Monitoring permissions to /Applications/.Karabiner-VirtualHIDDevice-Manager.app/kmonad-daemon-shim in System Preferences > Security & Privacy > Privacy > Input Monitoring\x1b[0m\n'
+ '';
+ };
+}
diff --git a/hosts/mac/m1mba/mac.nix b/hosts/mac/m1mba/mac.nix
new file mode 100644
index 0000000..dba3035
--- /dev/null
+++ b/hosts/mac/m1mba/mac.nix
@@ -0,0 +1,12 @@
+{ pkgs, ... }:
+{
+ fonts.fontDir.enable = true;
+ fonts.fonts = with pkgs; [
+ recursive
+ (nerdfonts.override { fonts = [ "JetBrainsMono" ]; })
+ ];
+ system.keyboard = {
+ enableKeyMapping = true;
+ remapCapsLockToEscape = true;
+ };
+}
diff --git a/hosts/mac/m1mba/pkgs.nix b/hosts/mac/m1mba/pkgs.nix
new file mode 100644
index 0000000..dffcd66
--- /dev/null
+++ b/hosts/mac/m1mba/pkgs.nix
@@ -0,0 +1,68 @@
+{ pkgs, kmonad, unstablePkgs, ...}:
+
+{
+# custom
+# y.kmonad.enable = true;
+ environment.systemPackages = with unstablePkgs; [
+ # custom
+ pkgs.overlays.yabai
+ #unfree
+# slack
+# spotify
+# corefonts
+# symbola
+ #gui
+ alacritty
+ vscodium
+ tdesktop
+ # terminal
+ #
+ vim
+ neovim
+ helix
+ # ---
+ wget
+ htop
+ bat
+ gitAndTools.gitFull
+ lazygit
+ git-lfs
+ lsd
+ lsof
+ tmux
+ tmate
+ curlFull
+ ripgrep
+ ranger
+ minio
+ minio-client
+ zip
+ unzip
+ jq
+ vifm
+ nnn
+ # neovim asks for a c compiler just to run nvim-treesitter commands. let's see
+ fzf
+ killall
+ tree
+ deluge
+ ncdu
+ edir
+ bottom
+ pigz
+ rclone
+ # direnv
+ direnv
+ nix-direnv
+ # scraping
+ python310Packages.yt-dlp
+ # code
+ nodejs
+ node2nix
+ zig
+ gcc
+ gnumake
+ sqlite
+ ];
+}
+
diff --git a/hosts/mac/m1mba/services.nix b/hosts/mac/m1mba/services.nix
new file mode 100644
index 0000000..52572ac
--- /dev/null
+++ b/hosts/mac/m1mba/services.nix
@@ -0,0 +1,11 @@
+inputs: pkgs:
+let inherit (pkgs) callPackage
+in {
+ Karabiner-DriverKit-VirtualHIDDevice = callPackage
+ ./Karabiner-DriverKit-VirtualHIDDevice
+ { Karabiner-DriverKit-VirtualHIDDevice-src = inputs.kmonad + "/../c_src/mac/Karabiner-DriverKit-VirtualHIDDevice"; };
+ kmonad-daemon-shim = callPackage ./kmonad-daemon-shim { };
+ yabai = callPackage ./yabai {
+ inherit (pkgs) yabai;
+ };
+} \ No newline at end of file
diff --git a/hosts/mac/m1mba/users.nix b/hosts/mac/m1mba/users.nix
new file mode 100644
index 0000000..10eceac
--- /dev/null
+++ b/hosts/mac/m1mba/users.nix
@@ -0,0 +1,43 @@
+{ config, pkgs, ... }:
+
+
+let shellAliases = {
+ l = "lsd -lAh";
+ la = "lsd -lAh";
+ ports = "sudo lsof -i -P -n | grep LISTEN";
+ gco = "git checkout";
+ gcob = "git checkout -b";
+ v = "nvim";
+ sv = "sudo nvim";
+ dotsin = "sh ~/dotfiles/commit.sh";
+ sourceit = ". (sed 's/^/export /' .env | psub)";
+ rebuild = "darwin-rebuild switch --flake ~/dotfiles/nixos/mac";
+};
+
+in {
+ programs.fish = {
+ inherit shellAliases;
+ enable = true;
+# plugins = [{
+# name="foreign-env";
+# src = pkgs.fetchFromGitHub {
+# owner = "oh-my-fish";
+# repo = "plugin-foreign-env";
+# rev = "dddd9213272a0ab848d474d0cbde12ad034e65bc";
+# sha256 = "00xqlyl3lffc5l0viin1nyp819wf81fncqyz87jx8ljjdhilmgbs";
+# };
+# }];
+};
+
+ users = {
+ users = {
+ y = {
+ createHome = true;
+ home = "/home/y";
+ shell = pkgs.fish;
+ };
+ };
+ };
+}
+
+
diff --git a/hosts/mac/mac.nix b/hosts/mac/mac.nix
new file mode 100644
index 0000000..dba3035
--- /dev/null
+++ b/hosts/mac/mac.nix
@@ -0,0 +1,12 @@
+{ pkgs, ... }:
+{
+ fonts.fontDir.enable = true;
+ fonts.fonts = with pkgs; [
+ recursive
+ (nerdfonts.override { fonts = [ "JetBrainsMono" ]; })
+ ];
+ system.keyboard = {
+ enableKeyMapping = true;
+ remapCapsLockToEscape = true;
+ };
+}
diff --git a/hosts/mac/yabai/0001-mouse-follows-swap.patch b/hosts/mac/yabai/0001-mouse-follows-swap.patch
new file mode 100644
index 0000000..ac7b8f5
--- /dev/null
+++ b/hosts/mac/yabai/0001-mouse-follows-swap.patch
@@ -0,0 +1,31 @@
+From 612465d4000cc747a1673a4b422f863aa2bfdc25 Mon Sep 17 00:00:00 2001
+From: Matthew Toohey <contact@mtoohey.com>
+Date: Sat, 19 Nov 2022 19:55:08 -0500
+Subject: [PATCH] mouse follows swap
+
+---
+ src/window_manager.c | 8 ++++++++
+ 1 file changed, 8 insertions(+)
+
+diff --git a/src/window_manager.c b/src/window_manager.c
+index b07a88b..96b07e1 100644
+--- a/src/window_manager.c
++++ b/src/window_manager.c
+@@ -1812,6 +1812,14 @@ enum window_op_error window_manager_swap_window(struct space_manager *sm, struct
+ }
+
+ window_manager_animate_window_list(window_list, ts_buf_len(window_list));
++
++ if (wm->enable_mff) {
++ struct window *focused_window_dest = NULL;
++ if (a->id == wm->focused_window_id) focused_window_dest = b;
++ else if (b->id == wm->focused_window_id) focused_window_dest = a;
++ if (focused_window_dest) window_manager_center_mouse(wm, focused_window_dest);
++ }
++
+ return WINDOW_OP_ERROR_SUCCESS;
+ }
+
+--
+2.37.1 (Apple Git-137.1)
+
diff --git a/hosts/mac/yabai/default.nix b/hosts/mac/yabai/default.nix
new file mode 100644
index 0000000..23e19cc
--- /dev/null
+++ b/hosts/mac/yabai/default.nix
@@ -0,0 +1,5 @@
+{ yabai }:
+
+yabai.overrideAttrs (oldAttrs: {
+ patches = (oldAttrs.patches or [ ]) ++ [ ./0001-mouse-follows-swap.patch ];
+})