Merge remote-tracking branch 'cd/master'

This commit is contained in:
makefu 2016-03-16 08:26:27 +01:00
commit 90150375a8
7 changed files with 175 additions and 27 deletions

View File

@ -60,6 +60,12 @@ let
};
imp = {
krebs.on-failure.plans =
listToAttrs (map (plan: nameValuePair "backup.${plan.name}" {
}) (filter (plan: build-host-is "pull" "dst" plan ||
build-host-is "push" "src" plan)
enabled-plans));
systemd.services =
listToAttrs (map (plan: nameValuePair "backup.${plan.name}" {
# TODO if there is plan.user, then use its privkey

View File

@ -23,6 +23,7 @@ let
./lib.nix
./nginx.nix
./nixpkgs.nix
./on-failure.nix
./os-release.nix
./per-user.nix
./Reaktor.nix

View File

@ -0,0 +1,91 @@
{ config, lib, pkgs, ... }: with config.krebs.lib; let
out = {
options.krebs.on-failure = api;
config = lib.mkIf cfg.enable imp;
};
cfg = config.krebs.on-failure;
api = {
enable = mkEnableOption "krebs.on-failure" // {
default = cfg.plans != {};
};
plans = mkOption {
default = {};
type = let
inherit (config) krebs;
in types.attrsOf (types.submodule ({ config, ... }: {
options = {
enable = mkEnableOption "krebs.on-failure.${config.name}" // {
default = true;
};
journalctl = {
lines = mkOption {
type = types.int;
default = 100;
};
output = mkOption {
type = types.enum [
"cat"
"export"
"json"
"json-pretty"
"json-sse"
"short"
"short-iso"
"short-precise"
"verbose"
];
default = "short-iso";
};
};
mailto = mkOption {
type = types.str;
default = krebs.build.user.mail;
description = "Mail address to send journal extract to.";
};
subject = mkOption {
type = types.str;
default = "[${krebs.build.host.name}] ${config.name} has failed";
};
name = mkOption {
type = types.str;
default = config._module.args.name;
description = "Name of the to-be-monitored service.";
};
};
}));
};
sendmail = mkOption {
type = types.str;
default = "/var/setuid-wrappers/sendmail";
};
};
imp = {
systemd.services = foldl (a: b: a // b) {} (map to-services enabled-plans);
};
enabled-plans = filter (getAttr "enable") (attrValues cfg.plans);
to-services = plan: {
"${plan.name}".unitConfig.OnFailure = "on-failure.${plan.name}.service";
"on-failure.${plan.name}".serviceConfig = rec {
ExecStart = start plan;
SyslogIdentifier = ExecStart.name;
Type = "oneshot";
};
};
start = plan: pkgs.writeDash "on-failure.${plan.name}" ''
{ echo Subject: ${shell.escape plan.subject}
echo To: ${shell.escape plan.mailto}
echo
${pkgs.systemd}/bin/journalctl \
--lines=${toString plan.journalctl.lines} \
--output=${plan.journalctl.output} \
--unit=${shell.escape plan.name}.service
} | ${shell.escape cfg.sendmail} -t
'';
in out

View File

@ -357,6 +357,35 @@ with config.krebs.lib;
};
tv = {
mail = "tv@nomic.retiolum";
pgp.pubkeys.default = ''
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQINBFbJ/B0BEADZx8l5gRurzhEHcc3PbBepdZqDJQZ2cGHixi8VEk9iN25qJO5y
HB0q5sQRsh7oNCbzKp6qRhaG9kXmEda+Uu+qbHWxE32QcT76+W8npH73qthaFwC/
5RA8KcSE8/XFxVBnVb14PNVHyAVxPHawawbhsOeaiZcHrq5IF6sVzcsc2KN87sIE
SthR4E01LBK4AFeFuKxga9OKFQV5WJNrihu+6H4wZwUfMpbE552N1rggxT4CouqZ
RocSg+el/aPRj3Jk9jDe/JFv4HU7KfioOD+NO8xLAkyw3aLsu/bv9nfUvcvTGeRp
z31UOjpNYpT3PS0+lNCUKQKUadAmhwU95V/0GdhadgxCFcS65qNO7ZZYDJqMIT2y
YH1d9MaVPDQD9W2v0ITCJcrks9p47o+C8zzDlcVr2VEGrTSngRDkWVNYjKwd3L8w
HuaTarqOprLzeZ6yblcLVOrW8tGTmxum0jB4Fn3enpTyJNzCfp6c0CoYp/ZziQ82
2jgLWuqKv3EKhX9aCUUgbeDFhnsM3GzdT5qYupX7UyWTLfiUlAEUQUgtyM7yBUNN
PsD5OeYeRQ/xFzUO30kglbjXOOUQpm7kyX38OJA01JdOOhXNI7BTvkFZsJzBLoVM
AdK3LvF4Rjau3HzYqL1Cr0ai1Y9jZVXP3vimcvUcI9bTRg9pMfD8LekiQQARAQAB
tAl0diA8dHZAcj6JAj0EEwEIACcFAlbJ/B0CGwM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O+5tW1wTYZXitFFBfwuHlXm6w77K5QDBW6olT7pat41/F5eGxLcz tv@wu";
uid = 1337; # TODO use default
};

View File

@ -17,7 +17,7 @@ let out = rec {
types = import ./types.nix {
inherit config;
lib = lib // { inherit genid; };
lib = lib // { inherit genid optionalTrace; };
};
dir.has-default-nix = path: pathExists (path + "/default.nix");
@ -41,7 +41,10 @@ let out = rec {
mapAttrs (name: _: path + "/${name}")
(filterAttrs (_: eq "directory") (readDir path));
getAttrDef = name: set: set.${name} or set.default or null;
mapAttrValues = f: mapAttrs (_: f);
setAttr = name: value: set: set // { ${name} = value; };
optionalTrace = c: msg: x: if c then trace msg x else x;
}; in out

View File

@ -6,7 +6,7 @@ with types;
let
# Inherited attributes are used in submodules that have their own `config`.
inherit (config.krebs) users;
inherit (config.krebs) build users;
in
types // rec {
@ -47,33 +47,15 @@ types // rec {
};
ssh.pubkey = mkOption {
type = nullOr str;
type = nullOr ssh-pubkey;
default = null;
apply = x:
if x != null
then x
else trace "The option `krebs.hosts.${config.name}.ssh.pubkey' is unused." null;
optionalTrace (x == null && config.owner.name == build.user.name)
"The option `krebs.hosts.${config.name}.ssh.pubkey' is unused."
x;
};
ssh.privkey = mkOption {
type = nullOr (submodule {
options = {
bits = mkOption {
type = nullOr (enum ["4096"]);
default = null;
};
path = mkOption {
type = either path str;
apply = x: {
path = toString x;
string = x;
}.${typeOf x};
};
type = mkOption {
type = enum ["rsa" "ed25519"];
default = "ed25519";
};
};
});
type = nullOr ssh-privkey;
default = null;
};
};
@ -129,7 +111,7 @@ types // rec {
);
};
pubkey = mkOption {
type = str;
type = tinc-pubkey;
};
};
}));
@ -183,8 +165,18 @@ types // rec {
type = username;
default = config._module.args.name;
};
pgp.pubkeys = mkOption {
type = attrsOf pgp-pubkey;
default = {};
description = ''
Set of user's PGP public keys.
Modules supporting PGP may use well-known key names to define option
defaults, e.g. using `getAttrDef well-known-name pubkeys`.
'';
};
pubkey = mkOption {
type = nullOr str;
type = nullOr ssh-pubkey;
default = null;
};
uid = mkOption {
@ -199,6 +191,31 @@ types // rec {
addr4 = str;
addr6 = str;
pgp-pubkey = str;
ssh-pubkey = str;
ssh-privkey = submodule {
options = {
bits = mkOption {
type = nullOr (enum ["4096"]);
default = null;
};
path = mkOption {
type = either path str;
apply = x: {
path = toString x;
string = x;
}.${typeOf x};
};
type = mkOption {
type = enum ["rsa" "ed25519"];
default = "ed25519";
};
};
};
tinc-pubkey = str;
krebs.file-location = types.submodule {
options = {
# TODO user

View File

@ -30,6 +30,7 @@ let
load-env = {};
make-snapshot = {};
much = {};
newsbot-js = {};
nixpkgs = {};
push = {};
regfish = {};