From a1d45d730377162204b6faf34bdd9ac02bca0b04 Mon Sep 17 00:00:00 2001
From: Andrea Ciceri <andrea.ciceri@autistici.org>
Date: Fri, 25 Nov 2022 14:12:27 +0100
Subject: [PATCH] Things

---
 doom.d/config.el                          | 24 +++++++-
 doom.d/init.el                            |  2 +-
 flake.nix                                 | 16 +++---
 hmModules/emacs/default.nix               | 32 +++++++----
 hmModules/email/default.nix               | 53 +++++++++++++++++
 hmModules/firefox/default.nix             |  1 -
 hmModules/foot/default.nix                |  5 --
 hmModules/franz/default.nix               | 18 ------
 hmModules/nix-index/default.nix           |  5 --
 hmModules/password-store/default.nix      |  1 +
 hmModules/shell/default.nix               | 59 +++++++++----------
 hmModules/sway/default.nix                |  7 ++-
 hmModules/sway/style.css                  | 70 +++++++----------------
 hmModules/sway/waybar.nix                 |  2 -
 hosts/thinkpad/default.nix                |  2 +-
 hosts/thinkpad/hardware-configuration.nix |  4 +-
 modules/adb/default.nix                   |  5 --
 modules/ccr/default.nix                   | 10 +++-
 secrets/autistici-password.age            | 19 ++++++
 secrets/default.nix                       |  1 +
 utils/default.nix                         |  8 ++-
 21 files changed, 202 insertions(+), 142 deletions(-)
 create mode 100644 hmModules/email/default.nix
 delete mode 100644 hmModules/franz/default.nix
 create mode 100644 secrets/autistici-password.age

diff --git a/doom.d/config.el b/doom.d/config.el
index 9ab417d..dcfbe4c 100644
--- a/doom.d/config.el
+++ b/doom.d/config.el
@@ -32,7 +32,8 @@
 ;; There are two ways to load a theme. Both assume the theme is installed and
 ;; available. You can either set `doom-theme' or manually load a theme with the
 ;; `load-theme' function. This is the default:
-(setq doom-theme 'doom-one)
+;; (setq doom-theme 'doom-one)
+(setq doom-theme 'doom-one-light)
 
 ;; This determines the style of line numbers in effect. If set to `nil', line
 ;; numbers are disabled. For relative line numbers, set this to `relative'.
@@ -117,3 +118,24 @@
                   ("[-]" "❍")
                   ("#+begin_src" "λ")
                   ("#+end_src" "λ"))))
