From 4f9073757cf864d88ba7d7843615658327038970 Mon Sep 17 00:00:00 2001
From: Oliver Davies <oliver@oliverdavies.dev>
Date: Tue, 5 Nov 2024 12:00:00 +0000
Subject: [PATCH] Refactor vim plugins overlay

Add overlays for additions, modifications and unstable packages, and
move each additional plugin into its own additional package.
---
 flake.nix                                 |  14 ++-
 lib/nixos/configuration.nix               |   7 +-
 lib/nixos/default.nix                     |   2 +
 lib/wsl2/default.nix                      |   7 +-
 overlays/default.nix                      |  20 ++++
 overlays/vim-plugins-overlay.nix          | 130 ----------------------
 pkgs/default.nix                          |  20 ++++
 pkgs/vim-plugins/conf-vim.nix             |  11 ++
 pkgs/vim-plugins/edit-alternate-vim.nix   |  11 ++
 pkgs/vim-plugins/nvim-tmux-navigation.nix |  11 ++
 pkgs/vim-plugins/standard-vim.nix         |  11 ++
 pkgs/vim-plugins/tabline-vim.nix          |  11 ++
 pkgs/vim-plugins/vim-autoread.nix         |  11 ++
 pkgs/vim-plugins/vim-caser.nix            |  11 ++
 pkgs/vim-plugins/vim-heritage.nix         |  11 ++
 pkgs/vim-plugins/vim-textobj-indent.nix   |  11 ++
 pkgs/vim-plugins/vim-textobj-xmlattr.nix  |  11 ++
 pkgs/vim-plugins/vim-zoom.nix             |  11 ++
 18 files changed, 188 insertions(+), 133 deletions(-)
 create mode 100644 overlays/default.nix
 delete mode 100644 overlays/vim-plugins-overlay.nix
 create mode 100644 pkgs/default.nix
 create mode 100644 pkgs/vim-plugins/conf-vim.nix
 create mode 100644 pkgs/vim-plugins/edit-alternate-vim.nix
 create mode 100644 pkgs/vim-plugins/nvim-tmux-navigation.nix
 create mode 100644 pkgs/vim-plugins/standard-vim.nix
 create mode 100644 pkgs/vim-plugins/tabline-vim.nix
 create mode 100644 pkgs/vim-plugins/vim-autoread.nix
 create mode 100644 pkgs/vim-plugins/vim-caser.nix
 create mode 100644 pkgs/vim-plugins/vim-heritage.nix
 create mode 100644 pkgs/vim-plugins/vim-textobj-indent.nix
 create mode 100644 pkgs/vim-plugins/vim-textobj-xmlattr.nix
 create mode 100644 pkgs/vim-plugins/vim-zoom.nix

diff --git a/flake.nix b/flake.nix
index df8aec0c..ad540163 100644
--- a/flake.nix
+++ b/flake.nix
@@ -19,6 +19,8 @@
       ...
     }@inputs:
     let
+      inherit (self) outputs;
+
       system = "x86_64-linux";
       pkgs = nixpkgs.legacyPackages.${system};
 
@@ -27,13 +29,21 @@
       mkNixos = import ./lib/nixos {
         inherit
           inputs
+          outputs
           nixos-hardware
           pkgs
           self
           username
           ;
       };
-      mkWsl = import ./lib/wsl2 { inherit inputs self username; };
+      mkWsl = import ./lib/wsl2 {
+        inherit
+          inputs
+          outputs
+          self
+          username
+          ;
+      };
 
       inherit (pkgs) mkShell;
       inherit (pkgs.vimUtils) buildVimPlugin;
@@ -50,6 +60,8 @@
 
       formatter.${system} = pkgs.nixfmt-rfc-style;
 
