refactor: format

This commit is contained in:
Jake Hamilton 2024-07-09 01:49:44 -07:00
parent ea200d834e
commit 3f9d287065
Signed by untrusted user: 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,26 +64,24 @@ 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 {
{ value = entry;
value = entry; before = defaults.${name}.before or [ ];
before = defaults.${name}.before or [ ]; after = defaults.${name}.after or [ ];
after = defaults.${name}.after or [ ]; }
} else
else entry
entry // {
// { before = (entry.before or [ ]) ++ (defaults.${name}.before or [ ]);
before = (entry.before or [ ]) ++ (defaults.${name}.before or [ ]); after = (entry.after or [ ]) ++ (defaults.${name}.after or [ ]);
after = (entry.after or [ ]) ++ (defaults.${name}.after or [ ]); }
} 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);
@ -125,8 +123,8 @@ lib: {
## @type List a -> a ## @type List a -> a
last = last =
list: list:
assert lib.errors.trace (list != [ ]) "List cannot be empty"; assert lib.errors.trace (list != [ ]) "List cannot be empty";
builtins.elemAt list (builtins.length list - 1); builtins.elemAt list (builtins.length list - 1);
## Slice part of a list to create a new list. ## Slice part of a list to create a new list.
## ##
@ -165,8 +163,8 @@ lib: {
## @type List -> List ## @type List -> List
init = init =
list: list:
assert lib.errors.trace (builtins.length list != 0) "lib.lists.init: list must not be empty."; assert lib.errors.trace (builtins.length list != 0) "lib.lists.init: list must not be empty.";
lib.lists.take (builtins.length list - 1) list; lib.lists.take (builtins.length list - 1) list;
## Reverse a list. ## Reverse a list.
## ##
@ -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

@ -9,7 +9,7 @@ in
get = get =
dependencies: dependencies:
let let
exists = value: ! (builtins.isNull value); exists = value: !(builtins.isNull value);
available = builtins.filter exists dependencies; available = builtins.filter exists dependencies;
in in
builtins.map (dependency: dependency.package) available; builtins.map (dependency: dependency.package) available;
@ -18,46 +18,55 @@ 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 =
build = getPropagatedDependencies dependency.deps.build.build ++ process dependency.deps.build.build; getPropagatedDependencies dependency.deps.build.build
host = getPropagatedDependencies dependency.deps.build.host ++ process dependency.deps.build.host; ++ process dependency.deps.build.build;
target = getPropagatedDependencies dependency.deps.build.target ++ process dependency.deps.build.target; host = getPropagatedDependencies dependency.deps.build.host ++ process dependency.deps.build.host;
}; target =
host = { getPropagatedDependencies dependency.deps.build.target
only = getPropagatedDependencies dependency.deps.host.only ++ process dependency.deps.host.only; ++ process dependency.deps.build.target;
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;
};
}; };
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 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 deps.build.target
deps.build.target deps.host.only
deps.host.only deps.host.host
deps.host.host deps.host.target
deps.host.target deps.target.only
deps.target.only deps.target.target
deps.target.target ];
];
propagated = lib.attrs.mapToList getDeps dependencies; propagated = lib.attrs.mapToList getDeps dependencies;
in in
@ -83,122 +92,176 @@ 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; }) freeform = lib.types.any;
contexts
++ [
{
freeform = lib.types.any;
options = config.packages.context.options // { options = config.packages.context.options // {
target = lib.options.create { target = lib.options.create {
description = "The dependency target that is being generated."; description = "The dependency target that is being generated.";
type = lib.types.enum [ type = lib.types.enum [
"build.only" "build.only"
"build.build" "build.build"
"build.host" "build.host"
"build.target" "build.target"
"host.only" "host.only"
"host.host" "host.host"
"host.target" "host.target"
"target.only" "target.only"
"target.target" "target.target"
]; ];
writable = false; writable = false;
default.value = builtins.concatStringsSep "." path; default.value = builtins.concatStringsSep "." path;
}; };
deps = lib.options.create { deps = lib.options.create {
description = "The collected dependencies."; description = "The collected dependencies.";
writable = false; writable = false;
default.value = collected; default.value = collected;
type = lib.types.submodule { type = lib.types.submodule {
options = { options = {
build = { build = {
only = lib.options.create { type = lib.types.list.of lib'.types.package; }; only = lib.options.create { type = lib.types.list.of lib'.types.package; };
build = 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; }; 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 = lib.options.create { type = lib.types.list.of lib'.types.package; };
}; };
host = { host = {
only = lib.options.create { type = lib.types.list.of lib'.types.package; }; only = lib.options.create { type = lib.types.list.of lib'.types.package; };
host = 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 = lib.options.create { type = lib.types.list.of lib'.types.package; };
}; };
target = { target = {
only = lib.options.create { type = lib.types.list.of lib'.types.package; }; only = lib.options.create { type = lib.types.list.of lib'.types.package; };
target = 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 in
result.config; result.config;
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,34 +55,32 @@ 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: let
let setHost =
setHost = package:
package: package
package // {
// { __modules__ = package.__modules__ ++ [
__modules__ = package.__modules__ ++ [ {
{ config.platform = {
config.platform = { host = lib.modules.override 5 system;
host = lib.modules.override 5 system; target = lib.modules.override 5 system;
target = lib.modules.override 5 system; };
}; }
} ];
]; };
};
updated = alias // { updated = alias // {
versions = builtins.mapAttrs (version: package: setHost package) alias.versions; versions = builtins.mapAttrs (version: package: setHost package) alias.versions;
}; };
in in
updated updated
)
) )
packages ) packages
); );
}; };
} }