From 139222728ef7851efc3ff0c7ce04063d701af8a8 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 2 Feb 2023 14:10:12 +0100 Subject: [PATCH 1/4] flakeModule: Do not filter nullable parameters in definition of herculesCI.repo --- flake-modules/herculesCI-attribute.nix | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/flake-modules/herculesCI-attribute.nix b/flake-modules/herculesCI-attribute.nix index 94095de..6c8f7bd 100644 --- a/flake-modules/herculesCI-attribute.nix +++ b/flake-modules/herculesCI-attribute.nix @@ -244,10 +244,13 @@ in config = { # Filter out values which are unavailable and therefore null. # e.g. hci effect run may not support owner and name. - # Always be careful when filtering, because it's not as lazy as you'd like. - # Shouldn't be a problem here though. - repo = lib.filterAttrs (k: v: v != null) { - inherit (primaryRepo) ref branch tag rev shortRev; + repo = { + ref = primaryRepo.ref; + branch = primaryRepo.branch or null; + tag = primaryRepo.tag or null; + rev = primaryRepo.rev; + shortRev = primaryRepo.shortRev; + } // lib.filterAttrs (k: v: v != null) { remoteHttpUrl = primaryRepo.remoteHttpUrl or null; remoteSshUrl = primaryRepo.remoteSshUrl or null; webUrl = primaryRepo.webUrl or null; From 103370346824f6e1845187bb2169d98e6530ff4c Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 2 Feb 2023 14:35:37 +0100 Subject: [PATCH 2/4] Extract testSupport.nix --- lib/mkHerculesCI-test.nix | 21 ++++----------------- lib/testSupport.nix | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 lib/testSupport.nix diff --git a/lib/mkHerculesCI-test.nix b/lib/mkHerculesCI-test.nix index dc50e7d..ff51026 100644 --- a/lib/mkHerculesCI-test.nix +++ b/lib/mkHerculesCI-test.nix @@ -2,26 +2,13 @@ args@ { inputs ? hercules-ci-effects.inputs , hercules-ci-effects ? if args?inputs then inputs.self else builtins.getFlake "git+file://${toString ./..}" }: +let + testSupport = import ./testSupport.nix args; +in rec { inherit (inputs) flake-parts; inherit (inputs.nixpkgs.lib) attrNames; - - # Approximates https://github.com/NixOS/nix/blob/7cd08ae379746749506f2e33c3baeb49b58299b8/src/libexpr/flake/call-flake.nix#L46 - # s/flake.outputs/args.outputs/ - callFlake = args@{ inputs, outputs, sourceInfo }: - let - outputs = args.outputs (inputs // { self = result; }); - result = outputs // sourceInfo // { inherit inputs outputs sourceInfo; _type = "flake"; }; - in - result; - - callFlakeOutputs = outputs: callFlake { - inherit outputs; - inputs = inputs // { - inherit hercules-ci-effects; - }; - sourceInfo = { }; - }; + inherit (testSupport) callFlake callFlakeOutputs; fakePkg = name: { inherit name; diff --git a/lib/testSupport.nix b/lib/testSupport.nix new file mode 100644 index 0000000..d8a5a69 --- /dev/null +++ b/lib/testSupport.nix @@ -0,0 +1,29 @@ +args@ +{ inputs ? hercules-ci-effects.inputs +, hercules-ci-effects ? if args?inputs then inputs.self else builtins.getFlake "git+file://${toString ./..}" +}: + +let + # Approximates https://github.com/NixOS/nix/blob/7cd08ae379746749506f2e33c3baeb49b58299b8/src/libexpr/flake/call-flake.nix#L46 + # s/flake.outputs/args.outputs/ + callFlake = args@{ inputs, outputs, sourceInfo }: + let + outputs = args.outputs (inputs // { self = result; }); + result = outputs // sourceInfo // { inherit inputs outputs sourceInfo; _type = "flake"; }; + in + result; + + callFlakeOutputs = outputs: callFlake { + inherit outputs; + inputs = inputs // { + inherit hercules-ci-effects; + }; + sourceInfo = { }; + }; + +in { + inherit + callFlake + callFlakeOutputs + ; +} \ No newline at end of file From 293d93cfa1c7ec163b8d5a19eaca85daa2c7bbb0 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 2 Feb 2023 14:37:50 +0100 Subject: [PATCH 3/4] Test flakeModule config.repo.{branch,tag} --- flake-modules/herculesCI-eval-test.nix | 47 ++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/flake-modules/herculesCI-eval-test.nix b/flake-modules/herculesCI-eval-test.nix index b393d5a..20f60c9 100644 --- a/flake-modules/herculesCI-eval-test.nix +++ b/flake-modules/herculesCI-eval-test.nix @@ -1,9 +1,46 @@ -{ inputs }: +args@ +{ inputs ? hercules-ci-effects.inputs +, hercules-ci-effects ? if args?inputs then inputs.self else builtins.getFlake "git+file://${toString ./..}" +}: +let + testSupport = import ../lib/testSupport.nix args; +in rec { inherit (inputs) flake-parts; + inherit (testSupport) callFlakeOutputs; + + emptyFlake = callFlakeOutputs (inputs: + flake-parts.lib.mkFlake { inherit inputs; } { + imports = [ + ../flake-module.nix + ]; + systems = [ "x86_64-linux" ]; + } + ); + + fakeRepoBranch = { + branch = "main"; + ref = "refs/heads/main"; + rev = "deadbeef"; + shortRev = "deadbe"; + tag = null; + remoteHttpUrl = "https://git.forge/repo.git"; + }; + fakeRepoTag = { + branch = null; + ref = "refs/heads/main"; + rev = "deadbeef"; + shortRev = "deadbe"; + tag = "1.0"; + remoteHttpUrl = "https://git.forge/repo.git"; + }; + fakeHerculesCI = repo: { + primaryRepo = repo; + inherit (repo) branch ref tag rev shortRev remoteHttpUrl; + }; example1 = - flake-parts.lib.mkFlake { self = { }; } + flake-parts.lib.mkFlake { inputs = { self = { }; }; } ({ ... }: { imports = [ ../flake-module.nix @@ -49,6 +86,12 @@ rec { minute = null; }; + assert (emptyFlake.herculesCI (fakeHerculesCI fakeRepoBranch))._debug.repo.branch == "main"; + assert (emptyFlake.herculesCI (fakeHerculesCI fakeRepoBranch))._debug.repo.tag == null; + + assert (emptyFlake.herculesCI (fakeHerculesCI fakeRepoTag))._debug.repo.branch == null; + assert (emptyFlake.herculesCI (fakeHerculesCI fakeRepoTag))._debug.repo.tag == "1.0"; + ok; } From f0ca2415b9c251cf1ede36355abb140a8002a476 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 2 Feb 2023 14:41:30 +0100 Subject: [PATCH 4/4] Test: invoke example1 properly --- flake-modules/herculesCI-eval-test.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/flake-modules/herculesCI-eval-test.nix b/flake-modules/herculesCI-eval-test.nix index 20f60c9..4b2e9f8 100644 --- a/flake-modules/herculesCI-eval-test.nix +++ b/flake-modules/herculesCI-eval-test.nix @@ -40,7 +40,8 @@ rec { }; example1 = - flake-parts.lib.mkFlake { inputs = { self = { }; }; } + callFlakeOutputs (inputs: + flake-parts.lib.mkFlake { inherit inputs; } ({ ... }: { imports = [ ../flake-module.nix @@ -58,7 +59,8 @@ rec { minute = 59; }; herculesCI.onSchedule.scheduledJob3 = { }; - }); + }) + ); tests = ok: