From 0934df7b6f6af5919a865a0357e7063b4cf9b436 Mon Sep 17 00:00:00 2001
From: matt1432 <matt@nelim.org>
Date: Tue, 20 Jun 2023 15:35:36 +0200
Subject: [PATCH] fix: use ssh-askpass to use gparted

---
 nixos/cfg/home-manager.nix |  46 ++++++++++--
 nixos/configuration.nix    | 145 ++-----------------------------------
 2 files changed, 44 insertions(+), 147 deletions(-)

diff --git a/nixos/cfg/home-manager.nix b/nixos/cfg/home-manager.nix
index b9ccfdf8..67665c3a 100644
--- a/nixos/cfg/home-manager.nix
+++ b/nixos/cfg/home-manager.nix
@@ -6,6 +6,16 @@
       <home-manager/nixos>
     ];
 
+  # Define a user account. Don't forget to set a password with 'passwd'.
+  users.users.matt = {
+    isNormalUser = true;
+    extraGroups = [ "wheel" "input" "adm" "mlocate" "video" ];
+  #   packages = with pkgs; [
+  #     firefox
+  #     tree
+  #   ];
+  };
+
   home-manager.useGlobalPkgs = true;
   programs.dconf.enable = true;
 
@@ -27,7 +37,6 @@
     
     home.packages = with pkgs; 
       (with xorg; [
-        xhost # for gparted
         xcursorthemes
 
       ]) ++
@@ -37,10 +46,18 @@
 
       ]) ++
       (with plasma5Packages; [
+        polkit-kde-agent
         qtstyleplugin-kvantum
         breeze-icons
-        dolphin # install plugins
-        kio-admin # dbus issues
+        dolphin
+        dolphin-plugins
+        ffmpegthumbs
+        kio-admin # needs to be both here and in system pkgs
+        ark
+        kcharselect
+        #kdenlive
+        kmime
+        okular
 
       ]) ++
       (with gnome; [
@@ -59,14 +76,11 @@
       neofetch
       photoqt
       progress
-      tlp
       wl-color-picker # add bind for this in hyprland
       xclip
       xdg-utils
-      zathura # set default
       pavucontrol # TODO: open on left click
       gimp-with-plugins
-      gparted # doesn't open without sudo
       jdk8_headless
       bluez-tools
       spotify
@@ -97,7 +111,6 @@
       swayidle
       wl-clipboard
       cliphist
-      polkit-kde-agent
       gtklock
       gtklock-playerctl-module
       gtklock-powerbar-module
@@ -115,10 +128,26 @@
       squeekboard
       glib
       appimage-run
+      gparted # doesn't open without sudo
+      (writeShellScriptBin "Gparted" ''
+        (
+          sleep 0.5
+          while killall -r -0 ksshaskpass > /dev/null 2>&1
+          do
+	    sleep 0.1
+	    if [[ $(hyprctl activewindow | grep Ksshaskpas) == "" ]]; then
+	      killall -r ksshaskpass
+	    fi
+          done
+        ) &
+
+        exec sudo -k -EA '${gparted}/bin/${gparted.pname}' "$@"
+      '')
     ];
 
     home.sessionVariables = {
       XDG_DATA_DIRS = "${pkgs.gsettings-desktop-schemas}/share/gsettings-schemas/${pkgs.gsettings-desktop-schemas.name}:\$XDG_DATA_DIRS";
+      SUDO_ASKPASS= "${pkgs.plasma5Packages.ksshaskpass}/bin/${pkgs.plasma5Packages.ksshaskpass.pname}";
     };
 
     imports = [
@@ -133,8 +162,11 @@
       ];
 
       extraConfig = ''
+        exec-once = ${pkgs.plasma5Packages.polkit-kde-agent}/libexec/polkit-kde-authentication-agent-1
         source = ~/.config/hypr/main.conf
         env = XDG_DATA_DIRS, ${pkgs.gsettings-desktop-schemas}/share/gsettings-schemas/${pkgs.gsettings-desktop-schemas.name}:$XDG_DATA_DIRS
+        env = SUDO_ASKPASS, ${pkgs.plasma5Packages.ksshaskpass}/bin/${pkgs.plasma5Packages.ksshaskpass.pname}
+
       '';
     };
 
diff --git a/nixos/configuration.nix b/nixos/configuration.nix
index 08504bfa..63fa32a4 100644
--- a/nixos/configuration.nix
+++ b/nixos/configuration.nix
@@ -4,78 +4,22 @@
   imports =
     [ # Include the results of the hardware scan.
       ./hardware-configuration.nix
+      ./overlays/list.nix
       ./cfg/boot.nix
       ./cfg/security.nix
       ./cfg/extra-hardware.nix
-      ./overlays/list.nix
+      ./cfg/services.nix
+      ./cfg/packages.nix
       ./cfg/home-manager.nix
     ];
 
