2015-09-30 23:48:15 +00:00
|
|
|
{ current-date
|
|
|
|
, current-host-name
|
|
|
|
, current-user-name
|
|
|
|
}:
|
2015-07-24 15:34:08 +00:00
|
|
|
|
|
|
|
let
|
2015-09-26 22:22:50 +00:00
|
|
|
lib = import <nixpkgs/lib>;
|
2015-07-24 15:34:08 +00:00
|
|
|
|
2015-09-26 22:22:50 +00:00
|
|
|
krebs-modules-path = ./krebs/3modules;
|
|
|
|
krebs-pkgs-path = ./krebs/5pkgs;
|
2015-09-30 23:48:15 +00:00
|
|
|
user-modules-path = ./. + "/${current-user-name}/3modules";
|
|
|
|
user-pkgs-path = ./. + "/${current-user-name}/5pkgs";
|
2015-09-26 22:22:50 +00:00
|
|
|
|
|
|
|
out =
|
2015-10-01 01:07:31 +00:00
|
|
|
lib.mapAttrs (_: builtins.getAttr "main")
|
|
|
|
(lib.filterAttrs (_: builtins.hasAttr "main")
|
|
|
|
(lib.mapAttrs
|
|
|
|
(k: v:
|
|
|
|
if lib.hasPrefix "." k || v != "directory" then
|
|
|
|
{}
|
|
|
|
else if builtins.pathExists (./. + "/${k}/default.nix") then
|
|
|
|
{ main = import (./. + "/${k}"); }
|
|
|
|
else if builtins.pathExists (./. + "/${k}/1systems") then
|
|
|
|
{ main = mk-namespace (./. + "/${k}"); }
|
|
|
|
else
|
|
|
|
{})
|
|
|
|
(builtins.readDir ./.)));
|
2015-09-26 22:22:50 +00:00
|
|
|
|
|
|
|
eval = path: import <nixpkgs/nixos/lib/eval-config.nix> {
|
2015-07-24 15:34:08 +00:00
|
|
|
system = builtins.currentSystem;
|
2015-09-26 22:22:50 +00:00
|
|
|
modules = [
|
|
|
|
path
|
|
|
|
krebs-modules-path
|
|
|
|
user-modules-path
|
2015-08-28 22:17:25 +00:00
|
|
|
] ++ [
|
2015-09-26 22:22:50 +00:00
|
|
|
({ config, lib, pkgs, ... }@args: {
|
2015-08-28 22:17:25 +00:00
|
|
|
_module.args.pkgs =
|
2015-09-26 22:22:50 +00:00
|
|
|
(import krebs-pkgs-path args) //
|
|
|
|
(import user-pkgs-path args);
|
2015-08-28 22:17:25 +00:00
|
|
|
})
|
2015-07-25 16:16:51 +00:00
|
|
|
];
|
|
|
|
};
|
2015-07-24 15:34:08 +00:00
|
|
|
|
2015-09-26 22:22:50 +00:00
|
|
|
mk-namespace = path: mapNixDir mk-system (path + "/1systems");
|
|
|
|
|
|
|
|
mk-system = path: rec {
|
|
|
|
inherit (eval path) config options;
|
|
|
|
system = config.system.build.toplevel;
|
|
|
|
fetch = import ./krebs/0tools/fetch.nix { inherit config lib; };
|
|
|
|
};
|
|
|
|
|
|
|
|
mapNixDir = f: path: lib.mapAttrs (_: f) (nixDir path);
|
|
|
|
|
|
|
|
nixDir = path:
|
|
|
|
builtins.listToAttrs
|
|
|
|
(catMaybes
|
|
|
|
(lib.mapAttrsToList
|
|
|
|
(k: v: {
|
|
|
|
directory =
|
|
|
|
let p = path + "/${k}/default.nix"; in
|
|
|
|
if builtins.pathExists p
|
|
|
|
then Just (lib.nameValuePair k p)
|
|
|
|
else Nothing;
|
|
|
|
regular =
|
|
|
|
let p = path + "/${k}"; in
|
|
|
|
if lib.hasSuffix ".nix" p
|
|
|
|
then Just (lib.nameValuePair (lib.removeSuffix ".nix" k) p)
|
|
|
|
else Nothing;
|
|
|
|
}.${v} or Nothing)
|
|
|
|
(builtins.readDir path)));
|
2015-07-24 15:34:08 +00:00
|
|
|
|
2015-09-26 22:22:50 +00:00
|
|
|
# TODO move to lib
|
|
|
|
Just = x: { type = "maybe"; value = x; };
|
|
|
|
Nothing = { type = "maybe"; };
|
|
|
|
isMaybe = x: builtins.typeOf x == "set" && x.type or false == "maybe";
|
|
|
|
isJust = x: isMaybe x && builtins.hasAttr "value" x;
|
|
|
|
fromJust = x: assert isJust x; x.value;
|
|
|
|
catMaybes = xs: map fromJust (builtins.filter isJust xs);
|
2015-07-24 15:34:08 +00:00
|
|
|
|
2015-09-26 22:22:50 +00:00
|
|
|
in out
|