summaryrefslogtreecommitdiffstats
path: root/default.nix
diff options
context:
space:
mode:
authorlassulus <lass@aidsballs.de>2015-09-27 20:08:36 +0200
committerlassulus <lass@aidsballs.de>2015-09-27 20:08:36 +0200
commita9f6f7ac7b8e70633164d10980d1d041f34be3ac (patch)
tree13a8bdfafd994c999c5eeae3ff5e2537a4d96f0f /default.nix
parentb6383dba83a2e9ec6ada40fb780c15a56c8d715e (diff)
parentbc2bd6e2f6e9295b14e641b82bff62b40641988d (diff)
Merge branch 'makefu'
Diffstat (limited to 'default.nix')
-rw-r--r--default.nix83
1 files changed, 69 insertions, 14 deletions
diff --git a/default.nix b/default.nix
index 875f0d5b4..64c69a2f4 100644
--- a/default.nix
+++ b/default.nix
@@ -1,26 +1,81 @@
-{ user-name, system-name }:
+{ user-name, host-name }:
let
+ lib = import <nixpkgs/lib>;
- eval = import <nixpkgs/nixos/lib/eval-config.nix> {
+ krebs-modules-path = ./krebs/3modules;
+ krebs-pkgs-path = ./krebs/5pkgs;
+ user-modules-path = ./. + "/${user-name}/3modules";
+ user-pkgs-path = ./. + "/${user-name}/5pkgs";
+
+ out =
+ (lib.mapAttrs (k: v: mk-namespace (./. + "/${k}"))
+ (lib.filterAttrs
+ (k: v: !lib.hasPrefix "." k && v == "directory")
+ (builtins.readDir ./.)));
+
+ eval = path: import <nixpkgs/nixos/lib/eval-config.nix> {
system = builtins.currentSystem;
- modules = map (p: ./. + "/${p}") [
- "${user-name}/1systems/${system-name}.nix"
- "${user-name}/3modules"
- "krebs/3modules"
+ modules = [
+ ({ config, ... }:
+ with import ./krebs/4lib { inherit lib; };
+ {
+ options.krebs.exec.host = mkOption {
+ type = types.host;
+ default = config.krebs.hosts.${host-name};
+ };
+ options.krebs.exec.user = mkOption {
+ type = types.user;
+ default = config.krebs.users.${user-name};
+ };
+ }
+ )
+ path
+ krebs-modules-path
+ user-modules-path
] ++ [
- ({ lib, pkgs, ... }: {
+ ({ config, lib, pkgs, ... }@args: {
_module.args.pkgs =
- (import ./krebs/5pkgs { inherit lib pkgs; }) //
- (import (./. + "/${user-name}/5pkgs") { inherit lib pkgs; });
+ (import krebs-pkgs-path args) //
+ (import user-pkgs-path args);
})
];
};
-in
+ 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)));
-{
- inherit (eval) config options;
+ # 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);
- system = eval.config.system.build.toplevel;
-}
+in out