From 98bc5991db76171ae9e1631b66f41061420624db Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 26 Jul 2015 21:04:13 +0200 Subject: 3 krebs: make dns.providers part of api --- 3modules/krebs/default.nix | 61 +++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 31 deletions(-) (limited to '3modules/krebs/default.nix') diff --git a/3modules/krebs/default.nix b/3modules/krebs/default.nix index 33c10881..70d45497 100644 --- a/3modules/krebs/default.nix +++ b/3modules/krebs/default.nix @@ -34,6 +34,14 @@ let default = {}; }; + dns = { + providers = mkOption { + # TODO with types; tree dns.label dns.provider, so we can merge. + # Currently providers can only be merged if aliases occur just once. + type = with types; attrsOf unspecified; + }; + }; + hosts = mkOption { type = with types; attrsOf host; }; @@ -56,38 +64,26 @@ let { krebs = makefu-imp; } { krebs = tv-imp; } { - # XXX This overlaps with krebs.retiolum - networking.extraHosts = - let - # TODO move domain name providers to a dedicated module - # providers : tree label providername - providers = { - internet = "hosts"; - retiolum = "hosts"; - de.viljetic = "regfish"; - de.krebsco = "ovh"; - }; - - # splitByProvider : [alias] -> listset providername alias - splitByProvider = foldl (acc: alias: listset-insert (providerOf alias) alias acc) {}; + krebs.dns.providers = { + de.krebsco = "ovh"; + internet = "hosts"; + retiolum = "hosts"; + }; - # providerOf : alias -> providername - providerOf = alias: - tree-get (splitString "." alias) providers; - in - concatStringsSep "\n" (flatten ( - # TODO deepMap ["hosts" "nets"] (hostname: host: netname: net: - mapAttrsToList (hostname: host: - mapAttrsToList (netname: net: - let - aliases = toString (unique (longs ++ shorts)); - longs = (splitByProvider net.aliases).hosts; - shorts = map (removeSuffix ".${cfg.search-domain}") longs; - in - map (addr: "${addr} ${aliases}") net.addrs - ) host.nets - ) config.krebs.hosts - )); + # XXX This overlaps with krebs.retiolum + networking.extraHosts = concatStringsSep "\n" (flatten ( + mapAttrsToList (hostname: host: + mapAttrsToList (netname: net: + let + aliases = toString (unique (longs ++ shorts)); + providers = dns.split-by-provider net.aliases cfg.dns.providers; + longs = providers.hosts; + shorts = map (removeSuffix ".${cfg.search-domain}") longs; + in + map (addr: "${addr} ${aliases}") net.addrs + ) host.nets + ) cfg.hosts + )); } ]; @@ -139,6 +135,9 @@ let }; tv-imp = { + dns.providers = { + de.viljetic = "regfish"; + }; hosts = addNames { cd = { cores = 2; -- cgit v1.2.3 From a952f015a860c62046a22ca194d0d841390e7132 Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 27 Jul 2015 02:55:06 +0200 Subject: 3 krebs.build += {deploy,deps} --- 3modules/krebs/default.nix | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to '3modules/krebs/default.nix') diff --git a/3modules/krebs/default.nix b/3modules/krebs/default.nix index 70d45497..e385244d 100644 --- a/3modules/krebs/default.nix +++ b/3modules/krebs/default.nix @@ -22,6 +22,24 @@ let build = mkOption { type = types.submodule { options = { + deploy = mkOption { + type = with types; nullOr str; + default = null; + }; + deps = mkOption { + type = with types; attrsOf (submodule { + options = { + url = mkOption { + type = either str path; + }; + rev = mkOption { + type = nullOr str; + default = null; + }; + }; + }); + default = {}; + }; host = mkOption { type = types.host; }; -- cgit v1.2.3 From de2a7ff0eada30c6c0800ce9e6d12dd94c7df8af Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 27 Jul 2015 04:31:41 +0200 Subject: 3 krebs.build {s/deploy/target/,+=script} --- 3modules/krebs/default.nix | 87 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 83 insertions(+), 4 deletions(-) (limited to '3modules/krebs/default.nix') diff --git a/3modules/krebs/default.nix b/3modules/krebs/default.nix index e385244d..d32143be 100644 --- a/3modules/krebs/default.nix +++ b/3modules/krebs/default.nix @@ -20,9 +20,9 @@ let enable = mkEnableOption "krebs"; build = mkOption { - type = types.submodule { + type = types.submodule ({ config, ... }: { options = { - deploy = mkOption { + target = mkOption { type = with types; nullOr str; default = null; }; @@ -30,7 +30,7 @@ let type = with types; attrsOf (submodule { options = { url = mkOption { - type = either str path; + type = str; }; rev = mkOption { type = nullOr str; @@ -40,6 +40,85 @@ let }); default = {}; }; + script = mkOption { + type = types.str; + default = '' + #! /bin/sh + set -efux + + target=${escapeShellArg cfg.build.target} + + push(){( + src=$1/ + dst=$target:$2 + rsync \ + --exclude .git \ + --exclude .graveyard \ + --exclude old \ + --rsync-path="mkdir -p \"$dst\" && rsync" \ + --usermap=\*:0 \ + --groupmap=\*:0 \ + --delete-excluded \ + -vrLptgoD \ + "$src" "$dst" + )} + + ${concatStrings (mapAttrsToList (name: { url, rev, ... }: + optionalString (rev == null) '' + push ${toString (map escapeShellArg [ + "${url}" + "/root/src/${name}" + ])} + '') config.deps)} + + exec ssh -S none "$target" /bin/sh <<\EOF + set -efux + fetch(){( + url=$1 + rev=$2 + dst=$3 + mkdir -p "$dst" + cd "$dst" + if ! test -e .git; then + git init + fi + if ! cur_url=$(git config remote.origin.url 2>/dev/null); then + git remote add origin "$url" + elif test "$cur_url" != "$url"; then + git remote set-url origin "$url" + fi + if test "$(git rev-parse --verify HEAD 2>/dev/null)" != "$rev"; then + git fetch origin + git checkout "$rev" -- . + git checkout -q "$rev" + git submodule init + git submodule update + fi + git clean -dxf + )} + + ${concatStrings (mapAttrsToList (name: { url, rev, ... }: + optionalString (rev != null) '' + fetch ${toString (map escapeShellArg [ + url + rev + "/root/src/${name}" + ])} + '') config.deps)} + + echo build system... + NIX_PATH=/root/src \ + nix-build \ + -Q \ + -A system \ + '' \ + --argstr user-name ${escapeShellArg cfg.build.user.name} \ + --argstr system-name ${escapeShellArg cfg.build.host.name} + + exec result/bin/switch-to-configuration switch + EOF + ''; + }; host = mkOption { type = types.host; }; @@ -47,7 +126,7 @@ let type = types.user; }; }; - }; + }); # Define defaul value, so unset values of the submodule get reported. default = {}; }; -- cgit v1.2.3