+
+(setq +mu4e-backend 'mbsync)
+
+(after! mu4e
+  (setq sendmail-program (executable-find "msmtp")
+	send-mail-function #'smtpmail-send-it
+	message-sendmail-f-is-evil t
+	message-sendmail-extra-arguments '("--read-envelope-from")
+	message-send-mail-function #'message-send-mail-with-sendmail))
+
+(set-email-account! "Autistici"
+  '((mu4e-sent-folder       . "/autistici/Sent Mail")
+    (mu4e-drafts-folder     . "/autistici/Drafts")
+    (mu4e-trash-folder      . "/autistici/Trash")
+    (mu4e-refile-folder     . "/autistici/All Mail")
+    (smtpmail-smtp-user     . "andrea.ciceri@autistici.org"))
+  t)
+
+(after! eglot
+  (add-to-list 'eglot-server-programs '(nix-mode . ("nil")))
+)
diff --git a/doom.d/init.el b/doom.d/init.el
index 5f74e76..d78b725 100644
--- a/doom.d/init.el
+++ b/doom.d/init.el
@@ -178,7 +178,7 @@
        ;;zig               ; C, but simpler
 
        :email
-       ;;(mu4e +org +gmail)
+       (mu4e +org)
        ;;notmuch
        ;;(wanderlust +gmail)
 
diff --git a/flake.nix b/flake.nix
index c8a2ea6..78d5080 100644
--- a/flake.nix
+++ b/flake.nix
@@ -2,17 +2,17 @@
   description = "A complete, declarative, and reproducible configuration of my entire Nix fleet";
 
   inputs = {
-    nixpkgsUnstable.url = github:NixOS/nixpkgs/nixos-unstable;
-    nixpkgsStable.url = github:NixOS/nixpkgs/nixos-22.05;
-    nixosHardware.url = github:NixOS/nixos-hardware;
+    nixpkgsUnstable.url = "github:NixOS/nixpkgs/nixos-unstable";
+    nixpkgsStable.url = "github:NixOS/nixpkgs/nixos-22.05";
+    nixosHardware.url = "github:NixOS/nixos-hardware";
     homeManager = {
-      url = github:nix-community/home-manager;
+      url = "github:nix-community/home-manager";
       inputs.nixpkgs.follows = "nixpkgsUnstable";
     };
-    preCommitHooks.url = github:cachix/pre-commit-hooks.nix;
-    agenix.url = github:ryantm/agenix;
-    doomEmacs.url = github:nix-community/nix-doom-emacs;
-    comma.url = github:nix-community/comma;
+    preCommitHooks.url = "github:cachix/pre-commit-hooks.nix";
+    agenix.url = "github:ryantm/agenix";
+    doomEmacs.url = "github:nix-community/nix-doom-emacs";
+    comma.url = "github:nix-community/comma";
   };
 
   outputs = {self, ...} @ inputs: let
diff --git a/hmModules/emacs/default.nix b/hmModules/emacs/default.nix
index 1f7fc2e..2cc2e7d 100644
--- a/hmModules/emacs/default.nix
+++ b/hmModules/emacs/default.nix
@@ -78,6 +78,7 @@ in {
         path = ../../doom.d/modules;
       }
     ];
+    extraPackages = with pkgs; [mu];
   };
 
   services.emacs = {
@@ -104,16 +105,23 @@ in {
         nixpkgs-fmt <<< /dev/stdin
       fi
     '';
-  in [
-    binutils
-    (ripgrep.override {withPCRE2 = true;})
-    gnutls
-    fd
-    imagemagick
-    sqlite
-    maim
-    nixFormat
-    jq
-    xclip
-  ];
+  in
+    [
+      binutils
+      (ripgrep.override {withPCRE2 = true;})
+      gnutls
+      fd
+      imagemagick
+      sqlite
+      maim
+      nil
+      nixFormat
+      jq
+      xclip
+      hunspell
+    ]
+    ++ (with hunspellDicts; [
+      en_US-large
+      it_IT
+    ]);
 }
diff --git a/hmModules/email/default.nix b/hmModules/email/default.nix
new file mode 100644
index 0000000..f21deef
--- /dev/null
+++ b/hmModules/email/default.nix
@@ -0,0 +1,53 @@
+{
+  pkgs,
+  secrets,
+  ...
+}: {
+  home.packages = with pkgs; [mu];
+  programs.mbsync.enable = true;
+  programs.msmtp.enable = true;
+  programs.notmuch = {
+    enable = true;
+    hooks = {
+      preNew = "mbsync --all";
+    };
+  };
+  services = {
+    mbsync = {
+      enable = true;
+      frequency = "*:0/15";
+      preExec = "${pkgs.isync}/bin/mbsync -Ha";
+      # First time run: mu init --maildir ~/.mail --my-address andrea.ciceri@autistici.org
+      # TODO Nixify this
+      postExec = "${pkgs.mu}/bin/mu index";
+    };
+  };
+  accounts.email = {
+    maildirBasePath = ".mail";
+    accounts.autistici = {
+      address = "andrea.ciceri@autistici.org";
+      gpg = {
+        key = "7A66EEA1E6C598D07D361287A1FC89532D1C565";
+        signByDefault = true;
+      };
+      imap.host = "mail.autistici.org";
+      mbsync = {
+        enable = true;
+        create = "maildir";
+      };
+      msmtp.enable = true;
+      notmuch.enable = true;
+      primary = true;
+      realName = "Andrea Ciceri";
+      signature = {
+        # text = '''';
+        showSignature = "append";
+      };
+      passwordCommand = "${pkgs.pass}/bin/pass show autistici/password";
+      smtp = {
+        host = "smtp.autistici.org";
+      };
+      userName = "andrea.ciceri@autistici.org";
+    };
+  };
+}
diff --git a/hmModules/firefox/default.nix b/hmModules/firefox/default.nix
index 705ff31..e652c5d 100644
--- a/hmModules/firefox/default.nix
+++ b/hmModules/firefox/default.nix
@@ -2,7 +2,6 @@
   programs.firefox = {
     enable = true;
     package = pkgs.wrapFirefox pkgs.firefox-unwrapped {
-      forceWayland = true;
       extraPolicies = {
         ExtensionSettings = {};
       };
diff --git a/hmModules/foot/default.nix b/hmModules/foot/default.nix
index 8fff506..20954c3 100644
--- a/hmModules/foot/default.nix
+++ b/hmModules/foot/default.nix
@@ -1,8 +1,4 @@
 {
-  config,
-  lib,
-  ...
-}: {
   programs.foot = {
     enable = true;
     server.enable = true;
@@ -11,7 +7,6 @@
         term = "xterm-256color";
         login-shell = "yes";
         font = "Fira Code,Symbols Nerd Font,JoyPixels";
-        dpi-aware = "yes";
       };
 
       mouse = {
diff --git a/hmModules/franz/default.nix b/hmModules/franz/default.nix
deleted file mode 100644
index 4b95d6a..0000000
--- a/hmModules/franz/default.nix
+++ /dev/null
@@ -1,18 +0,0 @@
-{pkgs, ...}: {
-  home.packages = [pkgs.franz];
-
-  systemd.user.services.franz = {
-    Install.WantedBy = ["graphical-session.target"];
-
-    Unit = {
-      Description = "Franz";
-      PartOf = ["graphical-session.target"];
-    };
-
-    Service = {
-      ExecStart = "${pkgs.franz}/bin/franz";
-      Restart = "on-failure";
-      RestartSec = 3;
-    };
-  };
-}
diff --git a/hmModules/nix-index/default.nix b/hmModules/nix-index/default.nix
index 993abe0..5da7f53 100644
--- a/hmModules/nix-index/default.nix
+++ b/hmModules/nix-index/default.nix
@@ -3,11 +3,6 @@
   pkgs,
   ...
 }: {
-  programs.nix-index = {
-    enable = true;
-    enableZshIntegration = true;
-  };
-
   systemd.user.services.nix-index-update = {
     Unit = {Description = "Update nix-index";};
 
diff --git a/hmModules/password-store/default.nix b/hmModules/password-store/default.nix
index c2a01b3..c4c0375 100644
--- a/hmModules/password-store/default.nix
+++ b/hmModules/password-store/default.nix
@@ -9,6 +9,7 @@
     settings = {
       PASSWORD_STORE_DIR = "/home/ccr/.password-store";
     };
+    package = pkgs.pass.withExtensions (e: with e; [pass-otp]);
   };
   services.password-store-sync.enable = true;
 }
diff --git a/hmModules/shell/default.nix b/hmModules/shell/default.nix
index a7b3f2c..e4dc04a 100644
--- a/hmModules/shell/default.nix
+++ b/hmModules/shell/default.nix
@@ -25,37 +25,44 @@
 
   programs.vim.enable = true;
 
+  programs.command-not-found.enable = true;
+
+  programs.starship = {
+    enable = true;
+    settings = {
+      character = {
+        success_symbol = "[λ](bold green)";
+        error_symbol = "[λ](bold red)";
+      };
+      nix_shell = {
+        symbol = "❄";
+      };
+    };
+  };
+
   programs.zsh = {
     enable = true;
     enableAutosuggestions = true;
     enableCompletion = true;
+    enableSyntaxHighlighting = true;
+    enableVteIntegration = true;
     autocd = true;
-    plugins = [
-      {
-        name = "nix-zsh-completions";
-        file = "share/zsh/plugins/nix/nix-zsh-completions.plugin.zsh";
-        src = pkgs.nix-zsh-completions;
-      }
-      {
-        name = "spaceship";
-        file = "share/zsh/themes/spaceship.zsh-theme";
-        src = pkgs.spaceship-prompt;
-      }
-      {
-        name = "fast-zsh-syntax-highlighting";
-        file = "share/zsh/site-functions/fast-syntax-highlighting.plugin.zsh";
-        src = pkgs.zsh-fast-syntax-highlighting;
-      }
-    ];
     oh-my-zsh = {
       enable = true;
       plugins = [
-        "git"
-        "sudo"
+        "ag"
+        "cabal"
         "colored-man-pages"
         "colorize"
-        "thefuck"
+        "command-not-found"
         "fzf"
+        "git"
+        "nomad"
+        "pass"
+        "python"
+        "sudo"
+        "terraform"
+        "thefuck"
       ];
     };
     shellAliases = {
@@ -65,15 +72,6 @@
       "pass-clone" = "[ -d .password-store ] && echo 'Password store archive already exists' || git clone git@git.sr.ht:~zrsk/pass ~/.password-store";
       "getpass" = "pass show $(find .password-store/ -name \"*.gpg\" | sed \"s/\\.password-store\\/\\(.*\\)\\.gpg$/\\1/g\" | fzf) | wl-copy; ((sleep 60 && wl-copy --clear) &)";
     };
-    localVariables = {
-      PASSWORD_STORE_DIR = "/home/ccr/.password-store";
-      SPACESHIP_CHAR_SYMBOL = "λ ";
-      SPACESHIP_TIME_SHOW = "true";
-      SPACESHIP_USER_SHOW = "always";
-      SPACESHIP_HOST_SHOW = "always";
-      NIX_BUILD_SHELL = "${pkgs.zsh-nix-shell}/scripts/buildShellShim.zsh";
-      PROMPT = "\\\${IN_NIX_SHELL:+[nix-shell] }$PROMPT";
-    };
     loginExtra = "[[ -z $DISPLAY && $TTY = /dev/tty1 ]] && exec sway";
     envExtra = ''
       [ $TERM = "dumb" ] && unsetopt zle && PS1='$ ' # for Emacs TRAMP mode
@@ -84,5 +82,8 @@
     thefuck
     htop-vim
     dig.dnsutils
+    zsh-completions
+    nix-zsh-completions
+    gnuapl
   ];
 }
diff --git a/hmModules/sway/default.nix b/hmModules/sway/default.nix
index 487bf42..b2d3f59 100644
--- a/hmModules/sway/default.nix
+++ b/hmModules/sway/default.nix
@@ -29,7 +29,7 @@
       };
     };
 
-    # TODO check if work (just wait?)
+    # TODO check if it works (just wait?)
     services.swayidle.enable = true;
 
     wayland = {
@@ -62,7 +62,6 @@
             "1" = [{title = ".*Mozilla Firefox$";} {title = ".*qutebrowser$";}];
             "2" = [{title = "^((?!qutebrowser-editor).)*Emacs$";}];
             "3" = [{title = "Slack.*";}];
-            "8" = [{title = "^Franz$";}];
             "9" = [{title = "^Element.*";}];
           };
           floating.criteria = [
@@ -89,12 +88,16 @@
               ${pkgs.wf-recorder}/bin/wf-recorder -g "$coords" -f "$filename"
               wl-copy -t video/mp4 < $filename
             '';
+            emacsclientAsTerminal = pkgs.writeShellScript "emacsclientAsTerminal" ''
+              emacsclient -c -F '\\'(name . "VTerm"))' -q --eval '\\'(vterm "/bin/zsh")'
+            '';
           in
             lib.mkOptionDefault {
               "${modifier}+x" = "exec emacsclient -c";
               "${modifier}+b" = "exec qutebrowser";
               "${modifier}+s" = "exec ${screenshotScript}";
               "${modifier}+g" = "exec ${screenrecordingScript}";
+              # "${modifier}+Shift+Enter" = "exec ${emacsclientAsTerminal}"; # FIXME
               "XF86MonBrightnessUp" = "exec ${pkgs.brightnessctl}/bin/brightnessctl s +5%";
               "XF86MonBrightnessDown" = "exec ${pkgs.brightnessctl}/bin/brightnessctl s 5%-";
             };
diff --git a/hmModules/sway/style.css b/hmModules/sway/style.css
index 9c219e5..ccaf823 100644
--- a/hmModules/sway/style.css
+++ b/hmModules/sway/style.css
@@ -1,67 +1,39 @@
 * {
-    border: none;
-    font-family: "Fira Code, Symbols Nerd Font";
-    font-weight: normal;
-    font-size: 9pt;
-    min-height: 0;
+  border: none;
+  border-radius: 0;
+  min-height: 0;
 }
 
 window#waybar {
-    background-color: rgba(43, 48, 59, 0.5);
-    border-bottom: 3px solid rgba(100, 114, 125, 0.5);
-    color: #ffffff;
-    transition-property: background-color;
-    transition-duration: .5s;
-}
-
-window .modules-right :not(image) {  /* :not(image) excluded tray icon */
-    margin: 0 1rem;
-}
-
-window#waybar.hidden {
-    opacity: 0.2;
+  background: @theme_bg_color;
+  color: @theme_fg_color;
 }
 
 #workspaces button {
