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 #!/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) files=$(find . -name "*.nix" -type f)

View file

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

View file

@ -23,12 +23,10 @@ lib: {
parts = lib.strings.split "(0|[1-9][0-9]*)" string; parts = lib.strings.split "(0|[1-9][0-9]*)" string;
in in
builtins.map serialize parts; builtins.map serialize parts;
prepared = builtins.map prepared = builtins.map (value: [
(value: [
(vectorize value) (vectorize value)
value value
]) ]) list;
list;
isLess = a: b: (lib.lists.compare lib.numbers.compare (builtins.head a) (builtins.head b)) < 0; isLess = a: b: (lib.lists.compare lib.numbers.compare (builtins.head a) (builtins.head b)) < 0;
in in
builtins.map (x: builtins.elemAt x 1) (builtins.sort isLess prepared); builtins.map (x: builtins.elemAt x 1) (builtins.sort isLess prepared);
@ -191,12 +189,10 @@ lib: {
list list
else else
builtins.tail ( builtins.tail (
builtins.concatMap builtins.concatMap (part: [
(part: [
separator separator
part part
]) ]) list
list
); );
## Create a list of integers from a starting number to an ending ## 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. ## Flatten a list of lists into a single list.
## ##
## @type List (List a) -> List a ## @type List (List a) -> List a
flatten = value: flatten =
if builtins.isList value then value: if builtins.isList value then builtins.concatMap lib.lists.flatten value else [ value ];
builtins.concatMap lib.lists.flatten value
else
[ value ];
}; };
} }

View file

@ -36,10 +36,7 @@ in
hooks.target.target hooks.target.target
]; ];
in in
builtins.foldl' builtins.foldl' (final: defaults: lib.dag.apply.defaults final defaults) package.phases all;
(final: defaults: lib.dag.apply.defaults final defaults)
package.phases
all;
phases = lib.dag.apply.defaults phasesWithHooks { phases = lib.dag.apply.defaults phasesWithHooks {
unpack = lib.dag.entry.before [ "patch" ] ""; unpack = lib.dag.entry.before [ "patch" ] "";
@ -55,9 +52,7 @@ in
sorted = lib.dag.sort.topological phases; sorted = lib.dag.sort.topological phases;
script = lib.strings.concatMapSep "\n" script = lib.strings.concatMapSep "\n" (entry: entry.value) sorted.result;
(entry: entry.value)
sorted.result;
built = builtins.derivation ( built = builtins.derivation (
package.env package.env

View file

@ -18,36 +18,45 @@ in
build': host': target': build': host': target':
builtins.mapAttrs (name: dep: lib'.packages.build dep build' host' target'); builtins.mapAttrs (name: dep: lib'.packages.build dep build' host' target');
collect = package: collect =
package:
let let
isPropagated = name: package: package.propagate or false; isPropagated = name: package: package.propagate or false;
getPropagatedDependencies = target: builtins.attrValues (lib.attrs.filter isPropagated target); getPropagatedDependencies = target: builtins.attrValues (lib.attrs.filter isPropagated target);
process = dependencies: process =
dependencies:
let let
getDeps = name: dependency: getDeps =
name: dependency:
let let
deps = deps = {
{
build = { build = {
only = getPropagatedDependencies dependency.deps.build.only ++ process dependency.deps.build.only; 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; 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 = { host = {
only = getPropagatedDependencies dependency.deps.host.only ++ process dependency.deps.host.only; only = getPropagatedDependencies dependency.deps.host.only ++ process dependency.deps.host.only;
host = getPropagatedDependencies dependency.deps.host.host ++ process dependency.deps.host.host; 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 = { target = {
only = getPropagatedDependencies dependency.deps.target.only ++ process dependency.deps.target.only; 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 in
lib.lists.flatten lib.lists.flatten [
[
deps.build.only deps.build.only
deps.build.build deps.build.build
deps.build.host deps.build.host
@ -83,18 +92,16 @@ in
}; };
context = { context = {
create = collected: ctx: create =
collected: ctx:
let let
process = path: process =
path:
let let
dependencies = lib.attrs.selectOrThrow path collected; dependencies = lib.attrs.selectOrThrow path collected;
contexts = builtins.map (dependency: dependency.context or { }) dependencies; contexts = builtins.map (dependency: dependency.context or { }) dependencies;
result = lib.modules.run { result = lib.modules.run {
modules = modules = builtins.map (context: { config = context; }) contexts ++ [
builtins.map
(context: { config = context; })
contexts
++ [
{ {
freeform = lib.types.any; freeform = lib.types.any;
@ -151,54 +158,110 @@ in
in in
{ {
build = { build = {
only = process [ "build" "only" ]; only = process [
build = process [ "build" "build" ]; "build"
host = process [ "build" "host" ]; "only"
target = process [ "build" "target" ]; ];
build = process [
"build"
"build"
];
host = process [
"build"
"host"
];
target = process [
"build"
"target"
];
}; };
host = { host = {
only = process [ "host" "only" ]; only = process [
host = process [ "host" "host" ]; "host"
target = process [ "host" "target" ]; "only"
];
host = process [
"host"
"host"
];
target = process [
"host"
"target"
];
}; };
target = { target = {
only = process [ "target" "only" ]; only = process [
target = process [ "target" "target" ]; "target"
"only"
];
target = process [
"target"
"target"
];
}; };
}; };
}; };
hooks = { hooks = {
create = collected: ctx: create =
collected: ctx:
let let
process = path: process =
path:
let let
dependencies = lib.attrs.selectOrThrow path collected; dependencies = lib.attrs.selectOrThrow path collected;
hooks = builtins.map hooks = builtins.map (
(dependency: dependency:
let let
getHooks = dependency.hooks or (lib.fp.const { }); getHooks = dependency.hooks or (lib.fp.const { });
in in
getHooks ctx) getHooks ctx
dependencies; ) dependencies;
in in
hooks; hooks;
in in
{ {
build = { build = {
only = process [ "build" "only" ]; only = process [
build = process [ "build" "build" ]; "build"
host = process [ "build" "host" ]; "only"
target = process [ "build" "target" ]; ];
build = process [
"build"
"build"
];
host = process [
"build"
"host"
];
target = process [
"build"
"target"
];
}; };
host = { host = {
only = process [ "host" "only" ]; only = process [
host = process [ "host" "host" ]; "host"
target = process [ "host" "target" ]; "only"
];
host = process [
"host"
"host"
];
target = process [
"host"
"target"
];
}; };
target = { target = {
only = process [ "target" "only" ]; only = process [
target = process [ "target" "target" ]; "target"
"only"
];
target = process [
"target"
"target"
];
}; };
}; };
}; };

View file

@ -30,11 +30,7 @@ in
cflags = [ "-I $AUX_B/include" ]; cflags = [ "-I $AUX_B/include" ];
}; };
hooks = ctx: { hooks = ctx: { "aux:b:env" = lib.dag.entry.after [ "unpack" ] ''export AUX_B=${config.package}''; };
"aux:b:env" = lib.dag.entry.after
[ "unpack" ]
''export AUX_B=${config.package}'';
};
phases = { phases = {
install = '' install = ''

View file

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