mirror of
https://github.com/hercules-ci/flake-parts.git
synced 2024-12-14 11:47:31 +00:00
perSystem: functionTo -> deferredModule
This commit is contained in:
parent
d5370c0774
commit
3ee82a16d6
9 changed files with 58 additions and 17 deletions
|
@ -6,7 +6,7 @@
|
|||
../site/flake-module.nix
|
||||
];
|
||||
systems = [ "x86_64-linux" "aarch64-darwin" ];
|
||||
perSystem = system: { config, self', inputs', pkgs, ... }: {
|
||||
perSystem = { config, self', inputs', pkgs, ... }: {
|
||||
|
||||
devShells.default = pkgs.mkShell {
|
||||
nativeBuildInputs = [
|
||||
|
|
|
@ -20,11 +20,11 @@
|
|||
"nixpkgs": "nixpkgs"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1653415319,
|
||||
"narHash": "sha256-h+YUX7ZYujf73KL1R07LsEnhV7uV8oxSKEhH4bDj0Jc=",
|
||||
"lastModified": 1653487348,
|
||||
"narHash": "sha256-lWqxXMRqO8blpwhH2qvrFBVp6aZ7V+Z3xTqkNWKyLQw=",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "hercules-ci-effects",
|
||||
"rev": "1f904af1824e7393702daaf40a8fed56ebead0d7",
|
||||
"rev": "0ab66b56d3f2b40ddfd981899d1757773632075f",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -73,11 +73,11 @@
|
|||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1638351750,
|
||||
"narHash": "sha256-90OHC+11DIHD1QyMIPUuM3n6zjH5Mhc8RBZa0h8969A=",
|
||||
"lastModified": 1653494825,
|
||||
"narHash": "sha256-hMhnHZGRlJBX3yWIvxuYIBo4g+XQy/DJ4z7ti0IX7x0=",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "pre-commit-hooks.nix",
|
||||
"rev": "3bb289628867ac40fc9e7c514f8266b1ce8c0910",
|
||||
"rev": "89b64b7aca69fbd2957232d6a5a36bb93ad59d4b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
42
lib.nix
42
lib.nix
|
@ -2,8 +2,17 @@
|
|||
let
|
||||
inherit (lib)
|
||||
mkOption
|
||||
mkOptionType
|
||||
defaultFunctor
|
||||
isAttrs
|
||||
isFunction
|
||||
showOption
|
||||
types
|
||||
;
|
||||
inherit (lib.types)
|
||||
path
|
||||
submoduleWith
|
||||
;
|
||||
|
||||
# Polyfill functionTo to make sure it has type merging.
|
||||
# Remove 2022-12
|
||||
|
@ -26,6 +35,32 @@ let
|
|||
nestedTypes.elemType = elemType;
|
||||
};
|
||||
|
||||
# Polyfill https://github.com/NixOS/nixpkgs/pull/163617
|
||||
deferredModuleWith = lib.deferredModuleWith or (
|
||||
attrs@{ staticModules ? [ ] }: mkOptionType {
|
||||
name = "deferredModule";
|
||||
description = "module";
|
||||
check = x: isAttrs x || isFunction x || path.check x;
|
||||
merge = loc: defs: staticModules ++ map (def: lib.setDefaultModuleLocation "${def.file}, via option ${showOption loc}" def.value) defs;
|
||||
inherit (submoduleWith { modules = staticModules; })
|
||||
getSubOptions
|
||||
getSubModules;
|
||||
substSubModules = m: deferredModuleWith (attrs // {
|
||||
staticModules = m;
|
||||
});
|
||||
functor = defaultFunctor "deferredModuleWith" // {
|
||||
type = deferredModuleWith;
|
||||
payload = {
|
||||
inherit staticModules;
|
||||
};
|
||||
binOp = lhs: rhs: {
|
||||
staticModules = lhs.staticModules ++ rhs.staticModules;
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
flake-parts-lib = {
|
||||
evalFlakeModule =
|
||||
{ self
|
||||
|
@ -53,10 +88,9 @@ let
|
|||
|
||||
mkPerSystemType =
|
||||
module:
|
||||
functionTo (types.submoduleWith {
|
||||
modules = [ module ];
|
||||
shorthandOnlyDefinesConfig = false;
|
||||
});
|
||||
deferredModuleWith {
|
||||
staticModules = [ module ];
|
||||
};
|
||||
|
||||
mkPerSystemOption =
|
||||
module:
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#
|
||||
{
|
||||
config = {
|
||||
perSystem = _: { inputs', lib, ... }: {
|
||||
perSystem = { inputs', lib, ... }: {
|
||||
config = {
|
||||
_module.args.pkgs = lib.mkOptionDefault (
|
||||
builtins.seq
|
||||
|
|
|
@ -34,6 +34,14 @@ in
|
|||
_module.args.self' = rootConfig.perInput system self;
|
||||
};
|
||||
});
|
||||
apply = modules: system:
|
||||
(lib.evalModules {
|
||||
inherit modules;
|
||||
prefix = [ "perSystem" system ];
|
||||
specialArgs = {
|
||||
inherit system;
|
||||
};
|
||||
}).config;
|
||||
};
|
||||
|
||||
allSystems = mkOption {
|
||||
|
@ -44,7 +52,6 @@ in
|
|||
};
|
||||
|
||||
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);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{ ... }: {
|
||||
perSystem = system: { config, self', inputs', pkgs, lib, ... }:
|
||||
perSystem = { config, self', inputs', pkgs, lib, ... }:
|
||||
let
|
||||
inherit (lib) filter any hasPrefix concatMap removePrefix;
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
];
|
||||
systems = [ "x86_64-linux" "aarch64-darwin" ];
|
||||
perSystem = system: { config, self', inputs', pkgs, ... }: {
|
||||
perSystem = { config, self', inputs', pkgs, system, ... }: {
|
||||
# Per-system attributes can be defined here. The self' and inputs'
|
||||
# module parameters provide easy access to attributes of the same
|
||||
# system.
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
./hello/flake-module.nix
|
||||
];
|
||||
systems = [ "x86_64-linux" "aarch64-darwin" ];
|
||||
perSystem = system: { config, self', inputs', ... }: {
|
||||
perSystem = { config, self', inputs', ... }: {
|
||||
# Per-system attributes can be defined here. The self' and inputs'
|
||||
# module parameters provide easy access to attributes of the same
|
||||
# system.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Definitions can be imported from a separate file like this one
|
||||
|
||||
{ self, ... }: {
|
||||
perSystem = system: { config, self', inputs', pkgs, ... }: {
|
||||
perSystem = { config, self', inputs', pkgs, ... }: {
|
||||
# Definitions like this are entirely equivalent to the ones
|
||||
# you may have directly in flake.nix.
|
||||
packages.hello = pkgs.hello;
|
||||
|
|
Loading…
Reference in a new issue