-    padding: 0 5px;
-    background-color: transparent;
-    color: #ffffff;
-}
-
-#workspaces button label {
-    font-size: 25px;
-}
-
-/* https://github.com/Alexays/Waybar/wiki/FAQ#the-workspace-buttons-have-a-strange-hover-effect */
-#workspaces button:hover {
-    background: rgba(0, 0, 0, 0.2);
-}
-
-#workspaces button.current_output {
-    border-bottom: 3px solid #64727D;
+  padding: 0 10px;
+  /* background: transparent; */
+  /* color: @theme_fg_color; */
 }
 
 #workspaces button.focused {
-    background-color: #64727D;
-}
-
-#workspaces button.focused.current_output {
-    border-bottom: 3px solid #ffffff;
+  /* background: @theme_bg_color; */
+  border-bottom: 3px solid @theme_fg_color;
+  /* color: @theme_fg_color; */
 }
 
 #workspaces button.urgent {
-    background-color: #eb4d4b;
+  /* background: @theme_fg_color; */
+  /* color: @theme_selected_bg_color; */
 }
 
-
-
-@keyframes blink {
-    to {
-        background-color: #ffffff;
-        color: #000000;
-    }
+#mode {
+  margin: 0 4px;
+  padding: 0 4px;
+  /* background: @theme_fg_color; */
+  /* color: @unfocused_borders; */
 }
 
