mirror of
https://github.com/numtide/flake-utils.git
synced 2024-12-15 17:50:53 +00:00
Merge pull request #119 from trueNAHO/lib-each-default-system-pass-through-each-system-pass-through-init
This commit is contained in:
commit
c1dfcf0841
2 changed files with 66 additions and 27 deletions
25
README.md
25
README.md
|
@ -22,7 +22,7 @@ system = {
|
||||||
```
|
```
|
||||||
It's mainly useful to
|
It's mainly useful to
|
||||||
detect typos and auto-complete if you use [rnix-lsp](https://github.com/nix-community/rnix-lsp).
|
detect typos and auto-complete if you use [rnix-lsp](https://github.com/nix-community/rnix-lsp).
|
||||||
|
|
||||||
Eg: instead of typing `"x86_64-linux"`, use `system.x86_64-linux`.
|
Eg: instead of typing `"x86_64-linux"`, use `system.x86_64-linux`.
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,6 +83,11 @@ eachSystem allSystems (system: { hello = 42; })
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### `eachSystemPassThrough :: [<system>] -> (<system> -> attrs)`
|
||||||
|
|
||||||
|
Unlike `eachSystem`, this function does not inject the `${system}` key by merely
|
||||||
|
providing the system argument to the function.
|
||||||
|
|
||||||
### `eachDefaultSystem :: (<system> -> attrs)`
|
### `eachDefaultSystem :: (<system> -> attrs)`
|
||||||
|
|
||||||
`eachSystem` pre-populated with `defaultSystems`.
|
`eachSystem` pre-populated with `defaultSystems`.
|
||||||
|
@ -113,6 +118,24 @@ eachSystem allSystems (system: { hello = 42; })
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### `eachDefaultSystemPassThrough :: (<system> -> attrs)`
|
||||||
|
|
||||||
|
`eachSystemPassThrough` pre-populated with `defaultSystems`.
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
|
||||||
|
```nix
|
||||||
|
inputs.flake-utils.lib.eachDefaultSystem (system: {
|
||||||
|
checks./*<SYSTEM>.*/"<CHECK>" = /* ... */;
|
||||||
|
devShells./*<SYSTEM>.*/"<DEV_SHELL>" = /* ... */;
|
||||||
|
packages./*<SYSTEM>.*/"<PACKAGE>" = /* ... */;
|
||||||
|
})
|
||||||
|
// inputs.flake-utils.lib.eachDefaultSystemPassThrough (system: {
|
||||||
|
homeConfigurations."<HOME_CONFIGURATION>" = /* ... */;
|
||||||
|
nixosConfigurations."<NIXOS_CONFIGURATION>" = /* ... */;
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
### `meld :: attrs -> [ path ] -> attrs`
|
### `meld :: attrs -> [ path ] -> attrs`
|
||||||
|
|
||||||
Meld merges subflakes using common inputs. Useful when you want to
|
Meld merges subflakes using common inputs. Useful when you want to
|
||||||
|
|
68
lib.nix
68
lib.nix
|
@ -26,33 +26,47 @@ let
|
||||||
# eachSystem using defaultSystems
|
# eachSystem using defaultSystems
|
||||||
eachDefaultSystem = eachSystem defaultSystems;
|
eachDefaultSystem = eachSystem defaultSystems;
|
||||||
|
|
||||||
# Builds a map from <attr>=value to <attr>.<system>=value for each system
|
# eachSystemPassThrough using defaultSystems
|
||||||
#
|
eachDefaultSystemPassThrough = eachSystemPassThrough defaultSystems;
|
||||||
eachSystem = systems: f:
|
|
||||||
|
# Builds a map from <attr>=value to <attr>.<system>=value for each system.
|
||||||
|
eachSystem = eachSystemOp (
|
||||||
|
# Merge outputs for each system.
|
||||||
|
f: attrs: system:
|
||||||
let
|
let
|
||||||
# Merge together the outputs for all systems.
|
ret = f system;
|
||||||
op = attrs: system:
|
|
||||||
let
|
|
||||||
ret = f system;
|
|
||||||
op = attrs: key: attrs //
|
|
||||||
{
|
|
||||||
${key} = (attrs.${key} or { })
|
|
||||||
// { ${system} = ret.${key}; };
|
|
||||||
}
|
|
||||||
;
|
|
||||||
in
|
|
||||||
builtins.foldl' op attrs (builtins.attrNames ret);
|
|
||||||
in
|
in
|
||||||
builtins.foldl' op { }
|
builtins.foldl' (
|
||||||
(systems
|
attrs: key:
|
||||||
++ # add the current system if --impure is used
|
attrs
|
||||||
(if builtins?currentSystem then
|
// {
|
||||||
if builtins.elem builtins.currentSystem systems
|
${key} = (attrs.${key} or { }) // {
|
||||||
then []
|
${system} = ret.${key};
|
||||||
else [ builtins.currentSystem ]
|
};
|
||||||
else
|
}
|
||||||
[]))
|
) attrs (builtins.attrNames ret)
|
||||||
;
|
);
|
||||||
|
|
||||||
|
# Applies a merge operation accross systems.
|
||||||
|
eachSystemOp =
|
||||||
|
op: systems: f:
|
||||||
|
builtins.foldl' (op f) { } (
|
||||||
|
if
|
||||||
|
!builtins ? currentSystem || builtins.elem builtins.currentSystem systems
|
||||||
|
then
|
||||||
|
systems
|
||||||
|
else
|
||||||
|
# Add the current system if the --impure flag is used.
|
||||||
|
systems ++ [ builtins.currentSystem ]
|
||||||
|
);
|
||||||
|
|
||||||
|
# Merely provides the system argument to the function.
|
||||||
|
#
|
||||||
|
# Unlike eachSystem, this function does not inject the `${system}` key.
|
||||||
|
eachSystemPassThrough = eachSystemOp (
|
||||||
|
f: attrs: system:
|
||||||
|
attrs // (f system)
|
||||||
|
);
|
||||||
|
|
||||||
# eachSystemMap using defaultSystems
|
# eachSystemMap using defaultSystems
|
||||||
eachDefaultSystemMap = eachSystemMap defaultSystems;
|
eachDefaultSystemMap = eachSystemMap defaultSystems;
|
||||||
|
@ -198,9 +212,11 @@ let
|
||||||
check-utils
|
check-utils
|
||||||
defaultSystems
|
defaultSystems
|
||||||
eachDefaultSystem
|
eachDefaultSystem
|
||||||
eachSystem
|
|
||||||
eachDefaultSystemMap
|
eachDefaultSystemMap
|
||||||
|
eachDefaultSystemPassThrough
|
||||||
|
eachSystem
|
||||||
eachSystemMap
|
eachSystemMap
|
||||||
|
eachSystemPassThrough
|
||||||
filterPackages
|
filterPackages
|
||||||
flattenTree
|
flattenTree
|
||||||
meld
|
meld
|
||||||
|
|
Loading…
Reference in a new issue