This commit is contained in:
parent
5f644d0ccd
commit
a394b9cefd
167 changed files with 2795 additions and 2122 deletions
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
services.my-hydra.repos = {
|
||||
emacs = {};
|
||||
nixfleet = {};
|
||||
trotten = {};
|
||||
blog = {};
|
||||
emacs = { };
|
||||
nixfleet = { };
|
||||
trotten = { };
|
||||
blog = { };
|
||||
};
|
||||
}
|
||||
|
|
|
@ -3,58 +3,63 @@
|
|||
config,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
}:
|
||||
let
|
||||
cfg = config.services.my-hydra;
|
||||
toSpec = {
|
||||
name,
|
||||
owner,
|
||||
...
|
||||
}: let
|
||||
spec = {
|
||||
enabled = 1;
|
||||
hidden = false;
|
||||
description = "Declarative specification jobset automatically generated";
|
||||
checkinterval = 120;
|
||||
schedulingshares = 10000;
|
||||
enableemail = false;
|
||||
emailoverride = "";
|
||||
keepnr = 1;
|
||||
nixexprinput = "src";
|
||||
nixexprpath = "jobsets.nix";
|
||||
inputs = {
|
||||
src = {
|
||||
type = "path";
|
||||
value = pkgs.writeTextFile {
|
||||
name = "src";
|
||||
text = builtins.readFile ./jobsets.nix;
|
||||
destination = "/jobsets.nix";
|
||||
};
|
||||
emailresponsible = false;
|
||||
};
|
||||
repoInfoPath = {
|
||||
type = "path";
|
||||
value = pkgs.writeTextFile {
|
||||
name = "repo";
|
||||
text = builtins.toJSON {
|
||||
inherit name owner;
|
||||
toSpec =
|
||||
{
|
||||
name,
|
||||
owner,
|
||||
...
|
||||
}:
|
||||
let
|
||||
spec = {
|
||||
enabled = 1;
|
||||
hidden = false;
|
||||
description = "Declarative specification jobset automatically generated";
|
||||
checkinterval = 120;
|
||||
schedulingshares = 10000;
|
||||
enableemail = false;
|
||||
emailoverride = "";
|
||||
keepnr = 1;
|
||||
nixexprinput = "src";
|
||||
nixexprpath = "jobsets.nix";
|
||||
inputs = {
|
||||
src = {
|
||||
type = "path";
|
||||
value = pkgs.writeTextFile {
|
||||
name = "src";
|
||||
text = builtins.readFile ./jobsets.nix;
|
||||
destination = "/jobsets.nix";
|
||||
};
|
||||
emailresponsible = false;
|
||||
};
|
||||
repoInfoPath = {
|
||||
type = "path";
|
||||
value = pkgs.writeTextFile {
|
||||
name = "repo";
|
||||
text = builtins.toJSON {
|
||||
inherit name owner;
|
||||
};
|
||||
};
|
||||
emailresponsible = false;
|
||||
};
|
||||
prs = {
|
||||
type = "githubpulls";
|
||||
value = "${owner} ${name}";
|
||||
emailresponsible = false;
|
||||
};
|
||||
emailresponsible = false;
|
||||
};
|
||||
prs = {
|
||||
type = "githubpulls";
|
||||
value = "${owner} ${name}";
|
||||
emailresponsible = false;
|
||||
};
|
||||
};
|
||||
};
|
||||
drv = pkgs.writeTextFile {
|
||||
name = "hydra-jobset-specification-${name}";
|
||||
text = builtins.toJSON spec;
|
||||
destination = "/spec.json";
|
||||
};
|
||||
in "${drv}";
|
||||
in {
|
||||
drv = pkgs.writeTextFile {
|
||||
name = "hydra-jobset-specification-${name}";
|
||||
text = builtins.toJSON spec;
|
||||
destination = "/spec.json";
|
||||
};
|
||||
in
|
||||
"${drv}";
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
./config.nix
|
||||
../nginx-base
|
||||
|
@ -66,35 +71,40 @@ in {
|
|||
default = "hydra.aciceri.dev";
|
||||
};
|
||||
repos = lib.mkOption {
|
||||
type = lib.types.attrsOf (lib.types.submodule ({
|
||||
name,
|
||||
config,
|
||||
...
|
||||
}: {
|
||||
options = {
|
||||
name = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = name;
|
||||
};
|
||||
owner = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "aciceri";
|
||||
};
|
||||
description = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = config.homepage;
|
||||
};
|
||||
homepage = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "https://github.com/${config.owner}/${config.name}";
|
||||
};
|
||||
reportStatus = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
};
|
||||
};
|
||||
}));
|
||||
default = {};
|
||||
type = lib.types.attrsOf (
|
||||
lib.types.submodule (
|
||||
{
|
||||
name,
|
||||
config,
|
||||
...
|
||||
}:
|
||||
{
|
||||
options = {
|
||||
name = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = name;
|
||||
};
|
||||
owner = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "aciceri";
|
||||
};
|
||||
description = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = config.homepage;
|
||||
};
|
||||
homepage = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "https://github.com/${config.owner}/${config.name}";
|
||||
};
|
||||
reportStatus = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
)
|
||||
);
|
||||
default = { };
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -115,28 +125,38 @@ in {
|
|||
include ${config.age.secrets.hydra-github-token.path}
|
||||
</github_authorization>
|
||||
''
|
||||
+ (lib.concatMapStrings (repo:
|
||||
lib.optionalString repo.reportStatus
|
||||
''
|
||||
+ (lib.concatMapStrings (
|
||||
repo:
|
||||
lib.optionalString repo.reportStatus ''
|
||||
<githubstatus>
|
||||
jobs = ${repo.name}.*
|
||||
excludeBuildFromContext = 1
|
||||
useShortContext = 1
|
||||
</githubstatus>
|
||||
'') (builtins.attrValues cfg.repos));
|
||||
''
|
||||
) (builtins.attrValues cfg.repos));
|
||||
};
|
||||
|
||||
systemd.services.hydra-setup = {
|
||||
description = "Hydra CI setup";
|
||||
serviceConfig.Type = "oneshot";
|
||||
serviceConfig.RemainAfterExit = true;
|
||||
wantedBy = ["multi-user.target"];
|
||||
requires = ["hydra-init.service"];
|
||||
after = ["hydra-init.service"];
|
||||
environment = builtins.removeAttrs (config.systemd.services.hydra-init.environment) ["PATH"];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
requires = [ "hydra-init.service" ];
|
||||
after = [ "hydra-init.service" ];
|
||||
environment = builtins.removeAttrs (config.systemd.services.hydra-init.environment) [ "PATH" ];
|
||||
script =
|
||||
''
|
||||
PATH=$PATH:${lib.makeBinPath (with pkgs; [yq-go curl config.services.hydra.package])}
|
||||
PATH=$PATH:${
|
||||
lib.makeBinPath (
|
||||
with pkgs;
|
||||
[
|
||||
yq-go
|
||||
curl
|
||||
config.services.hydra.package
|
||||
]
|
||||
)
|
||||
}
|
||||
PASSWORD="$(cat ${config.age.secrets.hydra-admin-password.path})"
|
||||
if [ ! -e ~hydra/.setup-is-complete ]; then
|
||||
hydra-create-user admin \
|
||||
|
|
|
@ -2,42 +2,45 @@
|
|||
repoInfoPath,
|
||||
prs,
|
||||
...
|
||||
}: let
|
||||
}:
|
||||
let
|
||||
minutes = 60;
|
||||
hours = 60 * minutes;
|
||||
days = 24 * hours;
|
||||
filterAttrs = pred: set:
|
||||
builtins.listToAttrs (builtins.concatMap (name: let
|
||||
v = set.${name};
|
||||
mapAttrs' = f: set: builtins.listToAttrs (map (attr: f attr set.${attr}) (builtins.attrNames set));
|
||||
|
||||
mkJobset =
|
||||
{
|
||||
enabled ? 1,
|
||||
hidden ? false,
|
||||
type ? 1,
|
||||
description ? "",
|
||||
checkinterval ? 5 * minutes,
|
||||
schedulingshares ? 100,
|
||||
enableemail ? false,
|
||||
emailoverride ? "",
|
||||
keepnr ? 1,
|
||||
flake,
|
||||
}:
|
||||
{
|
||||
inherit
|
||||
enabled
|
||||
hidden
|
||||
type
|
||||
description
|
||||
checkinterval
|
||||
schedulingshares
|
||||
enableemail
|
||||
emailoverride
|
||||
keepnr
|
||||
flake
|
||||
;
|
||||
};
|
||||
|
||||
mkSpec =
|
||||
contents:
|
||||
let
|
||||
escape = builtins.replaceStrings [ ''"'' ] [ ''\"'' ];
|
||||
contentsJson = builtins.toJSON contents;
|
||||
in
|
||||
if pred name v
|
||||
then [
|
||||
{
|
||||
inherit name;
|
||||
value = v;
|
||||
}
|
||||
]
|
||||
else []) (builtins.attrNames set));
|
||||
mapAttrs' = f: set:
|
||||
builtins.listToAttrs (map (attr: f attr set.${attr}) (builtins.attrNames set));
|
||||
|
||||
mkJobset = {
|
||||
enabled ? 1,
|
||||
hidden ? false,
|
||||
type ? 1,
|
||||
description ? "",
|
||||
checkinterval ? 5 * minutes,
|
||||
schedulingshares ? 100,
|
||||
enableemail ? false,
|
||||
emailoverride ? "",
|
||||
keepnr ? 1,
|
||||
flake,
|
||||
} @ args: {inherit enabled hidden type description checkinterval schedulingshares enableemail emailoverride keepnr flake;};
|
||||
|
||||
mkSpec = contents: let
|
||||
escape = builtins.replaceStrings [''"''] [''\"''];
|
||||
contentsJson = builtins.toJSON contents;
|
||||
in
|
||||
builtins.derivation {
|
||||
name = "spec.json";
|
||||
system = "x86_64-linux";
|
||||
|
@ -54,20 +57,21 @@
|
|||
repo = builtins.fromJSON (builtins.readFile repoInfoPath);
|
||||
|
||||
pullRequests = builtins.fromJSON (builtins.readFile prs);
|
||||
pullRequestsToBuild = filterAttrs (n: pr: pr.head.repo != null && pr.head.repo.owner.login == repo.owner && pr.head.repo.name == repo.name) pullRequests;
|
||||
in {
|
||||
jobsets = mkSpec ({
|
||||
in
|
||||
{
|
||||
jobsets = mkSpec (
|
||||
{
|
||||
master = mkJobset {
|
||||
description = "${repo.name}'s master branch";
|
||||
flake = "git+ssh://git@github.com/${repo.owner}/${repo.name}?ref=master";
|
||||
};
|
||||
}
|
||||
// (mapAttrs' (n: pr: {
|
||||
name = "pullRequest_${n}";
|
||||
value = mkJobset {
|
||||
description = pr.title;
|
||||
flake = "git+ssh://git@github.com/${repo.owner}/${repo.name}?ref=${pr.head.ref}";
|
||||
};
|
||||
})
|
||||
pullRequests));
|
||||
name = "pullRequest_${n}";
|
||||
value = mkJobset {
|
||||
description = pr.title;
|
||||
flake = "git+ssh://git@github.com/${repo.owner}/${repo.name}?ref=${pr.head.ref}";
|
||||
};
|
||||
}) pullRequests)
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue