Skip to content

Commit

Permalink
Allow building multiple systems (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
srid authored Feb 24, 2024
1 parent 222d106 commit bb0e044
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 18 deletions.
30 changes: 23 additions & 7 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 23 additions & 11 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
systems.url = "github:nix-systems/default";
allowed-systems.url = "github:nix-systems/default";
flake-parts.url = "github:hercules-ci/flake-parts";
# The systems to build for. If empty, build for current system.
systems.url = "github:srid/empty";
flake = { };
};
outputs = inputs@{ flake-parts, systems, ... }:
outputs = inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = import systems;
systems = import inputs.allowed-systems;
perSystem = { self', pkgs, lib, system, ... }: {
packages.default =
let
configForCurrentSystem = cfg: cfg.config.nixpkgs.hostPlatform.system == system;
build-systems =
let systems = import inputs.systems;
in if systems == [ ] then [ system ] else systems;
shouldBuildOn = s: lib.elem s build-systems;
configForCurrentSystem = cfg:
shouldBuildOn cfg.config.nixpkgs.hostPlatform.system;
# Given a flake output key, how to get the buildable derivation for
# any of its attr values?
flakeSchema = {
perSystem = {
lookupFlake = k: lib.attrByPath [ k system ] { };
# -> [ path ]
lookupFlake = k: flake:
lib.flip builtins.map build-systems (sys:
lib.attrByPath [ k sys ] { } flake
);
getDrv = {
packages = _: x: [ x ];
checks = _: x: [ x ];
Expand All @@ -30,21 +41,22 @@
};
};
flake = {
lookupFlake = k: lib.attrByPath [ k ] { };
lookupFlake = k: flake: [ (lib.attrByPath [ k ] { } flake) ];
getDrv = {
nixosConfigurations = _: cfg:
lib.optional (configForCurrentSystem cfg) cfg.config.system.build.toplevel;
darwinConfigurations = _: cfg:
darwinConfigurations = _: cfg:
lib.optional (configForCurrentSystem cfg) cfg.config.system.build.toplevel;
};
};
};
paths =
lib.flip lib.mapAttrsToList flakeSchema (lvl: lvlSchema:
lib.flip lib.mapAttrsToList flakeSchema (_: lvlSchema:
lib.flip lib.mapAttrsToList lvlSchema.getDrv (kind: getDrv:
lib.mapAttrsToList
getDrv
(lvlSchema.lookupFlake kind inputs.flake))
builtins.concatMap
(attr: lib.mapAttrsToList getDrv attr)
(lvlSchema.lookupFlake kind inputs.flake)
)
);
in
pkgs.writeText "devour-output" (lib.strings.concatLines (lib.lists.flatten paths));
Expand Down

0 comments on commit bb0e044

Please sign in to comment.