Add NixOS modules

This commit is contained in:
clerie 2023-07-21 23:26:00 +02:00
parent 5177d942e4
commit ffefe1fea1
2 changed files with 94 additions and 0 deletions

View File

@ -28,6 +28,22 @@
default = self.apps.x86_64-linux.update-from-hydra;
};
nixosModules = {
update-from-hydra = { ... }: {
imports = [
./nix/module.nix
];
nixpkgs.overlays = [
(_: _: {
inherit (self.packages."x86_64-linux")
update-from-hydra;
})
];
};
default = self.nixosModules.update-from-hydra;
};
hydraJobs = {
inherit (self)
packages;

78
nix/module.nix Normal file
View File

@ -0,0 +1,78 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.update-from-hydra;
repositoryOpts = { config, ... }@moduleAttrs: {
options = {
updatePath = mkOption {
type = types.path;
description = ''
Path to the symlink pointing to the hydra build output store path
'';
};
hydraUrl = mkOption {
type = types.str;
example = "https://hydra.clerie.de/job/clerie/chaosevents/packages.x86_64-linux.chaosevents/latest-finished";
description = ''
Url to Hydra
'';
};
storeUri = mkOption {
type = types.str;
description = ''
Uri to nix store from which the store path build in Hydra can be copied from
'';
};
startAt = mkOption {
type = with types; either str (listOf str);
default = "hourly";
description = ''
How often the directory should be updated.
Format specified by `systemd.time 7`.
This value can also be a list of `systemd.time 7` formatted
strings, in which case the service will be started on multiple
schedules.
'';
};
};
};
in {
options = {
services.update-from-hydra = {
enable = mkEnableOption "Make a hydra build output availiable with a symlink and keep it up to date";
paths = mkOption {
type = with types; attrsOf (submodule repositoryOpts);
default = {};
};
};
};
config = mkIf cfg.enable {
systemd.services = (mapAttrs' (name: path: let
in nameValuePair "update-from-hydra-${name}" {
inherit (path) startAt;
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "oneshot";
};
path = [ pkgs.nix ];
script = ''
${pkgs.update-from-hydra}/bin/update-from-hydra "${path.hydraUrl}" "${path.updatePath}" "${path.storeUri}"
'';
}
) cfg.paths);
};
}