mirror of
https://github.com/TECHNOFAB11/kubenix.git
synced 2025-12-12 16:10:05 +01:00
feat: interface and lib refactoring
This commit is contained in:
parent
e260ad9bb4
commit
5d8b66f8a0
10 changed files with 111 additions and 88 deletions
45
lib/extra.nix
Normal file
45
lib/extra.nix
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
{ lib, pkgs }:
|
||||
|
||||
with lib;
|
||||
|
||||
rec {
|
||||
moduleToAttrs = value:
|
||||
if isAttrs value
|
||||
then mapAttrs (n: v: moduleToAttrs v) (filterAttrs (n: v: !(hasPrefix "_" n) && v != null) value)
|
||||
|
||||
else if isList value
|
||||
then map (v: moduleToAttrs v) value
|
||||
|
||||
else value;
|
||||
|
||||
mkOptionDefault = mkOverride 1001;
|
||||
|
||||
mkAllDefault = value: priority:
|
||||
if isAttrs value
|
||||
then mapAttrs (n: v: mkAllDefault v priority) value
|
||||
|
||||
else if isList value
|
||||
then map (v: mkAllDefault v priority) value
|
||||
|
||||
else mkOverride priority value;
|
||||
|
||||
loadYAML = path: importJSON (pkgs.runCommand "yaml-to-json" {
|
||||
} "${pkgs.remarshal}/bin/remarshal -i ${path} -if yaml -of json > $out");
|
||||
|
||||
toYAML = config: pkgs.runCommand "to-yaml" {
|
||||
buildInputs = [pkgs.remarshal];
|
||||
} ''
|
||||
remarshal -i ${pkgs.writeText "to-json" (builtins.toJSON config)} -if json -of yaml > $out
|
||||
'';
|
||||
|
||||
toBase64 = value:
|
||||
builtins.readFile
|
||||
(pkgs.runCommand "value-to-b64" {} "echo -n '${value}' | ${pkgs.coreutils}/bin/base64 -w0 > $out");
|
||||
|
||||
exp = base: exp: foldr (value: acc: acc * base) 1 (range 1 exp);
|
||||
|
||||
octalToDecimal = value: (foldr (char: acc: {
|
||||
i = acc.i + 1;
|
||||
value = acc.value + (toInt char) * (exp 8 acc.i);
|
||||
}) {i = 0; value = 0;} (stringToCharacters value)).value;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue