Skip to content

Commit 66d56a9

Browse files
committed
flake.nix: build all packages though a single evaluation
1 parent 6dd6f2c commit 66d56a9

File tree

7 files changed

+94
-5
lines changed

7 files changed

+94
-5
lines changed

.github/workflows/nix_build.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: build and cache all flake outputs
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "**"
7+
- "!.github/**"
8+
- ".github/actions/setup_nix.yml"
9+
- ".github/workflows/nix_build.yml"
10+
- "!dev-docs/**"
11+
- "!docs/**"
12+
- "!rfc/**"
13+
- "!tools/vale/**"
14+
workflow_dispatch:
15+
16+
jobs:
17+
checks:
18+
runs-on: ${{ matrix.runner }}
19+
permissions:
20+
contents: read
21+
strategy:
22+
matrix:
23+
include:
24+
- runner: yet-to-be-set-up-nix-build-host
25+
system: x86_64-linux
26+
steps:
27+
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
28+
with:
29+
persist-credentials: false
30+
- uses: ./.github/actions/setup_nix
31+
if: (!inputs.self-hosted)
32+
with:
33+
githubToken: ${{ secrets.GITHUB_TOKEN_IN || secrets.GITHUB_TOKEN }}
34+
cachixToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
35+
- name: pre-build all flake outputs
36+
run: |
37+
nix build .#matrix.${{ matrix.system }}

flake.nix

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@
3636
overlays = [
3737
(final: _prev: { fenix = self.inputs.fenix.packages.${final.stdenv.hostPlatform.system}; })
3838
(import ./overlays/nixpkgs.nix)
39-
(import ./overlays/contrast.nix)
39+
(import ./overlays/contrast.nix { inherit (self) inputs; })
4040
];
4141
config.allowUnfree = true;
4242
config.nvidia.acceptLicense = true;
4343
};
4444
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
45+
inherit (pkgs) lib;
4546
in
4647

4748
{
@@ -57,6 +58,8 @@
5758
"contrastPkgs"
5859
];
5960
};
61+
62+
matrix = pkgs.writeText "output-matrix.json" (builtins.toJSON (lib.ci.allOutputs self system));
6063
}
6164
);
6265

lib/ci.nix

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{ lib, ... }:
2+
rec {
3+
fromPackageOutputs =
4+
flake: system:
5+
lib.concatMap (kind: lib.attrValues (lib.attrByPath [ kind system ] { } flake)) [
6+
"legacyPackages"
7+
"packages"
8+
"checks"
9+
"devShells"
10+
"formatters"
11+
];
12+
13+
allOutputs =
14+
flake: system:
15+
lib.filter lib.isDerivation (
16+
lib.unique (
17+
lib.concatMap (from: from flake system) [
18+
fromPackageOutputs
19+
]
20+
)
21+
);
22+
}

lib/default.nix

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{ inputs }:
2+
3+
let
4+
mkLib =
5+
nixpkgs:
6+
nixpkgs.lib.extend (
7+
self: _: {
8+
ci = import ./ci.nix { lib = self; };
9+
}
10+
);
11+
in
12+
mkLib inputs.nixpkgs

overlays/contrast.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Copyright 2024 Edgeless Systems GmbH
22
# SPDX-License-Identifier: BUSL-1.1
33

4+
{ inputs }:
5+
46
final: _prev:
57

68
{
79
contrastPkgs = import ../packages { pkgs = final; };
10+
lib = import ../lib { inherit inputs; };
811
}

packages/contrast-releases.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
{
22
"contrast": [
3-
{
4-
"version": "v0.2.0",
5-
"hash": "sha256-cGyWvUmL/rbjX3Bu1OPGTZlk5PgVW/O0qdo9KmZPo+U="
6-
},
73
{
84
"version": "v0.3.0",
95
"hash": "sha256-8yVZLhwf2bsWIMxSAqXUKDNCjltCSGA6bwrXTi+cJB0="

packages/static.nix

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2025 Edgeless Systems GmbH
2+
# SPDX-License-Identifier: BUSL-1.1
3+
4+
{ pkgs }:
5+
6+
let
7+
inherit (pkgs.lib) makeScope;
8+
in
9+
10+
makeScope pkgs.pkgsStatic.newScope (
11+
self:
12+
pkgs.lib.packagesFromDirectoryRecursive {
13+
inherit (self) callPackage newScope;
14+
directory = ./by-name;
15+
}
16+
)

0 commit comments

Comments
 (0)