refactor: format
This commit is contained in:
parent
ea200d834e
commit
3f9d287065
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env nix-shell
|
||||
#!nix-shell -i bash -I "nixpkgs=https://github.com/nixos/nixpkgs/archive/nixos-24.05.tar.gz" -p nixfmt-rfc-style
|
||||
#!nix-shell -i bash -I "nixpkgs=https://github.com/nixos/nixpkgs/archive/nixos-unstable.tar.gz" -p nixfmt-rfc-style
|
||||
|
||||
files=$(find . -name "*.nix" -type f)
|
||||
|
||||
|
|
|
@ -47,12 +47,10 @@ lib: {
|
|||
in
|
||||
if sorted ? result then
|
||||
{
|
||||
result = builtins.map
|
||||
(value: {
|
||||
name = value.name;
|
||||
value = value.value;
|
||||
})
|
||||
sorted.result;
|
||||
result = builtins.map (value: {
|
||||
name = value.name;
|
||||
value = value.value;
|
||||
}) sorted.result;
|
||||
}
|
||||
else
|
||||
sorted;
|
||||
|
@ -66,26 +64,24 @@ lib: {
|
|||
defaults =
|
||||
graph: defaults:
|
||||
let
|
||||
result = builtins.mapAttrs
|
||||
(
|
||||
name: entry:
|
||||
if defaults ? ${name} then
|
||||
if builtins.isString entry then
|
||||
{
|
||||
value = entry;
|
||||
before = defaults.${name}.before or [ ];
|
||||
after = defaults.${name}.after or [ ];
|
||||
}
|
||||
else
|
||||
entry
|
||||
// {
|
||||
before = (entry.before or [ ]) ++ (defaults.${name}.before or [ ]);
|
||||
after = (entry.after or [ ]) ++ (defaults.${name}.after or [ ]);
|
||||
}
|
||||
else
|
||||
entry
|
||||
)
|
||||
graph;
|
||||
result = builtins.mapAttrs (
|
||||
name: entry:
|
||||
if defaults ? ${name} then
|
||||
if builtins.isString entry then
|
||||
{
|
||||
value = entry;
|
||||
before = defaults.${name}.before or [ ];
|
||||
after = defaults.${name}.after or [ ];
|
||||
}
|
||||
else
|
||||
entry
|
||||
// {
|
||||
before = (entry.before or [ ]) ++ (defaults.${name}.before or [ ]);
|
||||
after = (entry.after or [ ]) ++ (defaults.${name}.after or [ ]);
|
||||
}
|
||||
else
|
||||
entry
|
||||
) graph;
|
||||
in
|
||||
defaults // result;
|
||||
};
|
||||
|
|
|
@ -23,12 +23,10 @@ lib: {
|
|||
parts = lib.strings.split "(0|[1-9][0-9]*)" string;
|
||||
in
|
||||
builtins.map serialize parts;
|
||||
prepared = builtins.map
|
||||
(value: [
|
||||
(vectorize value)
|
||||
value
|
||||
])
|
||||
list;
|
||||
prepared = builtins.map (value: [
|
||||
(vectorize value)
|
||||
value
|
||||
]) list;
|
||||
isLess = a: b: (lib.lists.compare lib.numbers.compare (builtins.head a) (builtins.head b)) < 0;
|
||||
in
|
||||
builtins.map (x: builtins.elemAt x 1) (builtins.sort isLess prepared);
|
||||
|
@ -125,8 +123,8 @@ lib: {
|
|||
## @type List a -> a
|
||||
last =
|
||||
list:
|
||||
assert lib.errors.trace (list != [ ]) "List cannot be empty";
|
||||
builtins.elemAt list (builtins.length list - 1);
|
||||
assert lib.errors.trace (list != [ ]) "List cannot be empty";
|
||||
builtins.elemAt list (builtins.length list - 1);
|
||||
|
||||
## Slice part of a list to create a new list.
|
||||
##
|
||||
|
@ -165,8 +163,8 @@ lib: {
|
|||
## @type List -> List
|
||||
init =
|
||||
list:
|
||||
assert lib.errors.trace (builtins.length list != 0) "lib.lists.init: list must not be empty.";
|
||||
lib.lists.take (builtins.length list - 1) list;
|
||||
assert lib.errors.trace (builtins.length list != 0) "lib.lists.init: list must not be empty.";
|
||||
lib.lists.take (builtins.length list - 1) list;
|
||||
|
||||
## Reverse a list.
|
||||
##
|
||||
|
@ -191,12 +189,10 @@ lib: {
|
|||
list
|
||||
else
|
||||
builtins.tail (
|
||||
builtins.concatMap
|
||||
(part: [
|
||||
separator
|
||||
part
|
||||
])
|
||||
list
|
||||
builtins.concatMap (part: [
|
||||
separator
|
||||
part
|
||||
]) list
|
||||
);
|
||||
|
||||
## Create a list of integers from a starting number to an ending
|
||||
|
@ -232,10 +228,7 @@ lib: {
|
|||
## Flatten a list of lists into a single list.
|
||||
##
|
||||
## @type List (List a) -> List a
|
||||
flatten = value:
|
||||
if builtins.isList value then
|
||||
builtins.concatMap lib.lists.flatten value
|
||||
else
|
||||
[ value ];
|
||||
flatten =
|
||||
value: if builtins.isList value then builtins.concatMap lib.lists.flatten value else [ value ];
|
||||
};
|
||||
}
|
||||
|
|
|
@ -36,10 +36,7 @@ in
|
|||
hooks.target.target
|
||||
];
|
||||
in
|
||||
builtins.foldl'
|
||||
(final: defaults: lib.dag.apply.defaults final defaults)
|
||||
package.phases
|
||||
all;
|
||||
builtins.foldl' (final: defaults: lib.dag.apply.defaults final defaults) package.phases all;
|
||||
|
||||
phases = lib.dag.apply.defaults phasesWithHooks {
|
||||
unpack = lib.dag.entry.before [ "patch" ] "";
|
||||
|
@ -55,9 +52,7 @@ in
|
|||
|
||||
sorted = lib.dag.sort.topological phases;
|
||||
|
||||
script = lib.strings.concatMapSep "\n"
|
||||
(entry: entry.value)
|
||||
sorted.result;
|
||||
script = lib.strings.concatMapSep "\n" (entry: entry.value) sorted.result;
|
||||
|
||||
built = builtins.derivation (
|
||||
package.env
|
||||
|
|
|
@ -9,7 +9,7 @@ in
|
|||
get =
|
||||
dependencies:
|
||||
let
|
||||
exists = value: ! (builtins.isNull value);
|
||||
exists = value: !(builtins.isNull value);
|
||||
available = builtins.filter exists dependencies;
|
||||
in
|
||||
builtins.map (dependency: dependency.package) available;
|
||||
|
@ -18,46 +18,55 @@ in
|
|||
build': host': target':
|
||||
builtins.mapAttrs (name: dep: lib'.packages.build dep build' host' target');
|
||||
|
||||
collect = package:
|
||||
collect =
|
||||
package:
|
||||
let
|
||||
isPropagated = name: package: package.propagate or false;
|
||||
getPropagatedDependencies = target: builtins.attrValues (lib.attrs.filter isPropagated target);
|
||||
|
||||
process = dependencies:
|
||||
process =
|
||||
dependencies:
|
||||
let
|
||||
getDeps = name: dependency:
|
||||
getDeps =
|
||||
name: dependency:
|
||||
let
|
||||
deps =
|
||||
{
|
||||
build = {
|
||||
only = getPropagatedDependencies dependency.deps.build.only ++ process dependency.deps.build.only;
|
||||
build = getPropagatedDependencies dependency.deps.build.build ++ process dependency.deps.build.build;
|
||||
host = getPropagatedDependencies dependency.deps.build.host ++ process dependency.deps.build.host;
|
||||
target = getPropagatedDependencies dependency.deps.build.target ++ process dependency.deps.build.target;
|
||||
};
|
||||
host = {
|
||||
only = getPropagatedDependencies dependency.deps.host.only ++ process dependency.deps.host.only;
|
||||
host = getPropagatedDependencies dependency.deps.host.host ++ process dependency.deps.host.host;
|
||||
target = getPropagatedDependencies dependency.deps.host.target ++ process dependency.deps.host.target;
|
||||
};
|
||||
target = {
|
||||
only = getPropagatedDependencies dependency.deps.target.only ++ process dependency.deps.target.only;
|
||||
target = getPropagatedDependencies dependency.deps.target.target ++ process dependency.deps.target.target;
|
||||
};
|
||||
deps = {
|
||||
build = {
|
||||
only = getPropagatedDependencies dependency.deps.build.only ++ process dependency.deps.build.only;
|
||||
build =
|
||||
getPropagatedDependencies dependency.deps.build.build
|
||||
++ process dependency.deps.build.build;
|
||||
host = getPropagatedDependencies dependency.deps.build.host ++ process dependency.deps.build.host;
|
||||
target =
|
||||
getPropagatedDependencies dependency.deps.build.target
|
||||
++ process dependency.deps.build.target;
|
||||
};
|
||||
host = {
|
||||
only = getPropagatedDependencies dependency.deps.host.only ++ process dependency.deps.host.only;
|
||||
host = getPropagatedDependencies dependency.deps.host.host ++ process dependency.deps.host.host;
|
||||
target =
|
||||
getPropagatedDependencies dependency.deps.host.target
|
||||
++ process dependency.deps.host.target;
|
||||
};
|
||||
target = {
|
||||
only = getPropagatedDependencies dependency.deps.target.only ++ process dependency.deps.target.only;
|
||||
target =
|
||||
getPropagatedDependencies dependency.deps.target.target
|
||||
++ process dependency.deps.target.target;
|
||||
};
|
||||
};
|
||||
in
|
||||
lib.lists.flatten
|
||||
[
|
||||
deps.build.only
|
||||
deps.build.build
|
||||
deps.build.host
|
||||
deps.build.target
|
||||
deps.host.only
|
||||
deps.host.host
|
||||
deps.host.target
|
||||
deps.target.only
|
||||
deps.target.target
|
||||
];
|
||||
lib.lists.flatten [
|
||||
deps.build.only
|
||||
deps.build.build
|
||||
deps.build.host
|
||||
deps.build.target
|
||||
deps.host.only
|
||||
deps.host.host
|
||||
deps.host.target
|
||||
deps.target.only
|
||||
deps.target.target
|
||||
];
|
||||
|
||||
propagated = lib.attrs.mapToList getDeps dependencies;
|
||||
in
|
||||
|
@ -83,122 +92,176 @@ in
|
|||
};
|
||||
|
||||
context = {
|
||||
create = collected: ctx:
|
||||
create =
|
||||
collected: ctx:
|
||||
let
|
||||
process = path:
|
||||
process =
|
||||
path:
|
||||
let
|
||||
dependencies = lib.attrs.selectOrThrow path collected;
|
||||
contexts = builtins.map (dependency: dependency.context or { }) dependencies;
|
||||
result = lib.modules.run {
|
||||
modules =
|
||||
builtins.map
|
||||
(context: { config = context; })
|
||||
contexts
|
||||
++ [
|
||||
{
|
||||
freeform = lib.types.any;
|
||||
modules = builtins.map (context: { config = context; }) contexts ++ [
|
||||
{
|
||||
freeform = lib.types.any;
|
||||
|
||||
options = config.packages.context.options // {
|
||||
target = lib.options.create {
|
||||
description = "The dependency target that is being generated.";
|
||||
type = lib.types.enum [
|
||||
"build.only"
|
||||
"build.build"
|
||||
"build.host"
|
||||
"build.target"
|
||||
"host.only"
|
||||
"host.host"
|
||||
"host.target"
|
||||
"target.only"
|
||||
"target.target"
|
||||
];
|
||||
writable = false;
|
||||
default.value = builtins.concatStringsSep "." path;
|
||||
};
|
||||
options = config.packages.context.options // {
|
||||
target = lib.options.create {
|
||||
description = "The dependency target that is being generated.";
|
||||
type = lib.types.enum [
|
||||
"build.only"
|
||||
"build.build"
|
||||
"build.host"
|
||||
"build.target"
|
||||
"host.only"
|
||||
"host.host"
|
||||
"host.target"
|
||||
"target.only"
|
||||
"target.target"
|
||||
];
|
||||
writable = false;
|
||||
default.value = builtins.concatStringsSep "." path;
|
||||
};
|
||||
|
||||
deps = lib.options.create {
|
||||
description = "The collected dependencies.";
|
||||
writable = false;
|
||||
default.value = collected;
|
||||
type = lib.types.submodule {
|
||||
options = {
|
||||
build = {
|
||||
only = lib.options.create { type = lib.types.list.of lib'.types.package; };
|
||||
build = lib.options.create { type = lib.types.list.of lib'.types.package; };
|
||||
host = lib.options.create { type = lib.types.list.of lib'.types.package; };
|
||||
target = lib.options.create { type = lib.types.list.of lib'.types.package; };
|
||||
};
|
||||
host = {
|
||||
only = lib.options.create { type = lib.types.list.of lib'.types.package; };
|
||||
host = lib.options.create { type = lib.types.list.of lib'.types.package; };
|
||||
target = lib.options.create { type = lib.types.list.of lib'.types.package; };
|
||||
};
|
||||
target = {
|
||||
only = lib.options.create { type = lib.types.list.of lib'.types.package; };
|
||||
target = lib.options.create { type = lib.types.list.of lib'.types.package; };
|
||||
};
|
||||
deps = lib.options.create {
|
||||
description = "The collected dependencies.";
|
||||
writable = false;
|
||||
default.value = collected;
|
||||
type = lib.types.submodule {
|
||||
options = {
|
||||
build = {
|
||||
only = lib.options.create { type = lib.types.list.of lib'.types.package; };
|
||||
build = lib.options.create { type = lib.types.list.of lib'.types.package; };
|
||||
host = lib.options.create { type = lib.types.list.of lib'.types.package; };
|
||||
target = lib.options.create { type = lib.types.list.of lib'.types.package; };
|
||||
};
|
||||
host = {
|
||||
only = lib.options.create { type = lib.types.list.of lib'.types.package; };
|
||||
host = lib.options.create { type = lib.types.list.of lib'.types.package; };
|
||||
target = lib.options.create { type = lib.types.list.of lib'.types.package; };
|
||||
};
|
||||
target = {
|
||||
only = lib.options.create { type = lib.types.list.of lib'.types.package; };
|
||||
target = lib.options.create { type = lib.types.list.of lib'.types.package; };
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = ctx;
|
||||
}
|
||||
];
|
||||
config = ctx;
|
||||
}
|
||||
];
|
||||
};
|
||||
in
|
||||
result.config;
|
||||
in
|
||||
{
|
||||
build = {
|
||||
only = process [ "build" "only" ];
|
||||
build = process [ "build" "build" ];
|
||||
host = process [ "build" "host" ];
|
||||
target = process [ "build" "target" ];
|
||||
only = process [
|
||||
"build"
|
||||
"only"
|
||||
];
|
||||
build = process [
|
||||
"build"
|
||||
"build"
|
||||
];
|
||||
host = process [
|
||||
"build"
|
||||
"host"
|
||||
];
|
||||
target = process [
|
||||
"build"
|
||||
"target"
|
||||
];
|
||||
};
|
||||
host = {
|
||||
only = process [ "host" "only" ];
|
||||
host = process [ "host" "host" ];
|
||||
target = process [ "host" "target" ];
|
||||
only = process [
|
||||
"host"
|
||||
"only"
|
||||
];
|
||||
host = process [
|
||||
"host"
|
||||
"host"
|
||||
];
|
||||
target = process [
|
||||
"host"
|
||||
"target"
|
||||
];
|
||||
};
|
||||
target = {
|
||||
only = process [ "target" "only" ];
|
||||
target = process [ "target" "target" ];
|
||||
only = process [
|
||||
"target"
|
||||
"only"
|
||||
];
|
||||
target = process [
|
||||
"target"
|
||||
"target"
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
hooks = {
|
||||
create = collected: ctx:
|
||||
create =
|
||||
collected: ctx:
|
||||
let
|
||||
process = path:
|
||||
process =
|
||||
path:
|
||||
let
|
||||
dependencies = lib.attrs.selectOrThrow path collected;
|
||||
hooks = builtins.map
|
||||
(dependency:
|
||||
let
|
||||
getHooks = dependency.hooks or (lib.fp.const { });
|
||||
in
|
||||
getHooks ctx)
|
||||
dependencies;
|
||||
hooks = builtins.map (
|
||||
dependency:
|
||||
let
|
||||
getHooks = dependency.hooks or (lib.fp.const { });
|
||||
in
|
||||
getHooks ctx
|
||||
) dependencies;
|
||||
in
|
||||
hooks;
|
||||
in
|
||||
{
|
||||
build = {
|
||||
only = process [ "build" "only" ];
|
||||
build = process [ "build" "build" ];
|
||||
host = process [ "build" "host" ];
|
||||
target = process [ "build" "target" ];
|
||||
only = process [
|
||||
"build"
|
||||
"only"
|
||||
];
|
||||
build = process [
|
||||
"build"
|
||||
"build"
|
||||
];
|
||||
host = process [
|
||||
"build"
|
||||
"host"
|
||||
];
|
||||
target = process [
|
||||
"build"
|
||||
"target"
|
||||
];
|
||||
};
|
||||
host = {
|
||||
only = process [ "host" "only" ];
|
||||
host = process [ "host" "host" ];
|
||||
target = process [ "host" "target" ];
|
||||
only = process [
|
||||
"host"
|
||||
"only"
|
||||
];
|
||||
host = process [
|
||||
"host"
|
||||
"host"
|
||||
];
|
||||
target = process [
|
||||
"host"
|
||||
"target"
|
||||
];
|
||||
};
|
||||
target = {
|
||||
only = process [ "target" "only" ];
|
||||
target = process [ "target" "target" ];
|
||||
only = process [
|
||||
"target"
|
||||
"only"
|
||||
];
|
||||
target = process [
|
||||
"target"
|
||||
"target"
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
@ -30,11 +30,7 @@ in
|
|||
cflags = [ "-I $AUX_B/include" ];
|
||||
};
|
||||
|
||||
hooks = ctx: {
|
||||
"aux:b:env" = lib.dag.entry.after
|
||||
[ "unpack" ]
|
||||
''export AUX_B=${config.package}'';
|
||||
};
|
||||
hooks = ctx: { "aux:b:env" = lib.dag.entry.after [ "unpack" ] ''export AUX_B=${config.package}''; };
|
||||
|
||||
phases = {
|
||||
install = ''
|
||||
|
|
|
@ -55,34 +55,32 @@ in
|
|||
config = {
|
||||
packages.cross = lib.attrs.generate doubles (
|
||||
system:
|
||||
builtins.mapAttrs
|
||||
(
|
||||
namespace:
|
||||
builtins.mapAttrs (
|
||||
name: alias:
|
||||
let
|
||||
setHost =
|
||||
package:
|
||||
package
|
||||
// {
|
||||
__modules__ = package.__modules__ ++ [
|
||||
{
|
||||
config.platform = {
|
||||
host = lib.modules.override 5 system;
|
||||
target = lib.modules.override 5 system;
|
||||
};
|
||||
}
|
||||
];
|
||||
};
|
||||
builtins.mapAttrs (
|
||||
namespace:
|
||||
builtins.mapAttrs (
|
||||
name: alias:
|
||||
let
|
||||
setHost =
|
||||
package:
|
||||
package
|
||||
// {
|
||||
__modules__ = package.__modules__ ++ [
|
||||
{
|
||||
config.platform = {
|
||||
host = lib.modules.override 5 system;
|
||||
target = lib.modules.override 5 system;
|
||||
};
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
updated = alias // {
|
||||
versions = builtins.mapAttrs (version: package: setHost package) alias.versions;
|
||||
};
|
||||
in
|
||||
updated
|
||||
)
|
||||
updated = alias // {
|
||||
versions = builtins.mapAttrs (version: package: setHost package) alias.versions;
|
||||
};
|
||||
in
|
||||
updated
|
||||
)
|
||||
packages
|
||||
) packages
|
||||
);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue