Skip to content

Commit

Permalink
nix: Divide top-level into multiple files
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Spinale <[email protected]>
  • Loading branch information
nspin committed Nov 13, 2024
1 parent ce11f98 commit f6b4f12
Show file tree
Hide file tree
Showing 3 changed files with 216 additions and 191 deletions.
156 changes: 156 additions & 0 deletions hacking/nix/top-level/aggregating.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
#
# Copyright 2024, Colias Group, LLC
#
# SPDX-License-Identifier: BSD-2-Clause
#

self: with self;

let

aggregate = name: drvs: pkgs.build.writeText "aggregate-${name}" (toString (lib.flatten drvs));

in {

worldsForEverythingInstances = [
pkgs.host.aarch64.none.this.worlds.default
pkgs.host.aarch64.none.this.worlds.qemu-arm-virt.microkit
pkgs.host.aarch32.none.this.worlds.default
pkgs.host.riscv64.default.none.this.worlds.default
pkgs.host.riscv64.default.none.this.worlds.qemu-riscv-virt.microkit
pkgs.host.riscv32.default.none.this.worlds.default
pkgs.host.x86_64.none.this.worlds.default
];

someConfigurationBuildTests =
let
worlds = pkgs.host.aarch64.none.this.worlds.qemu-arm-virt.forBuildTests;
in
lib.forEach (lib.attrValues worlds) (world: [
world.sel4-capdl-initializer
] ++ lib.optionals world.worldConfig.isMicrokit [
world.instances.microkit.tests.passive-server-with-deferred-action.links
]);

sel4testInstances = (lib.mapAttrs (k: v: v.this.sel4test.automate) {
aarch64 = pkgs.host.aarch64.none;
aarch32 = pkgs.host.aarch32.none;
riscv64 = pkgs.host.riscv64.default.none;
riscv32 = pkgs.host.riscv32.default.none;
# TODO figure out why none doesn't build
x86_64 = pkgs.host.x86_64.linux;
ia32 = pkgs.host.ia32.linux; # no rust support yet
});

sel4testInstancesList = lib.attrValues sel4testInstances;

prerequisites = aggregate "prerequisites" [
pkgs.build.this.qemuForSeL4
pkgs.build.this.capdl-tool
(builtins.toJSON (pkgs.build.this.vendoredTopLevelLockfile.configFragment))

(lib.forEach (with pkgs.host; [ aarch64 aarch32 ]) (arch:
arch.none.this.platUtils.rpi4.defaultBootLinks
))
];

incremental = aggregate "incremental" [
(lib.forEach worldsForEverythingInstances (world:
map (instance: instance.links) world.instances.all
))

pkgs.build.this.someUnitTests

someConfigurationBuildTests

sel4testInstancesList

(lib.optionals pkgs.build.hostPlatform.isx86_64 [
pkgs.build.this.kani
pkgs.build.this.verus
])

pkgs.host.aarch32.none.this.worlds.default.seL4
pkgs.host.ia32.none.this.worlds.default.seL4

pkgs.host.riscv64.imac.none.stdenv
pkgs.host.riscv64.gc.none.stdenv
pkgs.host.riscv32.imac.none.stdenv
pkgs.host.riscv32.imafc.none.stdenv

example
example-rpi4-b-4gb
];

nonIncremental = aggregate "non-incremental" [
html
];

excess = aggregate "excess" [
];

everythingExceptNonIncremental = aggregate "everything-except-non-incremental" [
prerequisites
incremental
];

everything = aggregate "everything" [
everythingExceptNonIncremental
nonIncremental
];

everythingWithExcess = aggregate "everything-with-excess" [
everything
excess
];

fastTests =
lib.forEach worldsForEverythingInstances
(world: world.instances.allAutomationScripts);

slowTests = sel4testInstancesList;

runFastTests = mkRunTests (lib.flatten [
fastTests
]);

witnessFastTests = mkWitnessTests (lib.flatten [
fastTests
]);

runTests = mkRunTests (lib.flatten [
fastTests
slowTests
]);

witnessTests = mkWitnessTests (lib.flatten [
fastTests
slowTests
]);

mkRunTests = scripts:
with pkgs.build;
writeScript "run-tests" ''
#!${runtimeShell}
set -eu
${lib.concatStrings (lib.forEach scripts (script: ''
echo "<<< running test: ${script.testMeta.name or "unnamed"} >>>"
${script}
''))}
echo
echo '# All tests passed.'
echo
'';

mkWitnessTest = script:
pkgs.build.runCommand "witness-${script.testMeta.name or "unnamed"}" {} ''
${script}
touch $out
'';

mkWitnessTests = scripts:
pkgs.build.writeText "witness-tests" (lib.concatStrings (map mkWitnessTest scripts));

}
194 changes: 3 additions & 191 deletions hacking/nix/top-level/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,200 +6,12 @@

self: with self;

let

aggregate = name: drvs: pkgs.build.writeText "aggregate-${name}" (toString (lib.flatten drvs));

in {
overrideNixpkgsArgs = f: self.override (superArgs: selfBase:
let
concreteSuperArgs = superArgs selfBase;
in
concreteSuperArgs // {
nixpkgsArgsFor = crossSystem: f (concreteSuperArgs.nixpkgsArgsFor crossSystem);
}
);