+      overlays = import ./overlays { inherit inputs; };
+
       nixosConfigurations = {
         lemp11 = mkNixos {
           desktop = true;
diff --git a/lib/nixos/configuration.nix b/lib/nixos/configuration.nix
index 95d57735..7a3e9525 100644
--- a/lib/nixos/configuration.nix
+++ b/lib/nixos/configuration.nix
@@ -1,5 +1,6 @@
 {
   inputs,
+  outputs,
   desktop ? false,
   hostname,
   self,
@@ -18,7 +19,11 @@ in
       permittedInsecurePackages = [ "electron-27.3.11" ];
     };
 
-    overlays = [ (import "${self}/overlays/vim-plugins-overlay.nix") ];
+    overlays = [
+      outputs.overlays.additions
+      outputs.overlays.modifications
+      outputs.overlays.unstable-packages
+    ];
   };
 
   nix.nixPath = [ "nixpkgs=${inputs.nixpkgs}" ];
diff --git a/lib/nixos/default.nix b/lib/nixos/default.nix
index 1446396b..173e486d 100644
--- a/lib/nixos/default.nix
+++ b/lib/nixos/default.nix
@@ -1,5 +1,6 @@
 {
   inputs,
+  outputs,
   nixos-hardware,
   pkgs,
   self,
@@ -12,6 +13,7 @@
 let
   configuration = import ./configuration.nix {
     inherit
+      outputs
       desktop
       hostname
       inputs
diff --git a/lib/wsl2/default.nix b/lib/wsl2/default.nix
index 5e3c55af..0b4224f3 100644
--- a/lib/wsl2/default.nix
+++ b/lib/wsl2/default.nix
@@ -1,5 +1,6 @@
 {
   inputs,
+  outputs,
   self,
   username,
 }:
@@ -9,7 +10,11 @@ let
   inherit (pkgs) lib;
 
   pkgs = import inputs.nixpkgs {
-    overlays = [ (import "${self}/overlays/vim-plugins-overlay.nix") ];
+    overlays = [
+      outputs.overlays.additions
+      outputs.overlays.modifications
+      outputs.overlays.unstable-packages
+    ];
   };
 
   shared-config = import "${self}/lib/shared/home-manager.nix" {
diff --git a/overlays/default.nix b/overlays/default.nix
new file mode 100644
index 00000000..a9643c2d
--- /dev/null
+++ b/overlays/default.nix
@@ -0,0 +1,20 @@
+{ inputs, ... }:
+
+{
+  additions =
+    final: prev:
+    import ../pkgs {
+      inherit prev;
+
+      pkgs = final;
+    };
+
+  modifications = final: prev: { };
+
+  unstable-packages = final: _prev: {
+    unstable = import inputs.nixpkgs-unstable {
+      config.allowUnfree = true;
+      system = final.system;
+    };
+  };
+}
diff --git a/overlays/vim-plugins-overlay.nix b/overlays/vim-plugins-overlay.nix
deleted file mode 100644
index 8b9dc8bf..00000000
--- a/overlays/vim-plugins-overlay.nix
+++ /dev/null
@@ -1,130 +0,0 @@
-final: prev:
-
-let
-  inherit (final) fetchFromGitHub;
-  inherit (final.vimUtils) buildVimPlugin;
-in
-{
-  vimPlugins = prev.vimPlugins // {
-    conf-vim = buildVimPlugin {
-      name = "conf-vim";
-      src = fetchFromGitHub {
-        owner = "tjdevries";
-        repo = "conf.vim";
-        rev = "master";
-        sha256 = "AjiTJsoim0BAnyfqk1IQzNsa6jhFM2+A66E7q9sJqz0=";
-      };
-    };
-
-    edit-alternate-vim = buildVimPlugin {
-      name = "edit-alternate-vim";
-      src = fetchFromGitHub {
-        owner = "tjdevries";
-        repo = "edit_alternate.vim";
-        rev = "master";
-        sha256 = "mEKnqYAhgrdxPRoKf4S4yYecdFIHGg8bDxpqPuC1+S4=";
-      };
-    };
-
-    nvim-tmux-navigation = buildVimPlugin {
-      name = "nvim-tmux-navigation";
-      src = fetchFromGitHub {
-        owner = "alexghergh";
-        repo = "nvim-tmux-navigation";
-        rev = "4898c98702954439233fdaf764c39636681e2861";
-        sha256 = "sha256-CxAgQSbOrg/SsQXupwCv8cyZXIB7tkWO+Y6FDtoR8xk=";
-      };
-    };
-
-    standard-vim = buildVimPlugin {
-      name = "standard-vim";
-      src = fetchFromGitHub {
-        owner = "tjdevries";
-        repo = "standard.vim";
-        rev = "master";
-        sha256 = "9VwkvV1Dv6cE4uDkPp36DozjWJOclDR883yDMYw000E=";
-      };
-    };
-
-    vim-autoread = buildVimPlugin {
-      name = "vim-autoread";
-      src = fetchFromGitHub {
-        owner = "djoshea";
-        repo = "vim-autoread";
-        rev = "24061f84652d768bfb85d222c88580b3af138dab";
-        sha256 = "fSADjNt1V9jgAPjxggbh7Nogcxyisi18KaVve8j+c3w=";
-      };
-    };
-
-    vim-textobj-indent = buildVimPlugin {
-      name = "vim-textobj-indent";
-      src = fetchFromGitHub {
-        owner = "kana";
-        repo = "vim-textobj-indent";
-        rev = "deb76867c302f933c8f21753806cbf2d8461b548";
-        sha256 = "oFzUPG+IOkbKZ2gU/kduQ3G/LsLDlEjFhRP0BHBE+1Q=";
-      };
-    };
-
-    toggle-checkbox-nvim = buildVimPlugin {
-      name = "toggle-checkbox-nvim";
-      src = fetchFromGitHub {
-        owner = "opdavies";
-        repo = "toggle-checkbox.nvim";
-        rev = "main";
-        sha256 = "4YSEagQnLK5MBl2z53e6sOBlCDm220GYVlc6A+HNywg=";
-      };
-    };
-
-    vim-heritage = buildVimPlugin {
-      name = "vim-heritage";
-      src = fetchFromGitHub {
-        owner = "jessarcher";
-        repo = "vim-heritage";
-        rev = "cffa05c78c0991c998adc4504d761b3068547db6";
-        sha256 = "Lebe5V1XFxn4kSZ+ImZ69Vst9Nbc0N7eA9IzOCijFS0=";
-      };
-    };
-
-    vim-textobj-xmlattr = buildVimPlugin {
-      name = "vim-textobj-xmlattr";
-      src = fetchFromGitHub {
-        owner = "whatyouhide";
-        repo = "vim-textobj-xmlattr";
-        rev = "694a297f1d75fd527e87da9769f3c6519a87ebb1";
-        sha256 = "+91FVP95oh00flINdltqx6qJuijYo56tHIh3J098G2Q=";
-      };
-    };
-
-    tabline-vim = buildVimPlugin {
-      name = "tabline-vim";
-      src = fetchFromGitHub {
-        owner = "mkitt";
-        repo = "tabline.vim";
-        rev = "69c9698a3240860adaba93615f44778a9ab724b4";
-        sha256 = "51b8PxyKqBdeIvmmZyF2hpMBjkyrlZDdTB1opr5JZ7Y=";
-      };
-    };
-
-    vim-caser = buildVimPlugin {
-      name = "vim-caser";
-      src = fetchFromGitHub {
-        owner = "arthurxavierx";
-        repo = "vim-caser";
-        rev = "6bc9f41d170711c58e0157d882a5fe8c30f34bf6";
-        sha256 = "PXAY01O/cHvAdWx3V/pyWFeiV5qJGvLcAKhl5DQc0Ps=";
-      };
-    };
-
-    vim-zoom = buildVimPlugin {
-      name = "vim-zoom";
-      src = fetchFromGitHub {
-        owner = "dhruvasagar";
-        repo = "vim-zoom";
-        rev = "01c737005312c09e0449d6518decf8cedfee32c7";
-        sha256 = "/ADzScsG0u6RJbEtfO23Gup2NYdhPkExqqOPVcQa7aQ=";
-      };
-    };
-
-  };
-}
diff --git a/pkgs/default.nix b/pkgs/default.nix
new file mode 100644
index 00000000..361b055b
--- /dev/null
+++ b/pkgs/default.nix
@@ -0,0 +1,20 @@
+{ pkgs, prev, ... }:
+
+let
+  inherit (pkgs) callPackage;
+in
+{
+  vimPlugins = prev.vimPlugins // {
+    conf-vim = callPackage ./vim-plugins/conf-vim.nix { };
+    edit-alternate-vim = callPackage ./vim-plugins/edit-alternate-vim.nix { };
+    nvim-tmux-navigation = callPackage ./vim-plugins/nvim-tmux-navigation.nix { };
+    standard-vim = callPackage ./vim-plugins/standard-vim.nix { };
+    tabline-vim = callPackage ./vim-plugins/tabline-vim.nix { };
+    vim-autoread = callPackage ./vim-plugins/vim-autoread.nix { };
+    vim-caser = callPackage ./vim-plugins/vim-caser.nix { };
+    vim-heritage = callPackage ./vim-plugins/vim-heritage.nix { };
+    vim-textobj-indent = callPackage ./vim-plugins/vim-textobj-indent.nix { };
+    vim-textobj-xmlattr = callPackage ./vim-plugins/vim-textobj-xmlattr.nix { };
+    vim-zoom = callPackage ./vim-plugins/vim-zoom.nix { };
+  };
+}
diff --git a/pkgs/vim-plugins/conf-vim.nix b/pkgs/vim-plugins/conf-vim.nix
new file mode 100644
index 00000000..634e75c9
--- /dev/null
+++ b/pkgs/vim-plugins/conf-vim.nix
@@ -0,0 +1,11 @@
+{ pkgs, ... }:
+
+pkgs.vimUtils.buildVimPlugin {
+  name = "conf-vim";
+  src = pkgs.fetchFromGitHub {
+    owner = "tjdevries";
+    repo = "conf.vim";
+    rev = "master";
+    sha256 = "AjiTJsoim0BAnyfqk1IQzNsa6jhFM2+A66E7q9sJqz0=";
+  };
+}
diff --git a/pkgs/vim-plugins/edit-alternate-vim.nix b/pkgs/vim-plugins/edit-alternate-vim.nix
new file mode 100644
index 00000000..dbfc2876
--- /dev/null
+++ b/pkgs/vim-plugins/edit-alternate-vim.nix
@@ -0,0 +1,11 @@
+{ pkgs, ... }:
+
+pkgs.vimUtils.buildVimPlugin {
+  name = "edit-alternate-vim";
+  src = pkgs.fetchFromGitHub {
+    owner = "tjdevries";
+    repo = "edit_alternate.vim";
+    rev = "master";
+    sha256 = "mEKnqYAhgrdxPRoKf4S4yYecdFIHGg8bDxpqPuC1+S4=";
+  };
+}
diff --git a/pkgs/vim-plugins/nvim-tmux-navigation.nix b/pkgs/vim-plugins/nvim-tmux-navigation.nix
new file mode 100644
index 00000000..19835cb1
--- /dev/null
+++ b/pkgs/vim-plugins/nvim-tmux-navigation.nix
@@ -0,0 +1,11 @@
+{ pkgs, ... }:
+
+pkgs.vimUtils.buildVimPlugin {
+  name = "nvim-tmux-navigation";
+  src = pkgs.fetchFromGitHub {
+    owner = "alexghergh";
+    repo = "nvim-tmux-navigation";
+    rev = "4898c98702954439233fdaf764c39636681e2861";
+    sha256 = "sha256-CxAgQSbOrg/SsQXupwCv8cyZXIB7tkWO+Y6FDtoR8xk=";
+  };
+}
diff --git a/pkgs/vim-plugins/standard-vim.nix b/pkgs/vim-plugins/standard-vim.nix
new file mode 100644
index 00000000..d53432cd
--- /dev/null
+++ b/pkgs/vim-plugins/standard-vim.nix
@@ -0,0 +1,11 @@
+{ pkgs, ... }:
+
+pkgs.vimUtils.buildVimPlugin {
+  name = "standard-vim";
+  src = pkgs.fetchFromGitHub {
+    owner = "tjdevries";
+    repo = "standard.vim";
+    rev = "master";
+    sha256 = "9VwkvV1Dv6cE4uDkPp36DozjWJOclDR883yDMYw000E=";
+  };
+}
diff --git a/pkgs/vim-plugins/tabline-vim.nix b/pkgs/vim-plugins/tabline-vim.nix
new file mode 100644
index 00000000..bf70fa83
--- /dev/null
+++ b/pkgs/vim-plugins/tabline-vim.nix
@@ -0,0 +1,11 @@
+{ pkgs, ... }:
+
+pkgs.vimUtils.buildVimPlugin {
+  name = "tabline-vim";
+  src = pkgs.fetchFromGitHub {
+    owner = "mkitt";
+    repo = "tabline.vim";
+    rev = "69c9698a3240860adaba93615f44778a9ab724b4";
+    sha256 = "51b8PxyKqBdeIvmmZyF2hpMBjkyrlZDdTB1opr5JZ7Y=";
+  };
+}
diff --git a/pkgs/vim-plugins/vim-autoread.nix b/pkgs/vim-plugins/vim-autoread.nix
new file mode 100644
index 00000000..37f95a01
--- /dev/null
+++ b/pkgs/vim-plugins/vim-autoread.nix
@@ -0,0 +1,11 @@
+{ pkgs, ... }:
+
+pkgs.vimUtils.buildVimPlugin {
+  name = "vim-autoread";
+  src = pkgs.fetchFromGitHub {
+    owner = "djoshea";
+    repo = "vim-autoread";
+    rev = "24061f84652d768bfb85d222c88580b3af138dab";
+    sha256 = "fSADjNt1V9jgAPjxggbh7Nogcxyisi18KaVve8j+c3w=";
+  };
+}
diff --git a/pkgs/vim-plugins/vim-caser.nix b/pkgs/vim-plugins/vim-caser.nix
new file mode 100644
index 00000000..512a0652
--- /dev/null
+++ b/pkgs/vim-plugins/vim-caser.nix
@@ -0,0 +1,11 @@
+{ pkgs, ... }:
+
+pkgs.vimUtils.buildVimPlugin {
+  name = "vim-caser";
+  src = pkgs.fetchFromGitHub {
+    owner = "arthurxavierx";
+    repo = "vim-caser";
+    rev = "6bc9f41d170711c58e0157d882a5fe8c30f34bf6";
+    sha256 = "PXAY01O/cHvAdWx3V/pyWFeiV5qJGvLcAKhl5DQc0Ps=";
+  };
+}
diff --git a/pkgs/vim-plugins/vim-heritage.nix b/pkgs/vim-plugins/vim-heritage.nix
new file mode 100644
index 00000000..4c5f1787
--- /dev/null
+++ b/pkgs/vim-plugins/vim-heritage.nix
@@ -0,0 +1,11 @@
+{ pkgs, ... }:
+
+pkgs.vimUtils.buildVimPlugin {
+  name = "vim-heritage";
+  src = pkgs.fetchFromGitHub {
+    owner = "jessarcher";
+    repo = "vim-heritage";
+    rev = "cffa05c78c0991c998adc4504d761b3068547db6";
+    sha256 = "Lebe5V1XFxn4kSZ+ImZ69Vst9Nbc0N7eA9IzOCijFS0=";
+  };
+}
diff --git a/pkgs/vim-plugins/vim-textobj-indent.nix b/pkgs/vim-plugins/vim-textobj-indent.nix
new file mode 100644
index 00000000..d1dd5492
--- /dev/null
+++ b/pkgs/vim-plugins/vim-textobj-indent.nix
@@ -0,0 +1,11 @@
+{ pkgs, ... }:
+
+pkgs.vimUtils.buildVimPlugin {
+  name = "vim-textobj-indent";
+  src = pkgs.fetchFromGitHub {
+    owner = "kana";
+    repo = "vim-textobj-indent";
+    rev = "deb76867c302f933c8f21753806cbf2d8461b548";
+    sha256 = "oFzUPG+IOkbKZ2gU/kduQ3G/LsLDlEjFhRP0BHBE+1Q=";
+  };
+}
diff --git a/pkgs/vim-plugins/vim-textobj-xmlattr.nix b/pkgs/vim-plugins/vim-textobj-xmlattr.nix
new file mode 100644
index 00000000..94562d61
--- /dev/null
+++ b/pkgs/vim-plugins/vim-textobj-xmlattr.nix
@@ -0,0 +1,11 @@
+{ pkgs, ... }:
+
+pkgs.vimUtils.buildVimPlugin {
+  name = "vim-textobj-xmlattr";
+  src = pkgs.fetchFromGitHub {
+    owner = "whatyouhide";
+    repo = "vim-textobj-xmlattr";
+    rev = "694a297f1d75fd527e87da9769f3c6519a87ebb1";
+    sha256 = "+91FVP95oh00flINdltqx6qJuijYo56tHIh3J098G2Q=";
+  };
+}
diff --git a/pkgs/vim-plugins/vim-zoom.nix b/pkgs/vim-plugins/vim-zoom.nix
new file mode 100644
index 00000000..1bc85968
--- /dev/null
+++ b/pkgs/vim-plugins/vim-zoom.nix
@@ -0,0 +1,11 @@
+{ pkgs, ... }:
+
+pkgs.vimUtils.buildVimPlugin {
+  name = "vim-zoom";
+  src = pkgs.fetchFromGitHub {
+    owner = "dhruvasagar";
+    repo = "vim-zoom";
+    rev = "01c737005312c09e0449d6518decf8cedfee32c7";
+    sha256 = "/ADzScsG0u6RJbEtfO23Gup2NYdhPkExqqOPVcQa7aQ=";
+  };
+}