2024-01-05 03:41:21 -05:00
|
|
|
{
|
|
|
|
arion,
|
|
|
|
config,
|
|
|
|
lib,
|
2024-01-08 01:11:22 -05:00
|
|
|
pkgs,
|
2024-01-14 16:09:55 -05:00
|
|
|
self,
|
2024-01-05 03:41:21 -05:00
|
|
|
...
|
2024-01-06 02:40:54 -05:00
|
|
|
} @ inputs:
|
2024-01-05 03:41:21 -05:00
|
|
|
with lib;
|
|
|
|
with builtins; let
|
2024-01-16 23:51:28 -05:00
|
|
|
inherit (config.vars) mainUser hostName;
|
2024-01-07 02:05:16 -05:00
|
|
|
configPath = "/var/lib/arion";
|
2024-01-05 03:41:21 -05:00
|
|
|
in {
|
|
|
|
imports = [arion.nixosModules.arion];
|
|
|
|
|
2024-01-09 13:13:04 -05:00
|
|
|
users.extraUsers.${mainUser}.extraGroups = ["docker"];
|
|
|
|
|
2024-01-09 13:48:00 -05:00
|
|
|
environment.systemPackages = with pkgs; [
|
|
|
|
nix-prefetch-docker
|
|
|
|
(writeShellScriptBin "updateImages" ''
|
|
|
|
pull() {
|
|
|
|
FILE="$1"
|
|
|
|
IMAGE=$(sed -n 's/.*imageName = "\([^"]*\).*/\1/p' "$FILE")
|
|
|
|
TAG=$(sed -n 's/.*finalImageTag = "\([^"]*\).*/\1/p' "$FILE")
|
|
|
|
|
|
|
|
echo "$IMAGE $TAG"
|
|
|
|
|
|
|
|
PREFETCH=$(nix-prefetch-docker "$IMAGE" "$TAG")
|
|
|
|
|
|
|
|
echo -e "pkgs:\npkgs.dockerTools.pullImage $PREFETCH" > "$FILE"
|
|
|
|
}
|
|
|
|
|
|
|
|
DIR="$1"
|
|
|
|
if [ -z "$DIR" ]; then
|
|
|
|
DIR="."
|
|
|
|
fi
|
|
|
|
|
|
|
|
IFS=$'\n'
|
|
|
|
for i in $(find "$DIR"/images -type f); do
|
|
|
|
pull "$i"
|
|
|
|
done
|
|
|
|
unset IFS
|
|
|
|
'')
|
|
|
|
];
|
2024-01-07 02:05:16 -05:00
|
|
|
|
|
|
|
services.borgbackup.configs.arion = {
|
|
|
|
paths = [configPath];
|
|
|
|
exclude = ["**/lineageos*"];
|
2024-01-05 03:41:21 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
virtualisation = {
|
2024-01-07 04:21:44 -05:00
|
|
|
docker = {
|
2024-01-05 03:41:21 -05:00
|
|
|
enable = true;
|
2024-01-07 04:21:44 -05:00
|
|
|
storageDriver = "btrfs";
|
2024-01-05 03:41:21 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
arion = {
|
2024-01-07 04:21:44 -05:00
|
|
|
backend = "docker";
|
2024-01-05 03:41:21 -05:00
|
|
|
|
|
|
|
projects = let
|
2024-01-16 23:51:28 -05:00
|
|
|
basePath = "${self}/devices/${hostName}/modules/arion";
|
2024-01-14 16:09:55 -05:00
|
|
|
|
2024-01-05 03:41:21 -05:00
|
|
|
composeFiles =
|
|
|
|
filter (n: hasSuffix "compose.nix" (toString n))
|
2024-01-14 16:09:55 -05:00
|
|
|
(filesystem.listFilesRecursive basePath);
|
2024-01-05 03:41:21 -05:00
|
|
|
|
2024-01-06 02:40:54 -05:00
|
|
|
projects = filterAttrs (n: v: v.enabled or true) (listToAttrs (map (p: {
|
2024-01-05 03:41:21 -05:00
|
|
|
name = elemAt (match ".*\/(.*)\/compose\.nix" (toString p)) 0;
|
2024-01-06 02:40:54 -05:00
|
|
|
|
|
|
|
value = import p (inputs
|
|
|
|
// {
|
2024-01-08 01:11:22 -05:00
|
|
|
importImage = file: pkgs.callPackage file pkgs;
|
2024-01-07 02:05:16 -05:00
|
|
|
rwPath =
|
|
|
|
configPath
|
|
|
|
+ "/"
|
2024-01-14 16:09:55 -05:00
|
|
|
+ removePrefix basePath "${dirOf p}";
|
2024-01-06 02:40:54 -05:00
|
|
|
});
|
2024-01-05 03:41:21 -05:00
|
|
|
})
|
2024-01-06 02:40:54 -05:00
|
|
|
composeFiles));
|
2024-01-05 03:41:21 -05:00
|
|
|
in
|
|
|
|
mapAttrs (n: v: {
|
|
|
|
# https://docs.hercules-ci.com/arion/options
|
|
|
|
settings = {
|
|
|
|
enableDefaultNetwork = v.enableDefaultNetwork or true;
|
2024-01-08 01:11:22 -05:00
|
|
|
|
|
|
|
networks =
|
|
|
|
optionalAttrs (hasAttr "networks" v)
|
|
|
|
v.networks;
|
2024-01-05 03:41:21 -05:00
|
|
|
|
2024-01-06 02:40:54 -05:00
|
|
|
services =
|
|
|
|
mapAttrs (n': v': {
|
2024-01-08 01:11:22 -05:00
|
|
|
# https://github.com/hercules-ci/arion/issues/169#issuecomment-1301370634
|
|
|
|
build.image =
|
|
|
|
optionalAttrs (hasAttr "hostImage" v')
|
|
|
|
(mkForce v'.hostImage);
|
|
|
|
|
|
|
|
image =
|
|
|
|
optionalAttrs (hasAttr "customImage" v')
|
|
|
|
v'.customImage;
|
|
|
|
|
|
|
|
service =
|
|
|
|
filterAttrs
|
|
|
|
(n: v: n != "customImage" && n != "hostImage")
|
|
|
|
v';
|
2024-01-06 02:40:54 -05:00
|
|
|
})
|
|
|
|
v.services;
|
2024-01-05 03:41:21 -05:00
|
|
|
};
|
|
|
|
})
|
|
|
|
projects;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|