Skip to content

Commit 01b1942

Browse files
committed
Introduce genCrossPlatformNixActions command.
This command generates GitHub workflows on Ubuntu and macOS.
1 parent fac8fcc commit 01b1942

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

.nix/shellHook.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,17 @@ genNixActions (){
179179
}
180180
addNixCommand genNixActions
181181

182+
genCrossPlatformNixActions (){
183+
mkdir -p $currentDir/.github/workflows/
184+
for t in $bundles; do
185+
for p in "ubuntu" "macos"; do
186+
echo "generating $currentDir/.github/workflows/nix-action-$t-$p.yml"
187+
nix-shell --arg do-nothing true --argstr bundle $t --argstr ci-platform "$p-latest" --run "ppNixAction > $currentDir/.github/workflows/nix-action-$t-$p.yml"
188+
done
189+
done
190+
}
191+
addNixCommand genCrossPlatformNixActions
192+
182193
initNixConfig (){
183194
Orig=$toolboxDir/template-config.nix
184195
F=$configDir/config.nix;

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,15 @@ When you run `nix-shell`, you get an environment with a few available commands:
9393
- `fetchCoqOverlay`: fetch a derivation file from nixpkgs that you may then edit locally to override a package.
9494
- `createOverlay`: create a fresh derivation file from a template, which could then be added to nixpkgs.
9595
- `cachedMake`: compile the project by reusing build outputs cached (generally thanks to Cachix).
96-
- `genNixActions`: generates GitHub one actions file per bundle, for testing dependencies and reverse depndencies.
96+
- `genNixActions`: generates GitHub one actions file per bundle, for testing dependencies and reverse dependencies.
97+
- `genCrossPlatformNixActions`: duplicate generated workflows to run on both Ubuntu and macOS (useful when macOS users want to get cached artifacts as well).
9798

9899
These three commands update the nixpkgs version to use (will create or override `.nix/nixpkgs.nix`):
99100
- `updateNixpkgsUnstable`: update to the latest nixpkgs-unstable.
100101
- `updateNixpkgsMaster`: update to the head of `master` of nixpkgs.
101102
- `updateNixpkgs`: update to the specified owner and ref.
102103

103-
After one of these three commands, you should leave and re-enter `nix-shell` if you want the update to be taken into account (e.g., before calling `genNixActions`).
104+
After one of these three commands, you should leave and re-enter `nix-shell` if you want the update to be taken into account.
104105

105106
## Arguments accepted by `nix-shell`
106107

@@ -117,7 +118,7 @@ To test a PR on nixpkgs that modifies the `coqPackages` set, clone this reposito
117118

118119
```
119120
nix-shell --arg do-nothing true --run "updateNixpkgs <pr_owner> <pr_branch>"
120-
nix-shell --arg do-nothing true --run "genNixActions"
121+
nix-shell --arg do-nothing true --run "genCrossPlatformNixActions"
121122
```
122123

123124
Then, open a draft PR with the generated changes here.
@@ -126,5 +127,5 @@ Once the PR on nixpkgs has been merged, you can transform the draft PR into one
126127

127128
```
128129
nix-shell --arg do-nothing true --run "updateNixpkgsMaster"
129-
nix-shell --arg do-nothing true --run "genNixActions"
130+
nix-shell --arg do-nothing true --run "genCrossPlatformNixActions"
130131
```

action.nix

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ with builtins; with lib; let
7878
run = "NIXPKGS_ALLOW_UNFREE=1 nix-build --no-out-link --argstr bundle \"${bundlestr}\" --argstr job \"${job}\"";
7979
};
8080

81-
mkJob = { job, jobs ? [], bundles ? [], deps ? {}, cachix ? {}, suffix ? false }:
81+
mkJob = { job, jobs ? [], bundles ? [], deps ? {}, cachix ? {}, ci-platform, suffix ? false }:
8282
let
8383
suffixStr = optionalString (suffix && isString bundles) "-${bundles}";
8484
jdeps = deps.${job} or [];
8585
in {
8686
"${job}${suffixStr}" = rec {
87-
runs-on = "ubuntu-latest";
87+
runs-on = if ci-platform == null then "ubuntu-latest" else ci-platform;
8888
needs = map (j: "${j}${suffixStr}") (filter (j: elem j jobs) jdeps);
8989
steps = [ stepCommitToTest stepCheckout stepCachixInstall ]
9090
++ (stepCachixUseAll cachix)
@@ -94,11 +94,11 @@ with builtins; with lib; let
9494
} // (optionalAttrs (isList bundles) {strategy.matrix.bundle = bundles;});
9595
};
9696

97-
mkJobs = { jobs ? [], bundles ? [], deps ? {}, cachix ? {}, suffix ? false }@args:
97+
mkJobs = { jobs ? [], bundles ? [], deps ? {}, cachix ? {}, ci-platform, suffix ? false }@args:
9898
foldl (action: job: action // (mkJob ({ inherit job; } // args))) {} jobs;
9999

100-
mkActionFromJobs = { actionJobs, bundles ? [] }: {
101-
name = "Nix CI for bundle ${toString bundles}";
100+
mkActionFromJobs = { actionJobs, bundles ? [], ci-platform }: {
101+
name = "Nix CI for bundle ${toString bundles}${if ci-platform == null then "" else " on platform ${ci-platform}"}";
102102
on = {
103103
push.branches = [ "master" ];
104104
pull_request.paths = [ ".github/workflows/**" ];
@@ -107,7 +107,7 @@ with builtins; with lib; let
107107
jobs = actionJobs;
108108
};
109109

110-
mkAction = { jobs ? [], bundles ? [], deps ? {}, cachix ? {} }@args:
111-
mkActionFromJobs {inherit bundles; actionJobs = mkJobs args; };
110+
mkAction = { jobs ? [], bundles ? [], deps ? {}, cachix ? {}, ci-platform ? null }@args:
111+
mkActionFromJobs {inherit bundles ci-platform; actionJobs = mkJobs args; };
112112

113113
in { inherit mkJob mkJobs mkAction; }

config-parser-1.0.0/default.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ with builtins;
1111
override ? {},
1212
ocaml-override ? {},
1313
global-override ? {},
14+
ci-platform,
1415
lib,
1516
}@initial:
1617
with lib;
@@ -59,6 +60,7 @@ in with config; let
5960
inherit (import ../action.nix { inherit lib; }) mkJobs mkAction;
6061
action = mkAction {
6162
inherit (config) cachix;
63+
inherit ci-platform;
6264
bundles = bundleName;
6365
jobs = let
6466
jdeps = genAttrs ci.mains (n: genCI.pkgsRevDepsSet.${n} or {});

default.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ in
1717
coq-overlays-dir ? get-path src "coq-overlays",
1818
ocaml-overlays-dir ? get-path src "ocaml-overlays",
1919
ci-matrix ? false,
20+
ci-platform ? null,
2021
config ? {},
2122
override ? {},
2223
ocaml-override ? {},
@@ -44,6 +45,7 @@ let
4445
// { diag = f: x: f x x; };
4546
inherit overlays-dir coq-overlays-dir ocaml-overlays-dir;
4647
inherit global-override override ocaml-override;
48+
inherit ci-platform;
4749
};
4850
my-throw = x: throw "Coq nix toolbox error: ${x}";
4951
in

0 commit comments

Comments
 (0)