From bb397841eee0986be2b2e0949be83d28f9958d3d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tristan=20Dani=C3=ABl=20Maat?= <tm@tlater.net>
Date: Sun, 26 Feb 2023 05:44:54 +0000
Subject: [PATCH] refactoring: Use flake-inputs instead of awkwardly passing
 through

---
 configuration/default.nix |  4 ++++
 flake.nix                 | 27 +++++++++++++++++----------
 lib/default.nix           | 22 +---------------------
 3 files changed, 22 insertions(+), 31 deletions(-)

diff --git a/configuration/default.nix b/configuration/default.nix
index d090cef..2a4ce63 100644
--- a/configuration/default.nix
+++ b/configuration/default.nix
@@ -3,9 +3,13 @@
   pkgs,
   lib,
   modulesPath,
+  flake-inputs,
   ...
 }: {
   imports = [
+    flake-inputs.sops-nix.nixosModules.sops
+    flake-inputs.tlaternet-webserver.nixosModules.default
+
     "${modulesPath}/profiles/headless.nix"
     "${modulesPath}/profiles/minimal.nix"
     (import ../modules)
diff --git a/flake.nix b/flake.nix
index 2aa6c0b..ec8a157 100644
--- a/flake.nix
+++ b/flake.nix
@@ -24,8 +24,8 @@
     sops-nix,
     nvfetcher,
     deploy-rs,
-    tlaternet-webserver,
-  }: let
+    ...
+  } @ inputs: let
     system = "x86_64-linux";
   in {
     ##################
@@ -33,9 +33,14 @@
     ##################
     nixosConfigurations = {
       # The actual system definition
-      tlaternet = self.lib.makeNixosSystem {
+      tlaternet = nixpkgs.lib.nixosSystem {
         inherit system;
-        extraModules = [(import ./configuration/hardware-specific/linode)];
+        specialArgs.flake-inputs = inputs;
+
+        modules = [
+          ./configuration
+          ./configuration/hardware-specific/linode
+        ];
       };
     };
 
@@ -63,19 +68,21 @@
     ####################
     # Helper functions #
     ####################
-    lib = import ./lib {
-      inherit nixpkgs sops-nix tlaternet-webserver;
-      lib = nixpkgs.lib;
-    };
+    lib = import ./lib {inherit (nixpkgs) lib;};
 
     ###################
     # Utility scripts #
     ###################
     packages.${system} = let
       inherit (nixpkgs.legacyPackages.${system}) writeShellScript;
-      vm = self.lib.makeNixosSystem {
+      vm = nixpkgs.lib.nixosSystem {
         inherit system;
-        extraModules = [(import ./configuration/hardware-specific/vm.nix)];
+        specialArgs.flake-inputs = inputs;
+
+        modules = [
+          ./configuration
+          ./configuration/hardware-specific/vm.nix
+        ];
       };
     in {
       default = vm.config.system.build.vm;
diff --git a/lib/default.nix b/lib/default.nix
index 5f6b68f..20d874d 100644
--- a/lib/default.nix
+++ b/lib/default.nix
@@ -1,9 +1,4 @@
-{
-  lib,
-  nixpkgs,
-  sops-nix,
-  tlaternet-webserver,
-}: let
+{lib}: let
   inherit (lib.attrsets) mapAttrsToList;
   inherit (lib.strings) concatStringsSep;
 in {
@@ -12,19 +7,4 @@ in {
     (mapAttrsToList
       (host: vm: "hostfwd=::${host}-:${vm}")
       portMapping);
-
-  makeNixosSystem = {
-    system,
-    extraModules,
-  }:
-    nixpkgs.lib.nixosSystem {
-      inherit system;
-      modules =
-        [
-          sops-nix.nixosModules.sops
-          tlaternet-webserver.nixosModules.default
-          (import ../configuration)
-        ]
-        ++ extraModules;
-    };
 }