diff --git a/flake.lock b/flake.lock index 7b2a1b9..ed82162 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,20 @@ { "nodes": { + "allowed-systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, "flake-parts": { "inputs": { "nixpkgs-lib": "nixpkgs-lib" @@ -54,6 +69,7 @@ }, "root": { "inputs": { + "allowed-systems": "allowed-systems", "flake-parts": "flake-parts", "nixpkgs": "nixpkgs", "systems": "systems" @@ -61,16 +77,16 @@ }, "systems": { "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "lastModified": 1708697125, + "narHash": "sha256-JeMK8G1oabQTSpqXhYaYtPRak4m6z1xxyRKf8CvHy14=", + "owner": "srid", + "repo": "empty", + "rev": "23d743284b73ae69caf0cb7874edf05c0c631a1f", "type": "github" }, "original": { - "owner": "nix-systems", - "repo": "default", + "owner": "srid", + "repo": "empty", "type": "github" } } diff --git a/flake.nix b/flake.nix index 855ba91..a5a33d8 100644 --- a/flake.nix +++ b/flake.nix @@ -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 ]; @@ -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));