refactor: reorganise flake, tests and repo tasks
This commit is contained in:
1 parent
b93147c7a6
commit
794ca5a086
34 files changed
+670
-220
No files matched your search
@@ -0,0 +1,54 @@
|
||||
{
|
||||
sampleUnits,
|
||||
lib,
|
||||
coreutils,
|
||||
runCommand,
|
||||
writeText,
|
||||
}:
|
||||
let
|
||||
toUnitFile = lib.generators.toINI { listsAsDuplicateKeys = true; };
|
||||
|
||||
serviceFile =
|
||||
name: spec:
|
||||
writeText "${name}.service" (toUnitFile {
|
||||
Unit = {
|
||||
Description = spec.description;
|
||||
After = map (dependency: "${dependency}.service") (spec.after or [ ]);
|
||||
};
|
||||
Service = {
|
||||
Type = "oneshot";
|
||||
ExecStart = [
|
||||
"${coreutils}/bin/sleep ${spec.seconds}"
|
||||
]
|
||||
++ lib.optional (spec.fails or false) "${coreutils}/bin/false";
|
||||
}
|
||||
// lib.optionalAttrs (spec ? stopSeconds) {
|
||||
RemainAfterExit = true;
|
||||
ExecStop = "${coreutils}/bin/sleep ${spec.stopSeconds}";
|
||||
};
|
||||
});
|
||||
|
||||
serviceNames = map (name: "${name}.service") (lib.attrNames sampleUnits.services);
|
||||
|
||||
targetFile = writeText "${sampleUnits.target}.target" (toUnitFile {
|
||||
Unit = {
|
||||
Description = "bootvine demo services";
|
||||
Wants = serviceNames;
|
||||
After = serviceNames;
|
||||
};
|
||||
});
|
||||
unitFiles =
|
||||
lib.mapAttrsToList (name: spec: {
|
||||
name = "${name}.service";
|
||||
path = serviceFile name spec;
|
||||
}) sampleUnits.services
|
||||
++ [
|
||||
{
|
||||
name = "${sampleUnits.target}.target";
|
||||
path = targetFile;
|
||||
}
|
||||
];
|
||||
in
|
||||
runCommand "bootvine-sample-unit-files" { } (
|
||||
lib.concatMapStringsSep "\n" (unit: "install -Dm644 ${unit.path} $out/${unit.name}") unitFiles
|
||||
)
|
||||
Reference in new issue
Block a user