-  services.xserver = {
-    enable = true;
-    layout = "ca";
-    displayManager = {
-      gdm.enable = true;
-      gdm.wayland = true;
-      sessionPackages = [ pkgs.hyprland pkgs.gnome.gnome-session.sessions ];
-    };
-  };
-
-  services.locate = {
-    enable = true;
-    interval = "hourly";
-    prunePaths = [
-      "/tmp"
-      "/var/tmp"
-      "/var/cache"
-      "/var/lock"
-      "/var/run"
-      "/var/spool"
-      "/nix/var/log/nix"
-      "/proc"
-    ];
-  };
-
-  programs.tmux = {
-    enable = true;
-    keyMode = "vi";
-    terminal = "screen-256color";
-    newSession = true;
-    historyLimit = 30000;
-    extraConfig = ''
-      bind-key -n Home send Escape "OH"
-      bind-key -n End send Escape "OF"
-      set -g mouse on
-      set -ga terminal-overrides ',xterm*:smcup@:rmcup@'
-      bind -T root WheelUpPane   if-shell -F -t = "#{alternate_on}" "send-keys -M" "select-pane -t =; copy-mode -e; send-keys -M"
-      bind -T root WheelDownPane if-shell -F -t = "#{alternate_on}" "send-keys -M" "select-pane -t =; send-keys -M"
-    '';
-  };
-  
-  programs.git = { # TODO: make better config
-    enable = true;
-    lfs.enable = true;
-  };
-
-  programs.htop = {
-    enable = true;
-  };
-
-  programs.fzf = {
-    fuzzyCompletion = true;
-    keybindings = true;
-  };
-
   networking.hostName = "wim";
   networking.networkmanager.enable = true;
   networking.networkmanager.wifi.backend = "iwd";
 
   # Set your time zone.
-  time.timeZone = "America/Montreal";
-
-  # Configure network proxy if necessary
-  # networking.proxy.default = "http://user:password@proxy:port/";
-  # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";
+  #time.timeZone = "America/Montreal";
+  time.timeZone = "Europe/Paris";
 
   # Select internationalisation properties.
   i18n.defaultLocale = "en_CA.UTF-8";
@@ -84,89 +28,10 @@
     keyMap = "ca";
     #useXkbConfig = true; # use xkbOptions in tty.
   };
-
-  virtualisation = {
-    waydroid.enable = true;
-    lxd.enable = true;
-  };
-
-  services.dbus.enable = true;
-
-  xdg.portal.enable = true;
-  xdg.portal.extraPortals = [ 
-    pkgs.xdg-desktop-portal-hyprland
-  ];
-  services.flatpak.enable = true;
-
-  # Enable touchpad support (enabled default in most desktopManager).
-  # services.xserver.libinput.enable = true;
-
-  # Define a user account. Don't forget to set a password with 'passwd'.
-  users.users.matt = {
-    isNormalUser = true;
-    extraGroups = [ "wheel" "input" "adm" "mlocate" "video" ];
-  #   packages = with pkgs; [
-  #     firefox
-  #     tree
-  #   ];
-  };
   
   nix.settings.experimental-features = [ "nix-command" "flakes" ];
   nixpkgs.config.allowUnfree = true;
 
-  # List packages in root user PATH
-  environment.systemPackages = with pkgs; [
-    wl-clipboard
-    alsa-utils
-    wget
-    tree
-    rsync
-    killall
-    ripgrep-all
-    neovim # TODO: use nix
-    imagemagick
-    usbutils
-    evtest
-  ];
-
-  fonts = {
-    fontconfig = {
-      enable = true;
-      defaultFonts = {
-        #emoji = [ "Noto Color Emoji" ];
-        #monospace = [ "MesloLGS Nerd Font" ];
-        #sansSerif = [ "MesloLGS Nerd Font" ];
-        #serif = [ "MesloLGS Nerd Font" ];
-      };
-    };
-    fonts = with pkgs; [
-      (nerdfonts.override { fonts = [ "JetBrainsMono" "Go-Mono" "Iosevka" "NerdFontsSymbolsOnly" "SpaceMono" "Ubuntu" ]; })
-      noto-fonts
-      noto-fonts-cjk
-      noto-fonts-emoji
-      liberation_ttf
-      font-awesome
-      meslo-lgs-nf
-      jetbrains-mono
-      #google-fonts
-      ubuntu_font_family
-    ];
-  };
-
-  # Some programs need SUID wrappers, can be configured further or are
-  # started in user sessions.
-  # programs.mtr.enable = true;
-  # programs.gnupg.agent = {
-  #   enable = true;
-  #   enableSSHSupport = true;
-  # };
-
-  programs.waybar = {
-    enable = true;
-    package = pkgs.waybar.overrideAttrs (oldAttrs: {
-      mesonFlags = oldAttrs.mesonFlags ++ [ "-Dexperimental=true" ];
-    });
-  };
 
   # TODO: see if setting them in Hyprland.nix works
   environment.sessionVariables = {