|
12 | 12 | }: |
13 | 13 | let |
14 | 14 | writePipelineGenerator = |
15 | | - { name, hook }: |
| 15 | + { backend, pipelines }: |
16 | 16 | pkgs.writeShellApplication { |
17 | | - name = "generate-${name}"; |
| 17 | + name = "generate-${backend}"; |
18 | 18 | runtimeInputs = [ pkgs.yq-go ]; |
19 | | - text = '' |
20 | | - out="$(nix build --extra-experimental-features 'nix-command flakes' \ |
21 | | - --print-out-paths \ |
22 | | - .#ci-pipeline-${name}-${hook.settings.pipeline} |
23 | | - )" |
| 19 | + text = |
| 20 | + let |
| 21 | + generatePipeline = name: outputPath: '' |
| 22 | + out="$(nix build --extra-experimental-features 'nix-command flakes' \ |
| 23 | + --print-out-paths \ |
| 24 | + .#ci-pipeline-${backend}-${name} |
| 25 | + )" |
24 | 26 |
|
25 | | - mkdir -p "$(dirname "${hook.settings.outputPath}")" |
26 | | - yq --prettyPrint --output-format yaml "$out" > "${hook.settings.outputPath}" |
27 | | - ''; |
| 27 | + mkdir -p "$(dirname "${outputPath}")" |
| 28 | + yq --prettyPrint --output-format yaml "$out" > "${outputPath}" |
| 29 | + ''; |
| 30 | + in |
| 31 | + lib.concatStringsSep "\n" (lib.mapAttrsToList generatePipeline pipelines); |
28 | 32 | }; |
29 | 33 | in |
30 | 34 | { |
|
34 | 38 | type = types.submodule { |
35 | 39 | imports = [ hookModule ]; |
36 | 40 | options.settings = { |
37 | | - pipeline = lib.mkOption { |
38 | | - type = types.str; |
39 | | - description = "The pipeline to generate."; |
40 | | - default = "default"; |
41 | | - example = "pr"; |
42 | | - }; |
43 | | - |
44 | | - outputPath = lib.mkOption { |
45 | | - type = types.str; |
46 | | - description = "The path of the output file generated."; |
47 | | - default = ".github/workflows/ci.yaml"; |
48 | | - example = ".github/workflows/example.yaml"; |
| 41 | + pipelines = lib.mkOption { |
| 42 | + type = types.attrsOf types.str; |
| 43 | + default = { |
| 44 | + default = ".github/workflows/ci.yaml"; |
| 45 | + }; |
| 46 | + description = "Pipeline name to output path mapping."; |
| 47 | + example = lib.literalExpression '' |
| 48 | + { |
| 49 | + default = ".github/workflows/ci.yaml"; |
| 50 | + nightly = ".github/workflows/nightly.yaml"; |
| 51 | + } |
| 52 | + ''; |
49 | 53 | }; |
50 | 54 | }; |
51 | 55 | }; |
|
56 | 60 | type = types.submodule { |
57 | 61 | imports = [ hookModule ]; |
58 | 62 | options.settings = { |
59 | | - pipeline = lib.mkOption { |
60 | | - type = types.str; |
61 | | - description = "The pipeline to generate."; |
62 | | - default = "default"; |
63 | | - example = "pr"; |
64 | | - }; |
65 | | - |
66 | | - outputPath = lib.mkOption { |
67 | | - type = types.str; |
68 | | - description = "The path of the output file generated."; |
69 | | - default = ".gitlab-ci.yml"; |
70 | | - example = ".gitlab/ci.yml"; |
| 63 | + pipelines = lib.mkOption { |
| 64 | + type = types.attrsOf types.str; |
| 65 | + default = { |
| 66 | + default = ".gitlab-ci.yml"; |
| 67 | + }; |
| 68 | + description = "Pipeline name to output path mapping."; |
| 69 | + example = lib.literalExpression '' |
| 70 | + { |
| 71 | + default = ".gitlab-ci.yml"; |
| 72 | + pr = ".gitlab/ci-pr.yml"; |
| 73 | + } |
| 74 | + ''; |
71 | 75 | }; |
72 | 76 | }; |
73 | 77 | }; |
|
79 | 83 | name = "generate-github-actions"; |
80 | 84 | description = "generate GitHub Actions workflow"; |
81 | 85 | package = writePipelineGenerator { |
82 | | - name = "github-actions"; |
83 | | - hook = config.hooks.first-ci-kit-gen-github-actions; |
| 86 | + backend = "github-actions"; |
| 87 | + inherit (config.hooks.first-ci-kit-gen-github-actions.settings) pipelines; |
84 | 88 | }; |
85 | 89 | entry = "${config.hooks.first-ci-kit-gen-github-actions.package}/bin/generate-github-actions"; |
86 | 90 | files = lib.mkDefault "\\.nix$"; |
|
91 | 95 | name = "generate-gitlab-ci"; |
92 | 96 | description = "generate GitLab CI pipeline"; |
93 | 97 | package = writePipelineGenerator { |
94 | | - name = "gitlab-ci"; |
95 | | - hook = config.hooks.first-ci-kit-gen-gitlab-ci; |
| 98 | + backend = "gitlab-ci"; |
| 99 | + inherit (config.hooks.first-ci-kit-gen-gitlab-ci.settings) pipelines; |
96 | 100 | }; |
97 | 101 | entry = "${config.hooks.first-ci-kit-gen-gitlab-ci.package}/bin/generate-gitlab-ci"; |
98 | 102 | files = lib.mkDefault "\\.nix$"; |
|
0 commit comments