withOverlays = overlays: self.overrideNixpkgsArgs (superNixpkgsArgs:
superNixpkgsArgs // {
overlays = superNixpkgsArgs.overlays ++ overlays;
}
);

withConfigOverride = f: self.withOverlays [
(self': super': {
this = super'.this.overrideScope (self'': super'': {
overridableScopeConfig = f super''.overridableScopeConfig;
});
})
];

withClippy = self.withConfigOverride (attrs: attrs // {
runClippyDefault = true;
});

withFerrocene = self.withConfigOverride (attrs: attrs // {
rustEnvironmentSelector = (attrs.rustEnvironmentSelector or {}) // {
tracks = "ferrocene";
upstream = false;
};
});

withVerus = self.withConfigOverride (attrs: attrs // {
rustEnvironmentSelector = (attrs.rustEnvironmentSelector or {}) // {
tracks = "verus";
};
});

withUpstream = self.withConfigOverride (attrs: attrs // {
rustEnvironmentSelector = (attrs.rustEnvironmentSelector or {}) // {
upstream = true;
};
});
import ./overriding.nix self //
import ./aggregating.nix self //
{

inherit (pkgs.build.this) shellForMakefile shellForHacking;

worldsForEverythingInstances = [
pkgs.host.aarch64.none.this.worlds.default
pkgs.host.aarch64.none.this.worlds.qemu-arm-virt.microkit
pkgs.host.aarch32.none.this.worlds.default
pkgs.host.riscv64.default.none.this.worlds.default
pkgs.host.riscv64.default.none.this.worlds.qemu-riscv-virt.microkit
pkgs.host.riscv32.default.none.this.worlds.default
pkgs.host.x86_64.none.this.worlds.default
];

someConfigurationBuildTests =
let
worlds = pkgs.host.aarch64.none.this.worlds.qemu-arm-virt.forBuildTests;
in
lib.forEach (lib.attrValues worlds) (world: [
world.sel4-capdl-initializer
] ++ lib.optionals world.worldConfig.isMicrokit [
world.instances.microkit.tests.passive-server-with-deferred-action.links
]);

sel4testInstances = (lib.mapAttrs (k: v: v.this.sel4test.automate) {
aarch64 = pkgs.host.aarch64.none;
aarch32 = pkgs.host.aarch32.none;
riscv64 = pkgs.host.riscv64.default.none;
riscv32 = pkgs.host.riscv32.default.none;
# TODO figure out why none doesn't build
x86_64 = pkgs.host.x86_64.linux;
ia32 = pkgs.host.ia32.linux; # no rust support yet
});

sel4testInstancesList = lib.attrValues sel4testInstances;

prerequisites = aggregate "prerequisites" [
pkgs.build.this.qemuForSeL4
pkgs.build.this.capdl-tool
(builtins.toJSON (pkgs.build.this.vendoredTopLevelLockfile.configFragment))

(lib.forEach (with pkgs.host; [ aarch64 aarch32 ]) (arch:
arch.none.this.platUtils.rpi4.defaultBootLinks
))
];

incremental = aggregate "incremental" [
(lib.forEach worldsForEverythingInstances (world:
map (instance: instance.links) world.instances.all
))

pkgs.build.this.someUnitTests

someConfigurationBuildTests

sel4testInstancesList

(lib.optionals pkgs.build.hostPlatform.isx86_64 [
pkgs.build.this.kani
pkgs.build.this.verus
])

pkgs.host.aarch32.none.this.worlds.default.seL4
pkgs.host.ia32.none.this.worlds.default.seL4

pkgs.host.riscv64.imac.none.stdenv
pkgs.host.riscv64.gc.none.stdenv
pkgs.host.riscv32.imac.none.stdenv
pkgs.host.riscv32.imafc.none.stdenv

example
example-rpi4-b-4gb
];

nonIncremental = aggregate "non-incremental" [
html
];

excess = aggregate "excess" [
];

everythingExceptNonIncremental = aggregate "everything-except-non-incremental" [
prerequisites
incremental
];

everything = aggregate "everything" [
everythingExceptNonIncremental
nonIncremental
];

everythingWithExcess = aggregate "everything-with-excess" [
everything
excess
];

fastTests =
lib.forEach worldsForEverythingInstances
(world: world.instances.allAutomationScripts);

slowTests = sel4testInstancesList;

runFastTests = mkRunTests (lib.flatten [
fastTests
]);

witnessFastTests = mkWitnessTests (lib.flatten [
fastTests
]);

runTests = mkRunTests (lib.flatten [
fastTests
slowTests
]);

witnessTests = mkWitnessTests (lib.flatten [
fastTests
slowTests
]);

mkRunTests = scripts:
with pkgs.build;
writeScript "run-tests" ''
#!${runtimeShell}
set -eu
${lib.concatStrings (lib.forEach scripts (script: ''
echo "<<< running test: ${script.testMeta.name or "unnamed"} >>>"
${script}
''))}
echo
echo '# All tests passed.'
echo
'';

mkWitnessTest = script:
pkgs.build.runCommand "witness-${script.testMeta.name or "unnamed"}" {} ''
${script}
touch $out
'';

mkWitnessTests = scripts:
pkgs.build.writeText "witness-tests" (lib.concatStrings (map mkWitnessTest scripts));

docs = import ./docs {
inherit lib pkgs;
};
Expand Down
Loading

0 comments on commit f6b4f12

Please sign in to comment.