Skip to content

Commit

Permalink
refactor(errors): enhance throw info
Browse files Browse the repository at this point in the history
  • Loading branch information
GTrunSec committed Nov 9, 2023
1 parent d5b3efb commit 8c933df
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 21 deletions.
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions local/cells/repo/pops.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ in
)
);

configs = inputs.omnibus.pops.configs.addLoadExtender {
load.inputs.inputs = inputs';
configs = inputs.omnibus.pops.configs {
inputs = {
inputs = {
inherit (inputs') nixfmt topiary nur;
inherit (inputs) std;
inherit nixpkgs;
};
};
};
}
20 changes: 9 additions & 11 deletions src/errors/requiredInputs.nix
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
{ lib, super }:
inputs': object: listNames:
let
fondInputs =
if
(lib.length (
lib.filter (pair: pair == true) (map (v: lib.hasAttr v inputs') listNames)
)) > 0
then
true
else
false;
notFoundInputs =
(lib.filter (pair: pair != true) (
map (v: if (lib.hasAttr v inputs') then true else v) listNames
));
isFound = (lib.length notFoundInputs == 0);
msg =
(lib.concatMapStringsSep "\n "
(
Expand All @@ -19,16 +15,18 @@ let
${name} = inputs.${name};
''
)
(super.inputsSource listNames)
(super.inputsSource notFoundInputs)
);

noSysNixpkgs =
if (lib.elem "nixpkgs" listNames && inputs' ? nixpkgs) then
if (lib.hasAttr "path" inputs'.nixpkgs) then true else false
else if (lib.elem "nixpkgs" listNames && !inputs' ? nixpkgs) then
false
else
true;
in
assert lib.assertMsg fondInputs ''
assert lib.assertMsg isFound ''
please, add the these inputs into
${object}.addLoadExtender {
Expand Down
9 changes: 9 additions & 0 deletions src/lib/types.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
lib,
yants,
self,
}:
with yants; {
a = struct "test" { name = string; };
b = either self.a (struct { age = int; });
}
54 changes: 52 additions & 2 deletions src/pops/configs.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,54 @@
flops.haumea.pops.default.setInit {
{
flops,
lib,
root,
projectDir,
POP,
}:
load:
let
inherit
(root.errors.requiredInputs load.inputs.inputs "omnibus.pops.configs" [ "std" ])
std
;
inherit (std.lib.dev) mkNixago;
inherit (std.lib) cfg;

applyRecursive =
mkFunc: layoutData:
lib.mapAttrsRecursiveCond (as: !(lib.isAttrs as && as ? data)) # Condition to check
(n: v: mkFunc v) # Function to apply
layoutData;

# Function to process each layout
processLayouts =
data: cfgName:
applyRecursive
(
layoutData:
if (lib.hasAttr cfgName cfg) then
mkNixago cfg.${cfgName} layoutData
else
throw "Unknown layout: ${cfgName}"
)
(data.layouts.default.${cfgName});
in
((flops.haumea.pops.default.setInit {
src = projectDir + "/units/configs";
inputs = root.lib.loaderInputs;
}
}).addLoadExtender
{ inherit load; }
).addExporters
[
(POP.extendPop flops.haumea.pops.exporter (
self: _super: {
exports = {
stdNixago = lib.listToAttrs (
map (name: lib.nameValuePair name (processLayouts self name)) (
lib.attrNames self.layouts.default
)
);
};
}
))
]
7 changes: 7 additions & 0 deletions units/configs/treefmt.nix
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ in
options = [ "format" ];
};
};
deadnix = {
packages = [ nixpkgs.deadnix ];
data.formatter.deadnix = {
command = "deadnix";
options = [ "--edit" ];
};
};
topiary = {
data.formatter.topiary = {
command = "topiary";
Expand Down

0 comments on commit 8c933df

Please sign in to comment.