From 03789095893784eeafc087141dfb4ae612fd3d9a Mon Sep 17 00:00:00 2001 From: Philipp Hochkamp Date: Mon, 5 Sep 2022 21:30:29 +0200 Subject: [PATCH] emacs server --- hm-imports/cli.nix | 58 +++++++-------- hm-imports/zsh/zshrc | 6 ++ hosts/daedalus/default.nix | 129 +++++++++++++++++++-------------- hosts/daedalus/hammerspoon.lua | 3 + 4 files changed, 112 insertions(+), 84 deletions(-) diff --git a/hm-imports/cli.nix b/hm-imports/cli.nix index ce3f8cdd..203108fd 100644 --- a/hm-imports/cli.nix +++ b/hm-imports/cli.nix @@ -1,7 +1,7 @@ { inputs, config, lib, pkgs, ... }: { - home.stateVersion = lib.mkDefault "21.05"; + home.stateVersion = lib.mkDefault "22.05"; home.packages = with pkgs; [ my.scripts @@ -46,34 +46,34 @@ }; programs = { - gpg = { - enable = true; - settings = { - cert-digest-algo = "SHA512"; - charset = "utf-8"; - default-preference-list = "SHA512 SHA384 SHA256 AES256 AES192 AES ZLIB BZIP2 ZIP Uncompressed"; - auto-key-retrieve = true; - fixed-list-mode = true; - keyserver = "hkps://keyserver.ubuntu.com:443"; - list-options = [ "show-uid-validity" "show-unusable-subkeys" ]; - no-comments = true; - no-emit-version = true; - no-greeting = true; - no-symkey-cache = true; - personal-cipher-preferences = "AES256 AES192 AES"; - personal-compress-preferences = "ZLIB BZIP2 ZIP Uncompressed"; - personal-digest-preferences = "SHA512 SHA384 SHA256"; - require-cross-certification = true; - s2k-cipher-algo = "AES256"; - s2k-digest-algo = "SHA512"; - throw-keyids = true; - use-agent = true; - verbose = true; - verify-options = "show-uid-validity"; - with-fingerprint = true; - with-key-origin = true; - }; - }; + # gpg = { + # enable = true; + # settings = { + # cert-digest-algo = "SHA512"; + # charset = "utf-8"; + # default-preference-list = "SHA512 SHA384 SHA256 AES256 AES192 AES ZLIB BZIP2 ZIP Uncompressed"; + # auto-key-retrieve = true; + # fixed-list-mode = true; + # keyserver = "hkps://keyserver.ubuntu.com:443"; + # list-options = [ "show-uid-validity" "show-unusable-subkeys" ]; + # no-comments = true; + # no-emit-version = true; + # no-greeting = true; + # no-symkey-cache = true; + # personal-cipher-preferences = "AES256 AES192 AES"; + # personal-compress-preferences = "ZLIB BZIP2 ZIP Uncompressed"; + # personal-digest-preferences = "SHA512 SHA384 SHA256"; + # require-cross-certification = true; + # s2k-cipher-algo = "AES256"; + # s2k-digest-algo = "SHA512"; + # throw-keyids = true; + # use-agent = true; + # verbose = true; + # verify-options = "show-uid-validity"; + # with-fingerprint = true; + # with-key-origin = true; + # }; + # }; bat = { enable = true; config.theme = "gruvbox-dark"; diff --git a/hm-imports/zsh/zshrc b/hm-imports/zsh/zshrc index f45c86aa..ad991e35 100644 --- a/hm-imports/zsh/zshrc +++ b/hm-imports/zsh/zshrc @@ -47,3 +47,9 @@ n () rm -f "$NNN_TMPFILE" > /dev/null fi } + +ORIGTMPDIR=$TMPDIR # nix-shell overrides tmpdir, but we want to save it +emacsclient () +{ + command emacsclient -s $ORIGTMPDIR/emacs$(id -u)/server "$@" +} diff --git a/hosts/daedalus/default.nix b/hosts/daedalus/default.nix index 9371356c..30043c36 100644 --- a/hosts/daedalus/default.nix +++ b/hosts/daedalus/default.nix @@ -1,12 +1,18 @@ { pkgs, inputs, lib, ... }: with lib; with lib.my; + let + myEmacs = pkgs.emacsNativeComp; + in { users.users.ragon = { name = "ragon"; home = "/Users/ragon"; }; + environment.systemPackages = [ + myEmacs + ]; homebrew = { enable = true; @@ -42,61 +48,74 @@ with lib.my; #}; }; - 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"; - - home.sessionVariables = { - EDITOR = "nvim"; - VISUAL = "nvim"; - PATH = "$PATH:$HOME/go/bin:$HOME/development/flutter/bin:/Applications/Android Studio.app/Contents/bin/:/Applications/Docker.app/Contents/Resources/bin:/Applications/Android Studio.app/Contents/jre/Contents/Home/bin"; - JAVA_HOME = "/Applications/Android Studio.app/Contents/jre/Contents/Home/"; - }; - home.packages = with pkgs; [ - terraform-ls - terraform - - emacsNativeComp - cmake - - pandoc - texlive.combined.scheme-full - - yabai - - google-cloud-sdk - ]; - - home.activation = { - aliasApplications = - let - apps = pkgs.buildEnv { - name = "home-manager-applications"; - paths = config.home.packages; - pathsToLink = "/Applications"; - }; - in - lib.hm.dag.entryAfter [ "writeBoundary" ] '' - # Install MacOS applications to the user environment. - HM_APPS="$HOME/Applications/Home Manager Apps" - - # Reset current state - [ -e "$HM_APPS" ] && $DRY_RUN_CMD rm -r "$HM_APPS" - $DRY_RUN_CMD mkdir -p "$HM_APPS" - - # .app dirs need to be actual directories for Finder to detect them as Apps. - # The files inside them can be symlinks though. - $DRY_RUN_CMD cp --recursive --symbolic-link --no-preserve=mode -H ${apps}/Applications/* "$HM_APPS" || true # can fail if no apps exist - # Modes need to be stripped because otherwise the dirs wouldn't have +w, - # preventing us from deleting them again - # In the env of Apps we build, the .apps are symlinks. We pass all of them as - # arguments to cp and make it dereference those using -H - ''; - }; - + launchd.user.agents.emacsdaemon = { + script = "${myEmacs}/Applications/Emacs.app/Contents/MacOS/Emacs --daemon"; + serviceConfig.RunAtLoad = true; + serviceConfig.UserName = "ragon"; + serviceConfig.KeepAlive = true; + serviceConfig.WorkingDirectory = "/Users/ragon"; }; + programs.gnupg.agent.enable = true; + home-manager.users.ragon = { pkgs, lib, inputs, config, ... }: + { + home.file.".hammerspoon/init.lua".source = + pkgs.substituteAll { + src = ./hammerspoon.lua; inherit myEmacs; }; + + programs.home-manager.enable = true; + home.stateVersion = "21.11"; + + home.shellAliases = { + v = lib.mkForce "emacsclient -t"; + vv = lib.mkForce "emacsclient -c"; + }; + home.sessionVariables = { + EDITOR = "emacsclient -t"; + VISUAL = "emacsclient -c"; + PATH = "$PATH:$HOME/go/bin:$HOME/development/flutter/bin:/Applications/Android Studio.app/Contents/bin/:/Applications/Docker.app/Contents/Resources/bin:/Applications/Android Studio.app/Contents/jre/Contents/Home/bin"; + JAVA_HOME = "/Applications/Android Studio.app/Contents/jre/Contents/Home/"; + }; + home.packages = with pkgs; [ + terraform-ls + terraform + + cmake + + pandoc + texlive.combined.scheme-full + + yabai + + google-cloud-sdk + ]; + + home.activation = { + aliasApplications = + let + apps = pkgs.buildEnv { + name = "home-manager-applications"; + paths = config.home.packages; + pathsToLink = "/Applications"; + }; + in + lib.hm.dag.entryAfter [ "writeBoundary" ] '' + # Install MacOS applications to the user environment. + HM_APPS="$HOME/Applications/Home Manager Apps" + + # Reset current state + [ -e "$HM_APPS" ] && $DRY_RUN_CMD rm -r "$HM_APPS" + $DRY_RUN_CMD mkdir -p "$HM_APPS" + + # .app dirs need to be actual directories for Finder to detect them as Apps. + # The files inside them can be symlinks though. + $DRY_RUN_CMD cp --recursive --symbolic-link --no-preserve=mode -H ${apps}/Applications/* "$HM_APPS" || true # can fail if no apps exist + # Modes need to be stripped because otherwise the dirs wouldn't have +w, + # preventing us from deleting them again + # In the env of Apps we build, the .apps are symlinks. We pass all of them as + # arguments to cp and make it dereference those using -H + ''; + }; + + }; } diff --git a/hosts/daedalus/hammerspoon.lua b/hosts/daedalus/hammerspoon.lua index 5da882bd..37c06b50 100644 --- a/hosts/daedalus/hammerspoon.lua +++ b/hosts/daedalus/hammerspoon.lua @@ -88,9 +88,12 @@ function showHideBundleId(bundleId) end local hyperModifier = {"cmd", "shift", "ctrl", "alt"} +local cmdShiftModifier = {"cmd", "shift"} hs.hotkey.bind(hyperModifier, "b", function() showHideBundleId("com.bitwarden.desktop") end) hs.hotkey.bind(hyperModifier, "p", function() showHideBundleId("com.timeular.zei") end) hs.hotkey.bind(hyperModifier, "l", function() showHideBundleId("com.electron.logseq") end) +hs.hotkey.bind(hyperModifier, "e", function() hs.task.new("@myEmacs@/bin/emacsclient", nil, function() return false end, {"-c"}):start() end) +hs.hotkey.bind(hyperModifier, "i", function() hs.task.new("@myEmacs@/bin/emacsclient", nil, function() return false end, {"--eval", "(emacs-everywhere)"}):start() end) ---------------------------------------------------------------------------------------------------- -- Tiling