From 265be6521ce4db5f01c3725a7e12b8c2a6adf808 Mon Sep 17 00:00:00 2001
From: matt1432 <matt@nelim.org>
Date: Fri, 30 Aug 2024 12:30:35 -0400
Subject: [PATCH] feat: make cache public

---
 common/modules/cachix.nix                    | 64 ++++++++------------
 devices/bbsteamie/hardware-configuration.nix |  3 +-
 devices/cluster/modules/caddy.nix            |  7 +--
 3 files changed, 27 insertions(+), 47 deletions(-)

diff --git a/common/modules/cachix.nix b/common/modules/cachix.nix
index c731dfed..4592e6a2 100644
--- a/common/modules/cachix.nix
+++ b/common/modules/cachix.nix
@@ -4,7 +4,14 @@
   pkgs,
   ...
 }: let
-  inherit (lib) optionals;
+  inherit (lib) foldl isList mergeAttrsWithFunc optionals unique;
+
+  mergeAttrsList = list:
+    foldl (mergeAttrsWithFunc (a: b:
+      if isList a && isList b
+      then unique (a ++ b)
+      else b)) {}
+    list;
 in {
   environment.systemPackages = [
     (pkgs.writeShellApplication {
@@ -17,45 +24,22 @@ in {
   ];
 
   nix = {
-    settings = {
-      substituters =
-        [
-          "https://hyprland.cachix.org"
-          "https://nix-gaming.cachix.org"
-          # Nixpkgs-Wayland
-          "https://cache.nixos.org"
-          "https://nixpkgs-wayland.cachix.org"
-          "https://nix-community.cachix.org"
-          # Nix-community
-          "https://nix-community.cachix.org"
-          # Nh
-          "https://viperml.cachix.org"
-          # Caddy
-          "https://caddycf.cachix.org"
+    settings = let
+      mkSubstituterConf = url: key: {
+        substituters = [url];
+        trusted-public-keys = optionals (key != null) [key];
+      };
+    in
+      mergeAttrsList ([
+          (mkSubstituterConf "https://cache.nixos.org" "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=")
+          (mkSubstituterConf "https://hyprland.cachix.org" "hyprland.cachix.org-1:a7pgxzMz7+chwVL3/pzj6jIBMioiJM7ypFP8PwtkuGc=")
+          (mkSubstituterConf "https://nix-gaming.cachix.org" "nix-gaming.cachix.org-1:nbjlureqMbRAxR1gJ/f3hxemL9svXaZF/Ees8vCUUs4=")
+          (mkSubstituterConf "https://nixpkgs-wayland.cachix.org" "nixpkgs-wayland.cachix.org-1:3lwxaILxMRkVhehr5StQprHdEo4IrE8sRho9R9HOLYA=")
+          (mkSubstituterConf "https://nix-community.cachix.org" "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=")
+          (mkSubstituterConf "https://viperml.cachix.org" "viperml.cachix.org-1:qZhKBMTfmcLL+OG6fj/hzsMEedgKvZVFRRAhq7j8Vh8=")
         ]
-        ++ optionals (!config.services.nix-serve.enable && config.services.tailscale.enable) [
-          # Personal config cache
-          "https://cache.nelim.org"
-        ]
-        ++ optionals (!config.services.nix-serve.enable && !config.services.tailscale.enable) [
-          "http://10.0.0.249:5000"
-        ];
-
-      trusted-public-keys = [
-        "hyprland.cachix.org-1:a7pgxzMz7+chwVL3/pzj6jIBMioiJM7ypFP8PwtkuGc="
-        "nix-gaming.cachix.org-1:nbjlureqMbRAxR1gJ/f3hxemL9svXaZF/Ees8vCUUs4="
-        # Nixpkgs-Wayland
-        "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
-        "nixpkgs-wayland.cachix.org-1:3lwxaILxMRkVhehr5StQprHdEo4IrE8sRho9R9HOLYA="
-        # Nix-community
-        "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
-        # Nh
-        "viperml.cachix.org-1:qZhKBMTfmcLL+OG6fj/hzsMEedgKvZVFRRAhq7j8Vh8="
-        # Caddy
-        "caddycf.cachix.org-1:6vbQaeiec/zKv9XfEwi9yWVCe7opbeJMu6w81UEXugY="
-        # Personal config cache
-        "cache.nelim.org:JmFqkUdH11EA9EZOFAGVHuRYp7EbsdJDHvTQzG2pPyY="
-      ];
-    };
+        ++ optionals (!config.services.nix-serve.enable) [
+          (mkSubstituterConf "https://cache.nelim.org" "cache.nelim.org:JmFqkUdH11EA9EZOFAGVHuRYp7EbsdJDHvTQzG2pPyY=")
+        ]);
   };
 }
diff --git a/devices/bbsteamie/hardware-configuration.nix b/devices/bbsteamie/hardware-configuration.nix
index ae98d528..d5e1109e 100644
--- a/devices/bbsteamie/hardware-configuration.nix
+++ b/devices/bbsteamie/hardware-configuration.nix
@@ -1,7 +1,6 @@
 {
   config,
   jovian,
-  lib,
   modulesPath,
   ...
 }: {
@@ -62,5 +61,5 @@
     }
   ];
 
-  hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
+  hardware.cpu.amd.updateMicrocode = config.hardware.enableRedistributableFirmware;
 }
diff --git a/devices/cluster/modules/caddy.nix b/devices/cluster/modules/caddy.nix
index f31220b9..b16a01c8 100644
--- a/devices/cluster/modules/caddy.nix
+++ b/devices/cluster/modules/caddy.nix
@@ -82,6 +82,8 @@ in {
 
       "Immich" = mkPublicReverseProxy "photos" "${nosIP}:2283" {};
 
+      "Binary Cache" = mkPublicReverseProxy "cache" "${serviviIP}:5000" {};
+
       # Private
       "nelim.org" = {
         serverAliases = ["*.nelim.org"];
@@ -107,11 +109,6 @@ in {
             '';
           };
 
-          nix-binary-cache = {
-            subDomainName = "cache";
-            reverseProxy = "${serviviIP}:5000";
-          };
-
           # Resume builder
           resume.reverseProxy = "${nosIP}:3060";
           resauth.reverseProxy = "${nosIP}:3100";