-label:focus {
-    background-color: #000000;
+#pulseaudio, #network, #cpu, #memory, #disk, #temperature, #battery, #language, #clock, #tray {
+  margin: 0 4px;
+  padding: 0 2px;
 }
diff --git a/hmModules/sway/waybar.nix b/hmModules/sway/waybar.nix
index f03cf77..9f9c875 100644
--- a/hmModules/sway/waybar.nix
+++ b/hmModules/sway/waybar.nix
@@ -34,10 +34,8 @@
             "1" = "";
             "2" = "";
             "3" = "";
-            "8" = "甆";
             "9" = "ﬧ";
             urgent = "";
-            default = "";
           };
           sort-by-number = true;
         };
diff --git a/hosts/thinkpad/default.nix b/hosts/thinkpad/default.nix
index 2f8bdb3..21e0ee6 100644
--- a/hosts/thinkpad/default.nix
+++ b/hosts/thinkpad/default.nix
@@ -40,6 +40,7 @@
       "discord"
       "element"
       "emacs"
+      "email"
       "firefox"
       "git"
       "gpg"
@@ -53,7 +54,6 @@
       "sway"
       "udiskie"
       "vscode"
-      "franz"
       "xdg"
       "zathura"
     ];
diff --git a/hosts/thinkpad/hardware-configuration.nix b/hosts/thinkpad/hardware-configuration.nix
index 7d48cf3..d3e3f6f 100644
--- a/hosts/thinkpad/hardware-configuration.nix
+++ b/hosts/thinkpad/hardware-configuration.nix
@@ -73,5 +73,7 @@
   powerManagement.cpuFreqGovernor = lib.mkDefault "powersave";
   hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
 
