2015-10-17 06:30:20 +02:00
|
|
|
{ current-date ? abort "current-date not defined"
|
|
|
|
, current-host-name ? abort "current-host-name not defined"
|
|
|
|
, current-user-name ? builtins.getEnv "LOGNAME"
|
2015-10-01 01:48:15 +02:00
|
|
|
}:
|
2015-07-24 17:34:08 +02:00
|
|
|
|
2015-10-17 06:30:20 +02:00
|
|
|
assert current-user-name != "";
|
|
|
|
|
2015-07-24 17:34:08 +02:00
|
|
|
let
|
2015-09-27 00:22:50 +02:00
|
|
|
lib = import <nixpkgs/lib>;
|
2015-07-24 17:34:08 +02:00
|
|
|
|
2015-10-17 05:44:42 +02:00
|
|
|
nspath = ns: p: ./. + "/${ns}/${p}";
|
|
|
|
kpath = nspath "krebs";
|
|
|
|
upath = nspath current-user-name;
|
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
2015-10-02 15:29:47 +02:00
|
|
|
|
2015-09-27 00:22:50 +02:00
|
|
|
out =
|
2015-10-17 06:50:06 +02:00
|
|
|
{ inherit (eval {}) config options pkgs; } //
|
2015-10-17 06:16:56 +02:00
|
|
|
lib.mapAttrs
|
|
|
|
(name: _:
|
2015-10-17 07:25:10 +02:00
|
|
|
if builtins.pathExists (nspath name "default.nix")
|
|
|
|
then import (nspath name "default.nix")
|
|
|
|
else import-1systems (nspath name "1systems"))
|
2015-10-17 06:16:56 +02:00
|
|
|
(lib.filterAttrs
|
|
|
|
(n: t: !lib.hasPrefix "." n && t == "directory")
|
|
|
|
(builtins.readDir ./.));
|
2015-09-27 00:22:50 +02:00
|
|
|
|
|
|
|
eval = path: import <nixpkgs/nixos/lib/eval-config.nix> {
|
|
|
|
modules = [
|
2015-10-17 05:44:42 +02:00
|
|
|
stockholm
|
2015-09-27 00:22:50 +02:00
|
|
|
path
|
2015-07-25 18:16:51 +02:00
|
|
|
];
|
|
|
|
};
|
2015-07-24 17:34:08 +02:00
|
|
|
|
2015-10-17 06:16:56 +02:00
|
|
|
import-1systems = path: lib.mapAttrs (_: mk-system) (nixDir path);
|
2015-09-27 00:22:50 +02:00
|
|
|
|
|
|
|
mk-system = path: rec {
|
|
|
|
inherit (eval path) config options;
|
|
|
|
system = config.system.build.toplevel;
|
|
|
|
fetch = import ./krebs/0tools/fetch.nix { inherit config lib; };
|
|
|
|
};
|
|
|
|
|
|
|
|
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 17:34:08 +02:00
|
|
|
|
2015-09-27 00:22:50 +02: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 17:34:08 +02:00
|
|
|
|
2015-09-27 00:22:50 +02:00
|
|
|
in out
|