From c39f8252f79dd4aba24be9b20d96fb0551e01d0e Mon Sep 17 00:00:00 2001 From: Philipp Hochkamp Date: Wed, 2 Mar 2022 00:32:03 +0100 Subject: [PATCH] feat: daedalus brew --- flake.lock | 41 ++++++++++----- flake.nix | 20 +++---- hm-imports/cli.nix | 2 +- hm-imports/nvim/default.nix | 16 +----- hm-imports/zsh/default.nix | 1 - hosts/daedalus/default.nix | 20 +++++++ hosts/daedalus/hammerspoon.lua | 95 ++++++++++++++++++++++++++++++++++ lib/default.nix | 2 +- 8 files changed, 159 insertions(+), 38 deletions(-) create mode 100644 hosts/daedalus/hammerspoon.lua diff --git a/flake.lock b/flake.lock index f178bfeb..5eec1e33 100644 --- a/flake.lock +++ b/flake.lock @@ -145,11 +145,11 @@ }, "impermanence": { "locked": { - "lastModified": 1644791231, - "narHash": "sha256-iDihsF1fUMK4xXiUudPnDM3veH1LXbbxfP9Lzekw9iU=", + "lastModified": 1646131459, + "narHash": "sha256-GPmgxvUFvQ1GmsGfWHy9+rcxWrczeDhS9XnAIPHi9XQ=", "owner": "nix-community", "repo": "impermanence", - "rev": "635bcd2d88739197a0b584aa9fadaa53c717a853", + "rev": "2f39baeb7d039fda5fc8225111bb79474138e6f4", "type": "github" }, "original": { @@ -189,11 +189,11 @@ }, "locked": { "dir": "contrib", - "lastModified": 1646012280, - "narHash": "sha256-rgx3+Xkqm6E9oR1hXKmipyTmMQb8kyXEklDuHHplD/I=", + "lastModified": 1646122061, + "narHash": "sha256-VD+GkXqZ/n0l2pKdol7Pg6/s0QiJfWG18tBLroodRO0=", "owner": "neovim", "repo": "neovim", - "rev": "e383543342db8e9dcf40f7d5237edeab29638880", + "rev": "37a86a2f964b5d6f9dbfae8b78acaa3a71f981bb", "type": "github" }, "original": { @@ -212,11 +212,11 @@ ] }, "locked": { - "lastModified": 1646036082, - "narHash": "sha256-dRTzOZszaNupxRUkEX11K4hzRCzcB2apNsyGx0WsmbU=", + "lastModified": 1646122501, + "narHash": "sha256-nszY7wfiAi/U8BRbIiEiAH7ycaWPLbzUd32Jzm60leM=", "owner": "nix-community", "repo": "neovim-nightly-overlay", - "rev": "c5d3b328cfe9c7414363f70d583dce6584a72251", + "rev": "359449438c8c6e435cf0d4bc16a79433bca46c8a", "type": "github" }, "original": { @@ -259,11 +259,11 @@ }, "nixpkgs-master": { "locked": { - "lastModified": 1646109749, - "narHash": "sha256-09nJZGDSoy+1LWX3AqjjQUJPpx9pYYhwOOI32sx7+Fg=", + "lastModified": 1646175689, + "narHash": "sha256-2iqYd0KBc5n9J5vTx7QbB2XxZnJEnIIED0khKdvKI8o=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "13e74fc7ff2f691da0791db67fe65930403b391d", + "rev": "bc52b6406e1eefd9fa35cd88ab1a36916a84b389", "type": "github" }, "original": { @@ -289,6 +289,22 @@ "type": "github" } }, + "pandoc-latex-template": { + "flake": false, + "locked": { + "lastModified": 1639934947, + "narHash": "sha256-AXVwBC/dZ7H9naXlvKfHoJFvG1x7G3MMAtdSRwKf+n4=", + "owner": "Wandmalfarbe", + "repo": "pandoc-latex-template", + "rev": "30cfc57a0c64fad1202aa1422e2ed3a77535bf02", + "type": "github" + }, + "original": { + "owner": "Wandmalfarbe", + "repo": "pandoc-latex-template", + "type": "github" + } + }, "rnix-lsp": { "inputs": { "naersk": "naersk", @@ -325,6 +341,7 @@ "nixpkgs": "nixpkgs", "nixpkgs-master": "nixpkgs-master", "nnn-vim": "nnn-vim", + "pandoc-latex-template": "pandoc-latex-template", "rnix-lsp": "rnix-lsp", "utils": "utils_2", "zsh-completions": "zsh-completions", diff --git a/flake.nix b/flake.nix index 5d2e4ba9..0922d57b 100644 --- a/flake.nix +++ b/flake.nix @@ -24,6 +24,8 @@ dart-vim.flake = false; rnix-lsp.url = "github:nix-community/rnix-lsp"; rnix-lsp.inputs.nixpkgs.follows = "nixpkgs"; + pandoc-latex-template.url = "github:Wandmalfarbe/pandoc-latex-template"; + pandoc-latex-template.flake = false; ## zsh zsh-completions.url = "github:zsh-users/zsh-completions"; zsh-completions.flake = false; @@ -55,6 +57,8 @@ imports = lib.my.mapModulesRec' ./hm-imports (x: x); }; + rev = if (lib.hasAttrByPath [ "rev" ] self.sourceInfo) then self.sourceInfo.rev else "Dirty Build"; + nixosSystem = system: extraModules: let pkgs = genPkgs system; in nixpkgs.lib.nixosSystem @@ -66,12 +70,12 @@ impermanence.nixosModules.impermanence home-manager.nixosModules.home-manager ({ config, ...}: lib.mkMerge [{ - system.configurationRevision = self.sourceInfo.rev; + system.configurationRevision = rev; services.getty.greetingLine = - "<<< Welcome to NixOS ${config.system.nixos.label} @ ${self.sourceInfo.rev} - \\l >>>"; + "<<< Welcome to ${config.system.nixos.label} @ ${rev} - Please leave\\l >>>"; home-manager.useGlobalPkgs = true; home-manager.useUserPackages = true; - home-manager.extraSpecialArgs = { inherit inputs; }; + home-manager.extraSpecialArgs = { inherit inputs lib; }; } (lib.mkIf (config.users.extraUsers.ragon != null) { # import hm stuff if enabled @@ -90,16 +94,14 @@ specialArgs = { inherit darwin lib pkgs inputs self; }; modules = [ home-manager.darwinModules.home-manager - ({ config, inputs, self, ...}: lib.mkMerge [{ - system.configurationRevision = (lib.traceVal (self.sourceInfo)).rev; + ({ config, inputs, self, ...}: { config = { + #system.darwinLabel = "${config.system.darwinLabel}@${rev}"; home-manager.useGlobalPkgs = true; home-manager.useUserPackages = true; home-manager.extraSpecialArgs = { inherit inputs; }; - } - (lib.mkIf (config.users.extraUsers.ragon != null) { # import hm stuff if enabled home-manager.users.ragon = hmConfig; - }) - ]) + }; + }) ./darwin-common.nix ] ++ extraModules; }; diff --git a/hm-imports/cli.nix b/hm-imports/cli.nix index a6ab7774..3751b875 100644 --- a/hm-imports/cli.nix +++ b/hm-imports/cli.nix @@ -22,7 +22,7 @@ yt-dlp aria2 libqalculate - ] + ]; home.shellAliases = { v = "nvim"; vim = "nvim"; diff --git a/hm-imports/nvim/default.nix b/hm-imports/nvim/default.nix index 283c7e26..ad83efd6 100644 --- a/hm-imports/nvim/default.nix +++ b/hm-imports/nvim/default.nix @@ -1,8 +1,6 @@ -{pkgs, config, inputs, lib, ...}: -with lib; -with lib.my; +{pkgs, config, inputs, ...}: { - home.packages = [ + home.packages = with pkgs;[ python3 # ultisnips lazygit nodejs @@ -41,15 +39,6 @@ with lib.my; name = "dart-vim"; src = inputs.dart-vim; }; - vim-pandoc-live-preview = pkgs.vimUtils.buildVimPlugin { - name = "vim-pandoc-live-preview"; - src = inputs.vim-pandoc-live-preview; - }; - orgmode-nvim = pkgs.vimUtils.buildVimPlugin { - name = "orgmode-nvim"; - src = inputs.orgmode-nvim; - dontBuild = true; - }; in map (x: { plugin = x; }) (with pkgs.vimPlugins; [ vim-tmux-navigator @@ -74,7 +63,6 @@ with lib.my; toggleterm-nvim undotree vim-pandoc - vim-pandoc-live-preview vim-pandoc-syntax ultisnips coc-nvim diff --git a/hm-imports/zsh/default.nix b/hm-imports/zsh/default.nix index bf80fe7d..74b70438 100644 --- a/hm-imports/zsh/default.nix +++ b/hm-imports/zsh/default.nix @@ -5,7 +5,6 @@ in { programs.zsh = { enable = true; - histSize = 10000; enableCompletion = true; initExtra = let diff --git a/hosts/daedalus/default.nix b/hosts/daedalus/default.nix index 5e64a72f..4086da75 100644 --- a/hosts/daedalus/default.nix +++ b/hosts/daedalus/default.nix @@ -2,13 +2,33 @@ with lib; with lib.my; { + networking.hostName = "daedalus"; users.users.ragon = { name = "ragon"; home = "/Users/ragon"; }; + + homebrew = { + enable = true; + autoUpdate = true; + casks = [ "hammerspoon" "amethyst" "android-platform-tools" "alfred" "ukelele" "homebrew/cask-drivers/zsa-wally" ]; + masApps = { # Install Mac App Store apps (install them manually and then do `mas list` to get the id) + "AdGuard for Safari" = 1440147259; + "Xcode" = 497799835; + "Home Assistant" = 1099568401; + "WireGuard" = 1451685025; + "UTM" = 1538878817; + "Bitwarden" = 1352778147; + "Shareful" = 1522267256; + "Tailscale" = 1475387142; + }; + }; + programs.gnupg.agent.enable = true; home-manager.users.ragon = { pkgs, lib, inputs, config, ... }: { + home.file.".hammerspoon/init.lua".source = ./hammerspoon.lua; + programs.home-manager.enable = true; home.stateVersion = "21.11"; diff --git a/hosts/daedalus/hammerspoon.lua b/hosts/daedalus/hammerspoon.lua new file mode 100644 index 00000000..d6520299 --- /dev/null +++ b/hosts/daedalus/hammerspoon.lua @@ -0,0 +1,95 @@ +---------------------------------------------------------------------------------------------------- +-- Settings +---------------------------------------------------------------------------------------------------- +hs.autoLaunch(true) +hs.automaticallyCheckForUpdates(true) +hs.consoleOnTop(true) +hs.dockIcon(false) +hs.menuIcon(false) +hs.uploadCrashData(false) + +hs.window.animationDuration = 0 + +local log = hs.logger.new('init', 'debug') + +configWatcher = hs.pathwatcher.new(hs.configdir, hs.reload):start() + + +---------------------------------------------------------------------------------------------------- +-- Moonlander Detection +---------------------------------------------------------------------------------------------------- + +function isDeviceMoonlander(device) + return device.productName == "Moonlander Mark I" +end + +function moonlanderDetected(connected) + if connected then + hs.keycodes.setLayout("EurKEY v1.2") + else + hs.keycodes.setLayout("Colemak DH ISO copy") + end +end + +function searchMoonlander() + local usbDevices = hs.usb.attachedDevices() + local moonlanderConnected = hs.fnutils.find(usbDevices, isDeviceMoonlander) ~= nil + + moonlanderDetected(moonlanderConnected) +end + +searchMoonlander() + +usbWatcher = hs.usb.watcher.new(function(event) + if event.productName == "Moonlander Mark I" then + moonlanderDetected(event.eventType == "added") + end +end):start() + +caffeinateWatcher = hs.caffeinate.watcher.new(function(event) + if event == hs.caffeinate.watcher.systemDidWake then + searchMoonlander() + end +end):start() + + +---------------------------------------------------------------------------------------------------- +-- mount ds9 via tailscale +---------------------------------------------------------------------------------------------------- +function mountDS9() + local ssid = hs.wifi.currentNetwork() + if ssid ~= nil and ssid ~= 'vim' then -- not at home + if os.execute("mount | grep //ragon@ds9._smb._tcp.local/data") == nil then -- check if mounted via mdns + os.execute("diskutil umount /Volumes/data") -- umount share if it exists + hs.osascript.applescript('mount volume "smb://ragon@ds9.ragon000.github.beta.tailscale.net/data"') -- mount share via tailscale + end + end +end + +mountDS9() + +hs.wifi.watcher.new(function(watcher, message, interface) + mountDS9() +end):start() + +---------------------------------------------------------------------------------------------------- +-- Scratchpad +---------------------------------------------------------------------------------------------------- + +function showHideBundleId(bundleId) + local focusedWindow = hs.window.focusedWindow() + if focusedWindow ~= nil and focusedWindow:application():bundleID() == bundleId then -- window is focused + focusedWindow:close() -- hide + else + hs.application.launchOrFocusByBundleID(bundleId) + hs.window.focusedWindow():centerOnScreen(hs.mouse.getCurrentScreen()) + end +end + +local hyperModifier = {"cmd", "shift", "ctrl", "alt"} +hs.hotkey.bind(hyperModifier, "b", function() showHideBundleId("com.bitwarden.desktop") end) +hs.hotkey.bind(hyperModifier, "p", function() showHideBundleId("com.timeular.zei") end) + +---------------------------------------------------------------------------------------------------- +-- Tiling +---------------------------------------------------------------------------------------------------- diff --git a/lib/default.nix b/lib/default.nix index 0186cb5a..f9c6ddb3 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,4 +1,4 @@ -{ darwin, inputs, lib, pkgsBySystem, ... }: +{ inputs, lib, ... }: let inherit (lib) makeExtensible attrValues foldr;