cluster/flake.nix
Magic_RB 68d5cb31f3
Add the actual Hydra Job for JMusicBot
Signed-off-by: Magic_RB <magic_rb@redalder.org>
2021-09-01 00:07:35 +02:00

95 lines
3 KiB
Nix

{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-21.05";
nixng = {
url = "github:MagicRB/NixNG";
inputs.nixpkgs.follows = "nixpkgs";
};
website = {
url = "git+https://gitea.redalder.org/Magic_RB/website";
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 = {
hydra = (import ./containers/hydra.nix nixng.lib).hydra;
hydraPostgresql = (import ./containers/hydra.nix nixng.lib).postgresql;
ingress = (import ./containers/ingress.nix nixng.lib);
website = (import ./containers/website.nix inputs.website.website nixng.lib);
jmusicbot = (import ./containers/jmusicbot.nix nixng.lib);
};
in
{
ociImages = mapAttrs (n: v: v.config.system.build.ociImage) 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))
gzip $img -c > $out/layers/$_hash.tar.gz
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
{
website = makeJob self.ociImages.website;
hydra = makeJob self.ociImages.hydra;
hydraPostgresql = makeJob self.ociImages.hydraPostgresql;
ingress = makeJob self.ociImages.ingress;
jmusicbot = makeJob self.ociImage.jmusicbot;
};
devShell = forAllSystems (system:
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
in
pkgs.mkShell {
nativeBuildInputs = with pkgs;
[ nomad_1_1 consul vault jq
];
}
);
};
}