implement basis docker network

This commit is contained in:
Maximilian Güntner
2020-06-19 19:19:18 +02:00
parent 4e95a1c0c8
commit 5ba744be76

View File

@@ -1,18 +1,47 @@
{ config, lib, ... }: { config, lib, pkgs, ... }:
with lib; with lib;
let let
cfg = config.foo.bar; cfg = config.docker-networks;
in dockerNetwork = { ... }: {
options = {
{ usedBy = mkOption {
options.foo.bar = { type = with types; listOf str;
enable = mkEnableOption "foobar"; default = [];
};
};
}; };
config = mkIf cfg.enable { mkService = name: network: let
# ... mkBefore = map (x: "docker-${x}.service") network.usedBy;
in rec {
wantedBy = [ "multi-user.target" ];
after = [ "docker.service" "docker.socket" ];
before = mkBefore;
requires = after;
serviceConfig = {
ExecStart = ''
${pkgs.docker}/bin/docker network create ${name}
'';
ExecStop = ''
${pkgs.docker}/bin/docker network rm ${name}
'';
RemainAfterExit="true";
Type="oneshot";
};
};
in
{
options.docker-networks = mkOption {
default = {};
type = types.attrsOf (types.submodule dockerNetwork);
description = "docker networks";
};
config = mkIf (cfg != {}) {
systemd.services = mapAttrs' (n: v: nameValuePair "docker-network-${n}" (mkService n v)) cfg;
}; };
} }