2021-10-28 21:59:01 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
|
|
|
inherit (lib)
|
2022-10-11 23:22:17 +02:00
|
|
|
any
|
2021-10-28 21:59:01 +02:00
|
|
|
attrValues
|
|
|
|
mkIf
|
|
|
|
mkOption
|
2022-10-11 23:22:17 +02:00
|
|
|
mkEnableOption
|
2021-10-28 21:59:01 +02:00
|
|
|
mkMerge
|
|
|
|
types
|
|
|
|
;
|
|
|
|
|
|
|
|
cfg = config.virtualisation.arion;
|
|
|
|
|
|
|
|
projectType = types.submoduleWith {
|
|
|
|
modules = [ projectModule ];
|
|
|
|
};
|
|
|
|
|
|
|
|
projectModule = { config, name, ... }: {
|
|
|
|
options = {
|
|
|
|
settings = mkOption {
|
|
|
|
description = ''
|
|
|
|
Arion project definition, otherwise known as arion-compose.nix contents.
|
|
|
|
|
|
|
|
See <link xlink:href="https://docs.hercules-ci.com/arion/options/">https://docs.hercules-ci.com/arion/options/</link>.
|
|
|
|
'';
|
2022-05-31 23:46:14 +02:00
|
|
|
type = arionSettingsType name;
|
2021-10-28 21:59:01 +02:00
|
|
|
visible = "shallow";
|
|
|
|
};
|
2022-10-11 23:22:17 +02:00
|
|
|
rootless = mkEnableOption "Run this project in rootless mode";
|
2021-10-28 21:59:01 +02:00
|
|
|
_systemd = mkOption { internal = true; };
|
|
|
|
};
|
2022-10-10 23:43:30 +02:00
|
|
|
config =
|
2022-10-11 23:22:17 +02:00
|
|
|
let
|
|
|
|
|
|
|
|
service = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "sockets.target" ];
|
|
|
|
|
|
|
|
path = [
|
|
|
|
cfg.package
|
|
|
|
cfg.docker.client.package
|
|
|
|
];
|
|
|
|
environment.ARION_PREBUILT = config.settings.out.dockerComposeYaml;
|
|
|
|
environment.DOCKER_HOST = mkIf config.rootless "unix:///run/user/1000/docker.sock"; # TODO: Do not hardcode path
|
|
|
|
script = ''
|
|
|
|
echo 1>&2 "docker compose file: $ARION_PREBUILT"
|
|
|
|
arion --prebuilt-file "$ARION_PREBUILT" up
|
|
|
|
'';
|
|
|
|
};
|
2021-10-28 21:59:01 +02:00
|
|
|
|
2022-10-10 23:43:30 +02:00
|
|
|
in
|
2022-10-11 23:22:17 +02:00
|
|
|
if false then
|
|
|
|
# if false then
|
2022-10-10 23:56:32 +02:00
|
|
|
{ _systemd.user.services."arion-${name}" = service; }
|
2022-10-10 23:43:30 +02:00
|
|
|
else
|
2022-10-10 23:56:32 +02:00
|
|
|
{ _systemd.services."arion-${name}" = service; };
|
2021-10-28 21:59:01 +02:00
|
|
|
};
|
|
|
|
|
2022-05-31 23:46:14 +02:00
|
|
|
arionSettingsType = name:
|
|
|
|
(cfg.package.eval { modules = [ { project.name = lib.mkDefault name; } ]; }).type or (
|
2021-10-28 21:59:01 +02:00
|
|
|
throw "lib.evalModules did not produce a type. Please upgrade Nixpkgs to nixos-unstable or >=nixos-21.11"
|
|
|
|
);
|
|
|
|
|
|
|
|
in
|
|
|
|
{
|
|
|
|
disabledModules = [ "virtualisation/arion.nix" ];
|
|
|
|
|
|
|
|
options = {
|
|
|
|
virtualisation.arion = {
|
|
|
|
backend = mkOption {
|
2022-10-11 16:50:55 +02:00
|
|
|
type = types.enum [ "podman-socket" "docker" ];
|
2021-10-28 21:59:01 +02:00
|
|
|
description = ''
|
|
|
|
Which container implementation to use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
2022-10-10 23:43:30 +02:00
|
|
|
|
2021-10-28 21:59:01 +02:00
|
|
|
default = (import ./. { inherit pkgs; }).arion;
|
|
|
|
description = ''
|
|
|
|
Arion package to use. This will provide <literal>arion</literal>
|
|
|
|
executable that starts the project.
|
|
|
|
|
|
|
|
It also must provide the arion <literal>eval</literal> function as
|
|
|
|
an attribute.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
docker.client.package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
internal = true;
|
|
|
|
};
|
|
|
|
projects = mkOption {
|
|
|
|
type = types.attrsOf projectType;
|
|
|
|
default = { };
|
|
|
|
description = ''
|
|
|
|
Arion projects to be run as a service.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf (cfg.projects != { }) (
|
|
|
|
mkMerge [
|
|
|
|
{
|
|
|
|
systemd = mkMerge (map (p: p._systemd) (attrValues cfg.projects));
|
|
|
|
}
|
|
|
|
(mkIf (cfg.backend == "podman-socket") {
|
|
|
|
virtualisation.docker.enable = false;
|
|
|
|
virtualisation.podman.enable = true;
|
|
|
|
virtualisation.podman.dockerSocket.enable = true;
|
|
|
|
virtualisation.podman.defaultNetwork.dnsname.enable = true;
|
|
|
|
|
|
|
|
virtualisation.arion.docker.client.package = pkgs.docker-client;
|
|
|
|
})
|
|
|
|
(mkIf (cfg.backend == "docker") {
|
|
|
|
virtualisation.docker.enable = true;
|
|
|
|
virtualisation.arion.docker.client.package = pkgs.docker;
|
|
|
|
})
|
2022-10-11 23:22:17 +02:00
|
|
|
(mkIf (any (project: project.rootless) (attrValues cfg.projects)) {
|
|
|
|
virtualisation.docker.rootless.enable = true;
|
2022-10-10 23:43:30 +02:00
|
|
|
})
|
2021-10-28 21:59:01 +02:00
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|