From be0c1d1b4b62c9ded56854c8c4a3b0936a874438 Mon Sep 17 00:00:00 2001
From: Nydragon <contact@ccnlc.eu>
Date: Mon, 8 Jul 2024 00:05:18 +0200
Subject: [PATCH] feat: add lib override with binary path validation

---
 flake.nix                       |  9 +++++-
 home/fish/default.nix           | 49 ++++++++++++++++++---------------
 home/fish/rename_images.fish    |  7 -----
 home/hyprland/default.nix       |  2 +-
 home/sway/default.nix           |  3 +-
 home/waybar/style.scss          |  2 +-
 hosts/brontes/configuration.nix |  3 ++
 hosts/brontes/home.nix          |  1 +
 hosts/marr/home.nix             |  1 +
 lib/default.nix                 | 12 ++++++++
 modules/programs/firefox.nix    |  4 ++-
 11 files changed, 58 insertions(+), 35 deletions(-)
 delete mode 100644 home/fish/rename_images.fish
 create mode 100644 lib/default.nix

diff --git a/flake.nix b/flake.nix
index 992a321..56f2d99 100644
--- a/flake.nix
+++ b/flake.nix
@@ -32,7 +32,14 @@
 
       };
 
-      lib = nixpkgs.lib;
+      lib = nixpkgs.lib.extend (
+        self: super: {
+          my = import ./lib {
+            inherit pkgs inputs;
+            lib = self;
+          };
+        }
+      );
 
       mkSystem =
         {
diff --git a/home/fish/default.nix b/home/fish/default.nix
index a7f17a5..b01ff65 100644
--- a/home/fish/default.nix
+++ b/home/fish/default.nix
@@ -1,10 +1,9 @@
-{ pkgs, ... }:
+{ pkgs, lib, ... }:
 {
   programs.fish = {
     enable = true;
     shellAbbrs = {
       clip = "wl-copy";
-      dp = "env --chdir ~/.dotfiles/ ${pkgs.dotter}/bin/dotter deploy -v";
       l = "eza -laa";
       ls = "eza -la";
       ll = "eza -l";
@@ -14,25 +13,31 @@
       cp = "cp -i";
       mv = "mv -i";
     };
-    functions =
-      let
-        rf = builtins.readFile;
-      in
-      {
-        gitignore = "curl -sL https://www.gitignore.io/api/$argv";
-        nrun = "nix run nixpkgs#$argv[1] -- $argv[2..]";
-        mv-bad-creation-date = ''exiftool -if 'not $CreateDate' -p '$FileName' "$PWD/$argv[1]" | xargs -I {} mv -i "$PWD/$argv[1]/{}" "$argv[2]"'';
-        rename-images = rf ./rename_images.fish;
-        fish_prompt = rf ./fish_prompt.fish;
-        rebuild = ''
-          env --chdir $HOME/.nixconf sudo nixos-rebuild switch --flake .#$(hostname) \
-          && ${pkgs.libnotify}/bin/notify-send nixos-rebuild "Rebuild complete" \
-              -a nixos-rebuild \
-              -i ${pkgs.nixos-icons}/share/icons/hicolor/scalable/apps/nix-snowflake.svg
-        '';
-        revert = ''
-          env --chdir $HOME/.nixconf sudo nixos-rebuild switch --flake .#$(hostname) --rollback
-        '';
-      };
+    functions = {
+      gitignore = "curl -sL https://www.gitignore.io/api/$argv";
+      nrun = "nix run nixpkgs#$argv[1] -- $argv[2..]";
+      mv-bad-creation-date = ''
+        ${lib.my.checkPath pkgs.exiftool "exiftool"} -if 'not $CreateDate' -p '$FileName' "$PWD/$argv[1]" | xargs -I {} mv -i "$PWD/$argv[1]/{}" "$argv[2]"
+      '';
+      rename-images = ''
+        set -f input "$PWD/$argv[1]"
+
+        if not test -d $input
+            echo "input is not a directory"
+        else
+            ${lib.my.checkPath pkgs.exiftool "exiftool"} -if '$CreateDate' -p '$FileName' "$input" | xargs -I {} jhead -n%Y-%m-%d-%H%M%S "$input/{}"
+        end
+      '';
+      fish_prompt = builtins.readFile ./fish_prompt.fish;
+      rebuild = ''
+        env --chdir $HOME/.nixconf sudo nixos-rebuild switch --flake .#$(hostname) \
+        && ${lib.my.checkPath pkgs.libnotify "notify-send"} nixos-rebuild "Rebuild complete" \
+            -a nixos-rebuild \
+            -i ${pkgs.nixos-icons}/share/icons/hicolor/scalable/apps/nix-snowflake.svg
+      '';
+      revert = ''
+        env --chdir $HOME/.nixconf sudo nixos-rebuild switch --flake .#$(hostname) --rollback
+      '';
+    };
   };
 }
diff --git a/home/fish/rename_images.fish b/home/fish/rename_images.fish
deleted file mode 100644
index 28eb361..0000000
--- a/home/fish/rename_images.fish
+++ /dev/null
@@ -1,7 +0,0 @@
-set -f input "$PWD/$argv[1]"
-
-if not test -d $input
-    echo "input is not a directory"
-else
-    exiftool -if '$CreateDate' -p '$FileName' "$input" | xargs -I {} jhead -n%Y-%m-%d-%H%M%S "$input/{}"
-end
diff --git a/home/hyprland/default.nix b/home/hyprland/default.nix
index c324495..7a0c2e3 100644
--- a/home/hyprland/default.nix
+++ b/home/hyprland/default.nix
@@ -137,7 +137,7 @@ lib.mkIf osConfig.programs.hyprland.enable {
           #"$mod, S, exec, rofi -show clipboard -show-icons"
           "$mod SHIFT, Q, killactive,"
           "$mod SHIFT, P, exec, rofi -show p -modi p:${pkgs.rofi-power-menu}/bin/rofi-power-menu"
-          "$mod, P, exec, cliphist wipe & ${pkgs.hyprlock}/bin/hyprlock"
+          "$mod, P, exec, ${pkgs.cliphist}/bin/cliphist wipe & ${pkgs.hyprlock}/bin/hyprlock"
           "$mod SHIFT, C, exec, hyprctl reload"
           "$mod, left, movefocus, l"
           "$mod, right, movefocus, r"
diff --git a/home/sway/default.nix b/home/sway/default.nix
index 0de6574..26145f5 100644
--- a/home/sway/default.nix
+++ b/home/sway/default.nix
@@ -60,8 +60,7 @@
             mod = config.wayland.windowManager.sway.config.modifier;
           in
           lib.mkOptionDefault {
-            # TODO: Update to use nixpkgs version of cliphist
-            "${mod}+p" = "exec cliphist wipe & ${pkgs.swaylock}/bin/swaylock";
+            "${mod}+p" = "exec ${pkgs.cliphist}/bin/cliphist wipe & ${pkgs.swaylock}/bin/swaylock";
             "${mod}+Shift+p" = "exec rofi -show p -modi p:${pkgs.rofi-power-menu}/bin/rofi-power-menu";
             # Reload the config file
             "${mod}+Shift+c" = "reload";
diff --git a/home/waybar/style.scss b/home/waybar/style.scss
index 0c91745..0b6a764 100644
--- a/home/waybar/style.scss
+++ b/home/waybar/style.scss
@@ -22,7 +22,7 @@
 }
 
 * {
-  font-family: "DejaVuSansMNerdFont-Regular";
+  font-family: "NotoSerifNerdFont-Regular";
   border: none;
   opacity: 50;
   border-radius: 10px;
diff --git a/hosts/brontes/configuration.nix b/hosts/brontes/configuration.nix
index 519c009..76075a6 100644
--- a/hosts/brontes/configuration.nix
+++ b/hosts/brontes/configuration.nix
@@ -80,6 +80,9 @@
     };
   };
 
+  # Necessary for Nautilus to display trash, DVDs and for gnome-disk-utility to show file systems
+  services.gvfs.enable = true;
+
   programs.gnupg.agent = {
     enable = true;
     enableSSHSupport = true;
diff --git a/hosts/brontes/home.nix b/hosts/brontes/home.nix
index 11b43cf..8ac0bae 100644
--- a/hosts/brontes/home.nix
+++ b/hosts/brontes/home.nix
@@ -74,6 +74,7 @@
         lazygit
         fd
         ripgrep
+        wl-clipboard
 
         custom.scripts.nixedit
       ];
diff --git a/hosts/marr/home.nix b/hosts/marr/home.nix
index 1e7e15c..96dbcd3 100644
--- a/hosts/marr/home.nix
+++ b/hosts/marr/home.nix
@@ -74,6 +74,7 @@
         fd
         ripgrep
         swaybg
+        wl-clipboard
 
         custom.scripts.screenshot
         custom.scripts.nixedit
diff --git a/lib/default.nix b/lib/default.nix
new file mode 100644
index 0000000..e963d91
--- /dev/null
+++ b/lib/default.nix
@@ -0,0 +1,12 @@
+{ lib, ... }:
+{
+
+  # Verify the existence of a binary inside of a derivation.
+  # Returns the path to the binary or throws.
+  checkPath =
+    pkg: bin:
+    let
+      abs = lib.getExe' pkg bin;
+    in
+    if builtins.pathExists abs then abs else throw "${abs} does not exist.";
+}
diff --git a/modules/programs/firefox.nix b/modules/programs/firefox.nix
index ea28cc7..99823a6 100644
--- a/modules/programs/firefox.nix
+++ b/modules/programs/firefox.nix
@@ -1,4 +1,6 @@
-# Reference https://discourse.nixos.org/t/declare-firefox-extensions-and-settings/36265
+# References:
+# https://discourse.nixos.org/t/declare-firefox-extensions-and-settings/36265
+# https://github.com/gvolpe/nix-config/blob/6feb7e4f47e74a8e3befd2efb423d9232f522ccd/home/programs/browsers/firefox.nix
 { lib, config, ... }:
 lib.mkIf config.programs.firefox.enable {
   programs.firefox = {