From 15c6f0678fad4bb7541338e4f422e8a913d616f9 Mon Sep 17 00:00:00 2001
From: tv <tv@shackspace.de>
Date: Sat, 17 Oct 2015 05:44:42 +0200
Subject: [PATCH] explicate stockholm configuration

---
 default.nix             | 40 +++++++++++++++-------------------------
 krebs/5pkgs/default.nix |  4 ++--
 2 files changed, 17 insertions(+), 27 deletions(-)

diff --git a/default.nix b/default.nix
index f14329d40..0900ca7b2 100644
--- a/default.nix
+++ b/default.nix
@@ -6,26 +6,23 @@
 let
   lib = import <nixpkgs/lib>;
 
-  krebs-modules-path = ./krebs/3modules;
-  krebs-pkgs-path = ./krebs/5pkgs;
-  user-modules-path = ./. + "/${current-user-name}/3modules";
-  user-pkgs-path = ./. + "/${current-user-name}/5pkgs";
+  nspath = ns: p: ./. + "/${ns}/${p}";
+  kpath = nspath "krebs";
+  upath = nspath current-user-name;
 
-  # XXX This is only used interactively, e.g. using get.
-  pkgs =
-    let
-      pkgs = import <nixpkgs> {};
-      args = {
-        inherit pkgs;
-        lib = pkgs.lib;
-      };
-    in
-    pkgs //
-    import krebs-pkgs-path args //
-    import user-pkgs-path args;
+  stockholm = {
+    imports = map (f: f "3modules") [ kpath upath ];
+
+    nixpkgs.config.packageOverrides = pkgs:
+      let
+        kpkgs = import (kpath "5pkgs") { inherit pkgs; };
+        upkgs = import (upath "5pkgs") { pkgs = pkgs // kpkgs; };
+      in
+      kpkgs // upkgs;
+  };
 
   out =
-    { inherit pkgs; } //
+    { inherit (eval {}) pkgs; } //
     lib.mapAttrs (_: builtins.getAttr "main")
       (lib.filterAttrs (_: builtins.hasAttr "main")
         (lib.mapAttrs
@@ -43,15 +40,8 @@ let
   eval = path: import <nixpkgs/nixos/lib/eval-config.nix> {
     system = builtins.currentSystem;
     modules = [
+      stockholm
       path
-      krebs-modules-path
-      user-modules-path
-    ] ++ [
-      ({ config, lib, pkgs, ... }@args: {
-       _module.args.pkgs =
-         (import krebs-pkgs-path args) //
-         (import user-pkgs-path args);
-      })
     ];
   };
 
diff --git a/krebs/5pkgs/default.nix b/krebs/5pkgs/default.nix
index a8a1b5853..77519e831 100644
--- a/krebs/5pkgs/default.nix
+++ b/krebs/5pkgs/default.nix
@@ -1,6 +1,6 @@
-{ lib, pkgs, ... }:
+{ pkgs, ... }:
 
-with import ../4lib { inherit lib; };
+with import ../4lib { inherit (pkgs) lib; };
 
 let
   subdirs = mapAttrs (_: flip pkgs.callPackage {}) (subdirsOf ./.);