diff --git a/hydra/jobsets.nix b/hydra/jobsets.nix new file mode 100644 index 00000000..6366f0e9 --- /dev/null +++ b/hydra/jobsets.nix @@ -0,0 +1,90 @@ +{ pulls, branches, ... }: +let + # create the json spec for the jobset + makeSpec = + contents: + builtins.derivation { + name = "spec.json"; + system = "x86_64-linux"; + preferLocalBuild = true; + allowSubstitutes = false; + builder = "/bin/sh"; + args = [ + (builtins.toFile "builder.sh" '' + echo "$contents" > $out + '') + ]; + contents = builtins.toJSON contents; + }; + + prs = readJSONFile pulls; + refs = readJSONFile branches; + + # template for creating a job + makeJob = + { + schedulingshares ? 10, + keepnr ? 3, + description, + flake, + enabled ? 1, + }: + { + inherit + description + flake + schedulingshares + keepnr + enabled + ; + type = 1; + hidden = false; + checkinterval = 300; # every 5 minutes + enableemail = false; + emailoverride = ""; + }; + + giteaHost = "ssh://gitea@nayeonie.com:2222"; + repo = "ahuston-0/hydra"; + # # Create a hydra job for a branch + jobOfRef = + name: + { ref, ... }: + if ((builtins.match "^refs/heads/(.*)$" ref) == null) then + null + else + { + name = builtins.replaceStrings [ "/" ] [ "-" ] "branch-${name}"; + value = makeJob { + description = "Branch ${name}"; + flake = "git+${giteaHost}/${repo}?ref=${ref}"; + }; + }; + + # Create a hydra job for a PR + jobOfPR = id: info: { + name = if info.draft then "draft-${id}" else "pr-${id}"; + value = makeJob { + description = "PR ${id}: ${info.title}"; + flake = "git+${giteaHost}/${repo}?ref=${info.head.ref}"; + enabled = info.state == "open"; + }; + }; + + # some utility functions + # converts json to name/value dicts + attrsToList = l: builtins.attrValues (builtins.mapAttrs (name: value: { inherit name value; }) l); + # wrapper function for reading json from file + readJSONFile = f: builtins.fromJSON (builtins.readFile f); + # remove null values from a set, in-case of branches that don't exist + mapFilter = f: l: builtins.filter (x: (x != null)) (map f l); + + # Create job set from PRs and branches + jobs = makeSpec ( + builtins.listToAttrs (map ({ name, value }: jobOfPR name value) (attrsToList prs)) + // builtins.listToAttrs (mapFilter ({ name, value }: jobOfRef name value) (attrsToList refs)) + ); +in +{ + jobsets = jobs; +} diff --git a/hydra/spec.json b/hydra/spec.json new file mode 100644 index 00000000..20407aec --- /dev/null +++ b/hydra/spec.json @@ -0,0 +1,35 @@ +{ + "enabled": 1, + "hidden": false, + "description": "ahuston-0's fork of hydra", + "nixexprinput": "nixexpr", + "nixexprpath": "hydra/jobsets.nix", + "checkinterval": 60, + "schedulingshares": 100, + "enableemail": false, + "emailoverride": "", + "keepnr": 3, + "type": 0, + "inputs": { + "nixexpr": { + "value": "ssh://gitea@nayeonie.com:2222/ahuston-0/hydra.git add-gitea-pulls", + "type": "git", + "emailresponsible": false + }, + "nixpkgs": { + "value": "https://github.com/NixOS/nixpkgs nixos-unstable", + "type": "git", + "emailresponsible": false + }, + "pulls": { + "type": "giteapulls", + "value": "nayeonie.com ahuston-0 hydra https", + "emailresponsible": false + }, + "branches": { + "type": "gitea_refs", + "value": "nayeonie.com ahuston-0 hydra heads https -", + "emailresponsible": false + } + } +}