Skip to content

Commit

Permalink
experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
dermetfan committed Sep 30, 2022
1 parent ea57a13 commit e7a0e6e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 54 deletions.
7 changes: 4 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Expand Up @@ -66,7 +66,7 @@
cardano-mainnet-mirror.url = "github:input-output-hk/cardano-mainnet-mirror/nix";

tullia = {
url = "github:input-output-hk/tullia";
url = "github:input-output-hk/tullia/hydra";
inputs.nixpkgs.follows = "nixpkgs";
};
};
Expand Down
64 changes: 14 additions & 50 deletions nix/tullia.nix
@@ -1,9 +1,6 @@
self: system:

let
inherit (self.inputs.nixpkgs) lib;
inherit (self.inputs.utils.lib) flattenTree;

ciInputName = "GitHub event";
in rec {
tasks = let
Expand All @@ -22,60 +19,27 @@ in rec {
};
};

flakeUrl = {
config,
lib,
...
}: lib.escapeShellArg (
if config.actionRun.facts != {}
then with config.preset.github-ci; "github:${repo}/${sha}"
else "."
);

# the attribute name in `hydraJobs` for the current system
os = {
x86_64-linux = "linux";
x86_64-darwin = "macos";
}.${system};

# returns flattened attrset of `hydraJobs.${os}` and system-agnostic hydra jobs
systemHydraJobs = hydraJobs:
lib.pipe hydraJobs.${os} [
(__mapAttrs (_: flattenTree))
(__mapAttrs (category: lib.mapAttrs' (jobName: lib.nameValuePair "${os}.${category}.${jobName}")))
__attrValues
(__foldl' lib.mergeAttrs {})
]
// { inherit (hydraJobs) build-version cardano-deployment; };

# returns attrset of tullia tasks named with the given prefix
# that run the corresponding task and depend on each other in the order given
taskSequence = taskNamePrefix: taskNames: lib.listToAttrs (
lib.imap0 (i: taskName: lib.nameValuePair
(taskNamePrefix + taskName)
({...}: {
imports = [tasks.${taskName}];
after = lib.optional (i > 0) (
taskNamePrefix + __elemAt taskNames (i - 1)
);
})
) taskNames
);
inherit (self.inputs.tullia) drvToTaskRecursive taskSequence;

# returns attrset of tullia tasks that run the given hydra jobs sequentially in lexicographical order
hydraJobsTaskSequence = taskNamePrefix: hydraJobs: taskSequence taskNamePrefix (__attrNames hydraJobs);
hydraJobTasks = drvToTaskRecursive self.outputs.hydraJobs.${os};
hydraJobPrTasks = drvToTaskRecursive self.outputs.hydraJobsPr.${os};

ciPushTasks = hydraJobsTaskSequence "ci/push/" (systemHydraJobs self.outputs.hydraJobs);
ciPrTasks = hydraJobsTaskSequence "ci/pr/" (systemHydraJobs self.outputs.hydraJobsPr);
ciPushTasks = taskSequence "ci/push/" hydraJobTasks (__attrNames hydraJobTasks);
ciPrTasks = taskSequence "ci/pr/" hydraJobPrTasks (__attrNames hydraJobPrTasks);
in
(__mapAttrs (jobName: _: (args: {
imports = [common];
(__mapAttrs (jobName: task: {config, ...}: {
imports = [common task];

command.text = ''
job=${flakeUrl args}#hydraJobs.${lib.escapeShellArg jobName}
echo Building "$job"…
nix build -L "$job"
'';
drvToTask.flakeUrl =
if config.actionRun.facts != {}
then with config.preset.github-ci; "github:${repo}/${sha}"
else ".";

# some hydra jobs run NixOS tests
env.NIX_CONFIG = ''
Expand All @@ -84,16 +48,16 @@ in rec {

memory = 1024 * 8;
nomad.resources.cpu = 10000;
})) (systemHydraJobs self.outputs.hydraJobs))
}) hydraJobTasks)
// ciPushTasks
// ciPrTasks
// {
"ci/push" = {...}: {
"ci/push" = {lib, ...}: {
imports = [common];
after = [(lib.last (__attrNames ciPushTasks))];
};

"ci/pr" = {...}: {
"ci/pr" = {lib, ...}: {
imports = [common];
after = [(lib.last (__attrNames ciPrTasks))];
};
Expand Down

0 comments on commit e7a0e6e

Please sign in to comment.