From 9b6dd624efb39482a131588e1f243da436f660f3 Mon Sep 17 00:00:00 2001
From: Tom Prince <tom.prince@private.storage>
Date: Thu, 23 Sep 2021 13:07:32 -0600
Subject: [PATCH] Set nixpkgs explicitly in morph.

---
 morph/grid/local/grid.nix      |  1 +
 morph/grid/production/grid.nix |  1 +
 morph/grid/testing/grid.nix    |  1 +
 morph/lib/base.nix             | 13 +++++++++++++
 morph/lib/default.nix          | 12 ++++++++++++
 5 files changed, 28 insertions(+)

diff --git a/morph/grid/local/grid.nix b/morph/grid/local/grid.nix
index 46cb9c8e..59880af8 100644
--- a/morph/grid/local/grid.nix
+++ b/morph/grid/local/grid.nix
@@ -129,6 +129,7 @@ let
 in {
   network = {
     description = "PrivateStorage.io LocalDev Grid";
+    inherit (gridlib) pkgs;
   };
   inherit payments monitoring storage1 storage2;
 }
diff --git a/morph/grid/production/grid.nix b/morph/grid/production/grid.nix
index 6009be84..3e0d41a5 100644
--- a/morph/grid/production/grid.nix
+++ b/morph/grid/production/grid.nix
@@ -130,6 +130,7 @@ let
 in {
   network = {
     description = "PrivateStorage.io Production Grid";
+    inherit (gridlib) pkgs;
   };
   inherit payments;
   inherit monitoring;
diff --git a/morph/grid/testing/grid.nix b/morph/grid/testing/grid.nix
index 18983f0b..383fe740 100644
--- a/morph/grid/testing/grid.nix
+++ b/morph/grid/testing/grid.nix
@@ -81,6 +81,7 @@ let
 in {
   network = {
     description = "PrivateStorage.io Testing Grid";
+    inherit (gridlib) pkgs;
   };
   inherit payments monitoring storage001;
 }
diff --git a/morph/lib/base.nix b/morph/lib/base.nix
index 271766d9..377ff80c 100644
--- a/morph/lib/base.nix
+++ b/morph/lib/base.nix
@@ -32,5 +32,18 @@
     # Instead, just tell morph how to reach the node here - by using its fully
     # qualified domain name.
     deployment.targetHost = "${config.networking.hostName}.${config.networking.domain}";
+
+    assertions = [
+      # This is a check to save somebody in the future trying to debug why
+      # setting `nixpkgs.config` is not having an effect.
+      {
+        # `{}` is the default value for `nixpkgs.config`
+        assertion = config.nixpkgs.config == {};
+        message = ''
+          Since we set `nixpkgs.pkgs` via morph's `network.pkgs`, the value for `nixpkgs.config` is ignored.
+          See https://whetstone.privatestorage.io/privatestorage/PrivateStorageio/-/issues/85#note_15876 for details.
+          '';
+      }
+    ];
   };
 }
diff --git a/morph/lib/default.nix b/morph/lib/default.nix
index bf25e5a5..34f5e8b5 100644
--- a/morph/lib/default.nix
+++ b/morph/lib/default.nix
@@ -17,4 +17,16 @@
   customize-monitoring = import ./customize-monitoring.nix;
 
   modules = builtins.toString ../../nixos/modules;
+
+  # The nixpkgs version used in our deployments. This affects both the packages
+  # installed, as well as the NixOS module set that is used.
+  # This is intended to be used in a grid definition like:
+  #     network = { ... ; inherit (gridlib) pkgs; ... }
+  pkgs = import ../../nixpkgs-2105.nix {
+    # Ensure that configuration of the system where this runs
+    # doesn't leak into what we build.
+    # See https://github.com/NixOS/nixpkgs/issues/62513
+    config = {};
+    overlays = [];
+  };
 }
-- 
GitLab