refactor: format

This commit is contained in:
Jake Hamilton 2024-07-09 01:49:44 -07:00
parent ea200d834e
commit 3f9d287065
Signed by: jakehamilton
GPG key ID: 9762169A1B35EA68
7 changed files with 237 additions and 196 deletions

View file

@ -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)

View file

@ -47,12 +47,10 @@ lib: {
in
if sorted ? result then
{
result = builtins.map
(value: {
result = builtins.map (value: {
name = value.name;
value = value.value;
})
sorted.result;
}) sorted.result;
}
else
sorted;
@ -66,8 +64,7 @@ lib: {
defaults =
graph: defaults:
let
result = builtins.mapAttrs
(
result = builtins.mapAttrs (
name: entry:
if defaults ? ${name} then
if builtins.isString entry then
@ -84,8 +81,7 @@ lib: {
}
else
entry
)
graph;
) graph;
in
defaults // result;
};

View file

@ -23,12 +23,10 @@ lib: {
parts = lib.strings.split "(0|[1-9][0-9]*)" string;
in
builtins.map serialize parts;
prepared = builtins.map
(value: [
prepared = builtins.map (value: [
(vectorize value)
value
])
list;
]) 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);
@ -191,12 +189,10 @@ lib: {
list
else
builtins.tail (
builtins.concatMap
(part: [
builtins.concatMap (part: [
separator
part
])
list
]) 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 ];
};
}

View file

@ -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

View file

@ -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,36 +18,45 @@ 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 =
{
deps = {
build = {
only = getPropagatedDependencies dependency.deps.build.only ++ process dependency.deps.build.only;
build = getPropagatedDependencies dependency.deps.build.build ++ process dependency.deps.build.build;
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;
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 =
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;
target =
getPropagatedDependencies dependency.deps.target.target
++ process dependency.deps.target.target;
};
};
in
lib.lists.flatten
[
lib.lists.flatten [
deps.build.only
deps.build.build
deps.build.host
@ -83,18 +92,16 @@ 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
++ [
modules = builtins.map (context: { config = context; }) contexts ++ [
{
freeform = lib.types.any;
@ -151,54 +158,110 @@ in
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:
hooks = builtins.map (
dependency:
let
getHooks = dependency.hooks or (lib.fp.const { });
in
getHooks ctx)
dependencies;
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"
];
};
};
};

View file

@ -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 = ''

View file

@ -55,8 +55,7 @@ in
config = {
packages.cross = lib.attrs.generate doubles (
system:
builtins.mapAttrs
(
builtins.mapAttrs (
namespace:
builtins.mapAttrs (
name: alias:
@ -81,8 +80,7 @@ in
in
updated
)
)
packages
) packages
);
};
}