forked from the-distro/infra
raito
9a04ef909b
We don't need weird Perl scripts where we are going. Here's a streaming channel-scripts deployment with plenty of bells, including OTLP. Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
64 lines
1.6 KiB
Nix
64 lines
1.6 KiB
Nix
# Vendored from https://raw.githubusercontent.com/NixOS/infra/master/lib/service-order.nix
|
|
# TODO: get rid of me?
|
|
# Ordering Services
|
|
#
|
|
# Given a set of services, make them run one at a time in a specific
|
|
# order, on a timer.
|
|
{ lib }:
|
|
{
|
|
# Given a list of systemd service, give each one an After
|
|
# attribute, so they start in a specific order. The returned
|
|
# list can be converted in to a systemd.services attrset with
|
|
# `lib.listToAttrs`.
|
|
#
|
|
# Example:
|
|
#
|
|
# mkOrderedChain [
|
|
# { name = "foo"; value = { script = "true"; }; }
|
|
# { name = "bar"; value = { script = "true"; }; }
|
|
# ]
|
|
#
|
|
# => [
|
|
# {
|
|
# name = "foo";
|
|
# value = {
|
|
# script = "true";
|
|
# unitConfig = { After = []; };
|
|
# };
|
|
# }
|
|
# {
|
|
# name = "bar";
|
|
# value = {
|
|
# script = "true";
|
|
# unitConfig = { After = [ "bar" ]; };
|
|
# };
|
|
# }
|
|
#
|
|
mkOrderedChain = jobs: let
|
|
unitConfigFrom = job: job.unitConfig or {};
|
|
afterFrom = job: (unitConfigFrom job).After or [];
|
|
previousFrom = collector:
|
|
if collector ? previous
|
|
then [collector.previous]
|
|
else [];
|
|
|
|
ordered = builtins.foldl'
|
|
(collector: item: {
|
|
services = collector.services
|
|
++ [{
|
|
inherit (item) name;
|
|
value = item.value // {
|
|
unitConfig = (unitConfigFrom item.value) //
|
|
{
|
|
After = (afterFrom item.value) ++
|
|
(previousFrom collector);
|
|
};
|
|
};
|
|
}];
|
|
previous = "${item.name}.service";
|
|
})
|
|
{ services = []; }
|
|
jobs;
|
|
in ordered.services;
|
|
}
|