-  services.throttled.enable = true;
+  services.throttled = {
+    enable = true;
+  };
 }
diff --git a/modules/adb/default.nix b/modules/adb/default.nix
index 85ded03..3abb9bd 100644
--- a/modules/adb/default.nix
+++ b/modules/adb/default.nix
@@ -1,9 +1,4 @@
 {
-  config,
-  lib,
-  pkgs,
-  ...
-}: {
   programs.adb.enable = true;
   users.users.ccr.extraGroups = ["adbusers"];
 }
diff --git a/modules/ccr/default.nix b/modules/ccr/default.nix
index d5bd0c8..a15e8cc 100644
--- a/modules/ccr/default.nix
+++ b/modules/ccr/default.nix
@@ -64,7 +64,15 @@
     home-manager.useGlobalPkgs = true;
     home-manager.useUserPackages = true;
     home-manager.users.ccr = {
-      imports = fleetHmModules config.ccr.modules;
+      imports =
+        fleetHmModules config.ccr.modules
+        ++ [
+          {
+            _module.args = {
+              secrets = config.age.secrets;
+            };
+          }
+        ];
       home.packages = config.ccr.packages;
       home.stateVersion = config.system.stateVersion;
     };
diff --git a/secrets/autistici-password.age b/secrets/autistici-password.age
new file mode 100644
index 0000000..fe2962c
--- /dev/null
+++ b/secrets/autistici-password.age
@@ -0,0 +1,19 @@
+age-encryption.org/v1
+-> ssh-rsa QHr3/A
+htmJ7Ita9rp1TshaeTq14G7Z8vUmsHG8cvcbiT+X7acGx/W79zUjM0r1KiBwyD75
+SqLMhlLylaPCf7wjoL800UZ/nlQsXCCOgETKFbJH7jJIJhsYIzWOWwVScXjRNRqY
+xp1Y+TTnyao0gzTv2uFJy2w2cg2VM+f+UXOeoQ6gUGxFHvwsuRDorXu2n/JHXh/R
+kiNZGBi9tx93F3jAsHM6Sudq7j1HsJwQZO6vaHwuqxankHX5CpXXo8bHY1pE+smG
+yO92qJ4cxSB/A9T2PXr20EDmj1Nr4pbk12Tn69GZasSKAlyUo0SDUW6BVFHwDf8E
+L3K6XKyGuUcZsd5Hh26deT7kAYwUbD5Edlyhgc8Rp9/rX2qEG5i196/tLL0ngI4G
+xoHwHhnVUC0IULOizzPbxtnat1cCIhcSbncKv6wnBnlXHDivJV8Vg0YGnzmYy0j8
+TbVN76OsNrU8zXXTGjLO6Gp+AEPIk5Z72Snpoq5Io4H+IoNuX0hYGbMrPQg0Urnn
+gM2/EN2ivCKfMMNWI6sq0FJy4IsGNsVLM98VmAh9pfWXGFjz3So9cYMwYCqG0vbP
+HQQKqsmxbdJljxGix7Z5SpIl6bDuS66hJpEA6wlvGcUmXzy+kFnlTNmmFwovfotX
+wIPYTJZGtXh0WNsIuVnPYSZ6MahBswKzHcI+az48PvM
+-> u!n2o-grease
++fY6SvlSCYFsB0/7dxDJtw7zKufZ9LZUZ7tqVaJkdjSl9y/2fDGVQHFKFXBGhHKu
+wcIB
+--- hBiR9gBibjABVhE5I42l1zepYvWZq3qsqXk9Y8qlTno
+��蹿\Ѓ-
+(>2�A����^� l[CPW@�ϛ���dj
\ No newline at end of file
diff --git a/secrets/default.nix b/secrets/default.nix
index bd09263..d1ec3f4 100644
--- a/secrets/default.nix
+++ b/secrets/default.nix
@@ -4,4 +4,5 @@ let
   };
 in {
   "secrets/mlabs-cachix.age".publicKeys = [keys.agenix];
+  "secrets/autistici-password.age".publicKeys = [keys.agenix];
 }
diff --git a/utils/default.nix b/utils/default.nix
index 5a24974..30638bc 100644
--- a/utils/default.nix
+++ b/utils/default.nix
@@ -34,7 +34,13 @@
             home-manager.users.ccr.imports = [
               doomEmacs.hmModule
             ];
-            age.identityPaths = ["/home/ccr/.ssh/id_rsa"];
+            age = {
+              identityPaths = ["/home/ccr/.ssh/id_rsa"];
+              secrets = lib.mapAttrs' (name: _: {
+                name = lib.removeSuffix ".age" (builtins.baseNameOf name);
+                value.file = ./.. + "/${name}";
+              }) (import ../secrets);
+            };
             nixpkgs.overlays = [agenix.overlay comma.overlays.default];
           }
           (../hosts + "/${name}")