mirror of
https://git.sr.ht/~magic_rb/cluster
synced 2024-11-22 08:04:20 +01:00
7011cf1eb3
Signed-off-by: main <magic_rb@redalder.org>
149 lines
5 KiB
Nix
149 lines
5 KiB
Nix
{
|
|
inputs = {
|
|
nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-unstable";
|
|
|
|
nixng = {
|
|
url = "github:nix-community/NixNG";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
website = {
|
|
url = "git+https://gitea.redalder.org/Magic_RB/website";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
camptules = {
|
|
url = "git+https://gitea.redalder.org/ThyW/camptules";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
};
|
|
|
|
outputs = { self, nixpkgs, nixng, ... }@inputs:
|
|
with nixpkgs.lib;
|
|
let
|
|
supportedSystems = [ "x86_64-linux" "i686-linux" "aarch64-linux" ];
|
|
forAllSystems' = systems: fun: nixpkgs.lib.genAttrs systems fun;
|
|
forAllSystems = forAllSystems' supportedSystems;
|
|
|
|
containers =
|
|
let base = { nglib = nixng.nglib nixpkgs.lib; inherit nixpkgs; };
|
|
in
|
|
{
|
|
hydra = (import ./containers/hydra.nix base).hydra;
|
|
hydraPostgresql = (import ./containers/hydra.nix base).postgresql;
|
|
ingressToothpick = import ./containers/ingress-toothpick.nix base;
|
|
ingressBlowhole = import ./containers/ingress-blowhole.nix base;
|
|
website = import ./containers/website.nix (base // { inherit (inputs.website) website; });
|
|
jmusicbot = import ./containers/jmusicbot.nix base;
|
|
camptules = (import ./containers/camptules.nix (base // { inherit (inputs) camptules; }));
|
|
gitea = import ./containers/gitea.nix base;
|
|
minecraft = import ./containers/minecraft.nix base;
|
|
mosquitto = import ./containers/mosquitto.nix base;
|
|
dovecot = import ./containers/dovecot.nix base;
|
|
getmail = import ./containers/getmail base;
|
|
syncthing = import ./containers/syncthing.nix base;
|
|
zigbee2mqtt = import ./containers/zigbee2mqtt.nix base;
|
|
home-assistant = import ./containers/home-assistant.nix base;
|
|
reicio = import ./containers/reicio.nix base;
|
|
};
|
|
in
|
|
{
|
|
ociImages = mapAttrs (n: v: v.config.system.build.ociImage) containers;
|
|
|
|
nixngSystems = containers;
|
|
|
|
hydraJobs =
|
|
let
|
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
|
makeJob = container:
|
|
pkgs.stdenv.mkDerivation
|
|
|
|
{ name = "${container.stream.imageName}-hydra-job";
|
|
buildPhase =
|
|
''
|
|
_workdir=$(mktemp -d)
|
|
mkdir -p $out/nix-support $out/layers
|
|
|
|
${container.stream} | tar -xf - -C $_workdir
|
|
for img in $_workdir/*/*.tar ; do
|
|
_hash=$(basename $(dirname $img))
|
|
|
|
cp $img $out/layers/$_hash.tar
|
|
done
|
|
|
|
_config=$(basename $(find $_workdir -name '*.json' ! -name 'manifest.json' -type f))
|
|
|
|
cp $_workdir/manifest.json $out/manifest.json
|
|
cp $_workdir/$_config $out/$_config
|
|
|
|
ln -s ${container.stream} $out/stream
|
|
|
|
cat > $out/nix-support/hydra-build-products <<EOF
|
|
directory image-layers $out/layers
|
|
|
|
file manifest $out/manifest.json
|
|
file config $out/$_config
|
|
|
|
file executable $out/stream
|
|
EOF
|
|
'' ;
|
|
|
|
phases = [ "buildPhase" ];
|
|
|
|
nativeBuildInputs = with pkgs; [ jq ];
|
|
};
|
|
in
|
|
nixpkgs.lib.mapAttrs (n: v: makeJob v) self.ociImages;
|
|
|
|
|
|
devShell = forAllSystems (system:
|
|
let
|
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
|
copy-containers = pkgs.writeShellScriptBin "copy-containers"
|
|
''
|
|
_profile="$1"
|
|
_address="$2"
|
|
_selector="$3"
|
|
|
|
function profile_blowhole()
|
|
{
|
|
_images=("camptules" "gitea" "home-assistant" "hydra" \
|
|
"minecraft" "mosquitto" "website" "zigbee2mqtt")
|
|
|
|
for _image in ''${_images[@]}
|
|
do
|
|
deploy $_address $_image
|
|
done
|
|
}
|
|
|
|
function profile_toothpick()
|
|
{
|
|
images=("ingress")
|
|
|
|
for _image in ''${_images[@]}
|
|
do
|
|
deploy $_address $_image
|
|
done
|
|
}
|
|
|
|
function deploy()
|
|
{
|
|
_address="$1"
|
|
_image="$2"
|
|
|
|
nix build ".#ociImages.$_image.stream" -o result-script && \
|
|
./result-script | ssh "$_address" docker load && \
|
|
ssh "$_address" docker tag "nixng-$_image:latest" "nixng-$_image:local"
|
|
}
|
|
|
|
"profile_$_profile"
|
|
'';
|
|
in
|
|
pkgs.mkShell {
|
|
nativeBuildInputs = with pkgs;
|
|
[ nomad_1_1 consul vault jq
|
|
copy-containers
|
|
];
|
|
}
|
|
);
|
|
};
|
|
}
|