1
0
Fork 0
mirror of https://github.com/hercules-ci/flake-parts.git synced 2024-12-15 17:50:53 +00:00

Merge pull request #3 from hercules-ci/memoize

Memoize and make devShell lazy
This commit is contained in:
Robert Hensing 2021-11-22 22:12:21 +01:00 committed by GitHub
commit e72740311d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 17 deletions

View file

@ -2,7 +2,6 @@
let let
inherit (lib) inherit (lib)
filterAttrs filterAttrs
genAttrs
mapAttrs mapAttrs
mkOption mkOption
optionalAttrs optionalAttrs
@ -30,7 +29,7 @@ in
(k: v: v.checks) (k: v: v.checks)
(filterAttrs (filterAttrs
(k: v: v.checks != null) (k: v: v.checks != null)
(genAttrs config.systems config.perSystem) config.allSystems
); );
perInput = system: flake: perInput = system: flake:

View file

@ -2,7 +2,6 @@
let let
inherit (lib) inherit (lib)
filterAttrs filterAttrs
genAttrs
mapAttrs mapAttrs
mkOption mkOption
optionalAttrs optionalAttrs
@ -25,13 +24,7 @@ in
}; };
}; };
config = { config = {
flake.devShell = flake.devShell = mapAttrs (k: v: v.devShell) config.allSystems;
mapAttrs
(k: v: v.devShell)
(filterAttrs
(k: v: v.devShell != null)
(genAttrs config.systems config.perSystem)
);
perInput = system: flake: perInput = system: flake:
optionalAttrs (flake?devShell.${system}) { optionalAttrs (flake?devShell.${system}) {
@ -42,7 +35,8 @@ in
_file = ./devShell.nix; _file = ./devShell.nix;
options = { options = {
devShell = mkOption { 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 = '' description = ''
A derivation that nix develop bases its environment on. A derivation that nix develop bases its environment on.
''; '';

View file

@ -2,7 +2,6 @@
let let
inherit (lib) inherit (lib)
filterAttrs filterAttrs
genAttrs
mapAttrs mapAttrs
mkOption mkOption
optionalAttrs optionalAttrs

View file

@ -2,7 +2,6 @@
let let
inherit (lib) inherit (lib)
filterAttrs filterAttrs
genAttrs
mapAttrs mapAttrs
mkOption mkOption
optionalAttrs optionalAttrs
@ -30,7 +29,7 @@ in
(k: v: v.legacyPackages) (k: v: v.legacyPackages)
(filterAttrs (filterAttrs
(k: v: v.legacyPackages != null) (k: v: v.legacyPackages != null)
(genAttrs config.systems config.perSystem) config.allSystems
); );
perInput = system: flake: perInput = system: flake:

View file

@ -2,7 +2,6 @@
let let
inherit (lib) inherit (lib)
filterAttrs filterAttrs
genAttrs
mapAttrs mapAttrs
mkOption mkOption
optionalAttrs optionalAttrs
@ -31,7 +30,7 @@ in
(k: v: v.packages) (k: v: v.packages)
(filterAttrs (filterAttrs
(k: v: v.packages != null) (k: v: v.packages != null)
(genAttrs config.systems config.perSystem) config.allSystems
); );
perInput = system: flake: perInput = system: flake:

View file

@ -1,6 +1,7 @@
{ config, lib, self, ... }: { config, lib, self, ... }:
let let
inherit (lib) inherit (lib)
genAttrs
mapAttrs mapAttrs
mkOption mkOption
types types
@ -36,7 +37,19 @@ in
shorthandOnlyDefinesConfig = false; 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; };
} }