diff --git a/modules/checks.nix b/modules/checks.nix index f20bd56..39f653a 100644 --- a/modules/checks.nix +++ b/modules/checks.nix @@ -2,7 +2,6 @@ let inherit (lib) filterAttrs - genAttrs mapAttrs mkOption optionalAttrs @@ -30,7 +29,7 @@ in (k: v: v.checks) (filterAttrs (k: v: v.checks != null) - (genAttrs config.systems config.perSystem) + config.allSystems ); perInput = system: flake: diff --git a/modules/devShell.nix b/modules/devShell.nix index 27534db..4f347c3 100644 --- a/modules/devShell.nix +++ b/modules/devShell.nix @@ -2,7 +2,6 @@ let inherit (lib) filterAttrs - genAttrs mapAttrs mkOption optionalAttrs @@ -25,13 +24,7 @@ in }; }; config = { - flake.devShell = - mapAttrs - (k: v: v.devShell) - (filterAttrs - (k: v: v.devShell != null) - (genAttrs config.systems config.perSystem) - ); + flake.devShell = mapAttrs (k: v: v.devShell) config.allSystems; perInput = system: flake: optionalAttrs (flake?devShell.${system}) { @@ -42,7 +35,8 @@ in _file = ./devShell.nix; options = { devShell = mkOption { - type = types.nullOr types.package; + type = types.package; + default = throw "The default devShell was not configured for system ${system}. Please set it, or if you don't want to use the devShell attribute, set flake.devShell = lib.mkForce {};"; description = '' A derivation that nix develop bases its environment on. ''; diff --git a/modules/flake.nix b/modules/flake.nix index 7202bee..2fe871c 100644 --- a/modules/flake.nix +++ b/modules/flake.nix @@ -2,7 +2,6 @@ let inherit (lib) filterAttrs - genAttrs mapAttrs mkOption optionalAttrs diff --git a/modules/legacyPackages.nix b/modules/legacyPackages.nix index 492984d..1c66b31 100644 --- a/modules/legacyPackages.nix +++ b/modules/legacyPackages.nix @@ -2,7 +2,6 @@ let inherit (lib) filterAttrs - genAttrs mapAttrs mkOption optionalAttrs @@ -30,7 +29,7 @@ in (k: v: v.legacyPackages) (filterAttrs (k: v: v.legacyPackages != null) - (genAttrs config.systems config.perSystem) + config.allSystems ); perInput = system: flake: diff --git a/modules/packages.nix b/modules/packages.nix index 3829800..d3352fb 100644 --- a/modules/packages.nix +++ b/modules/packages.nix @@ -2,7 +2,6 @@ let inherit (lib) filterAttrs - genAttrs mapAttrs mkOption optionalAttrs @@ -31,7 +30,7 @@ in (k: v: v.packages) (filterAttrs (k: v: v.packages != null) - (genAttrs config.systems config.perSystem) + config.allSystems ); perInput = system: flake: diff --git a/modules/perSystem.nix b/modules/perSystem.nix index 5fcf86e..5632b9b 100644 --- a/modules/perSystem.nix +++ b/modules/perSystem.nix @@ -1,6 +1,7 @@ { config, lib, self, ... }: let inherit (lib) + genAttrs mapAttrs mkOption types @@ -36,7 +37,19 @@ in shorthandOnlyDefinesConfig = false; }); }; + + allSystems = mkOption { + type = types.lazyAttrsOf types.unspecified; + description = "The system-specific config for each of systems."; + internal = true; + }; + }; + + config = { + perSystem = system: { _module.args.system = system; }; + allSystems = genAttrs config.systems config.perSystem; + # TODO: Sub-optimal error message. Get Nix to support a memoization primop, or get Nix Flakes to support systems properly or get Nix Flakes to add a name to flakes. + _module.args.getSystem = system: config.allSystems.${system} or builtins.trace "using non-memoized system ${system}" config.perSystem system; }; - config.perSystem = system: { _module.args.system = system; }; }