refactor: add formatting script

This commit is contained in:
Jake Hamilton 2024-06-22 10:56:18 -07:00
parent 403420fd4b
commit 3479354ec9
Signed by: jakehamilton
GPG key ID: 9762169A1B35EA68
7 changed files with 105 additions and 121 deletions

4
format.sh Executable file
View file

@ -0,0 +1,4 @@
#!/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
nixfmt ${1:-"--verify"} ./**/*.nix

View file

@ -1,14 +1,13 @@
{system ? builtins.currentSystem}: let
{
system ? builtins.currentSystem,
}:
let
lib = import ./../lib;
modules = import ./src;
result = lib.modules.run {
modules =
(builtins.attrValues modules)
++ [
{config.aux.system = system;}
];
modules = (builtins.attrValues modules) ++ [ { config.aux.system = system; } ];
};
in
result.config.exports.resolved.packages
result.config.exports.resolved.packages

View file

@ -7,34 +7,30 @@
};
};
outputs = inputs: let
inherit (inputs.lib) lib;
outputs =
inputs:
let
inherit (inputs.lib) lib;
modules = import ./src;
modules = import ./src;
forEachSystem = lib.attrs.generate [
"i686-linux"
];
in {
extras = let
result = lib.modules.run {
modules =
builtins.attrValues modules;
};
forEachSystem = lib.attrs.generate [ "i686-linux" ];
in
result.config.exports.resolved.extras;
{
extras =
let
result = lib.modules.run { modules = builtins.attrValues modules; };
in
result.config.exports.resolved.extras;
packages = forEachSystem (
system: let
result = lib.modules.run {
modules =
(builtins.attrValues modules)
++ [
{config.aux.system = system;}
];
};
in
packages = forEachSystem (
system:
let
result = lib.modules.run {
modules = (builtins.attrValues modules) ++ [ { config.aux.system = system; } ];
};
in
result.config.exports.resolved.packages
);
};
);
};
}

View file

@ -25,54 +25,51 @@ let
./src/versions/default.test.nix
];
resolve = file: let
imported = import file;
value =
if builtins.isFunction imported
then imported {inherit lib;}
else imported;
relative = lib.strings.removePrefix (builtins.toString root) (builtins.toString file);
in {
inherit file value;
relative =
if lib.strings.hasPrefix "/" relative
then "." + relative
else relative;
namespace = getNamespace file;
};
resolve =
file:
let
imported = import file;
value = if builtins.isFunction imported then imported { inherit lib; } else imported;
relative = lib.strings.removePrefix (builtins.toString root) (builtins.toString file);
in
{
inherit file value;
relative = if lib.strings.hasPrefix "/" relative then "." + relative else relative;
namespace = getNamespace file;
};
resolved = builtins.map resolve files;
getNamespace = path: let
relative = lib.strings.removePrefix (builtins.toString root) (builtins.toString path);
parts = lib.strings.split "/" relative;
in
if builtins.length parts > 2
then builtins.elemAt parts 2
else relative;
results = let
getTests = file: prefix: suite: let
nested = lib.attrs.mapToList (name: value: getTests file (prefix ++ [name]) value) suite;
relative = lib.strings.removePrefix (builtins.toString root) (builtins.toString file);
getNamespace =
path:
let
relative = lib.strings.removePrefix (builtins.toString root) (builtins.toString path);
parts = lib.strings.split "/" relative;
in
if builtins.isAttrs suite
then builtins.concatLists nested
else [
{
inherit prefix file;
name = builtins.concatStringsSep " > " prefix;
value = suite;
relative =
if lib.strings.hasPrefix "/" relative
then "." + relative
else relative;
}
];
if builtins.length parts > 2 then builtins.elemAt parts 2 else relative;
base =
builtins.map (entry: getTests entry.file [entry.namespace] entry.value) resolved;
in
results =
let
getTests =
file: prefix: suite:
let
nested = lib.attrs.mapToList (name: value: getTests file (prefix ++ [ name ]) value) suite;
relative = lib.strings.removePrefix (builtins.toString root) (builtins.toString file);
in
if builtins.isAttrs suite then
builtins.concatLists nested
else
[
{
inherit prefix file;
name = builtins.concatStringsSep " > " prefix;
value = suite;
relative = if lib.strings.hasPrefix "/" relative then "." + relative else relative;
}
];
base = builtins.map (entry: getTests entry.file [ entry.namespace ] entry.value) resolved;
in
builtins.concatLists base;
successes = builtins.filter (test: test.value) results;
@ -80,29 +77,23 @@ let
total = "${builtins.toString (builtins.length successes)} / ${builtins.toString (builtins.length results)}";
in
if failures == []
then let
message =
lib.strings.concatMapSep "\n"
(test: " ${test.name}")
successes;
in ''
if failures == [ ] then
let
message = lib.strings.concatMapSep "\n" (test: " ${test.name}") successes;
in
''
SUCCESS (${total})
${message}
''
else let
successMessage =
lib.strings.concatMapSep "\n"
(test: " ${test.name}")
successes;
failureMessage =
lib.strings.concatMapSep "\n\n"
(test:
" ${test.name}\n"
+ " -> ${test.relative}")
failures;
in ''
else
let
successMessage = lib.strings.concatMapSep "\n" (test: " ${test.name}") successes;
failureMessage = lib.strings.concatMapSep "\n\n" (
test: " ${test.name}\n" + " -> ${test.relative}"
) failures;
in
''
FAILURE (${total})
${failureMessage}

View file

@ -1,7 +1,5 @@
{
description = "A NixPkgs library replacement containing helper functions and a module system.";
outputs = _: {
lib = import ./src;
};
outputs = _: { lib = import ./src; };
}

View file

@ -1,27 +1,21 @@
{
lib ? import ./../lib,
foundation ? import ./../foundation {system = "i686-linux";},
}: let
foundation ? import ./../foundation { system = "i686-linux"; },
}:
let
modules = import ./src/modules.nix;
result = lib.modules.run {
modules =
(builtins.attrValues modules)
++ [
./src/export.nix
{
__file__ = ./default.nix;
modules = (builtins.attrValues modules) ++ [
./src/export.nix
{
__file__ = ./default.nix;
options.foundation = lib.options.create {
type = lib.types.attrs.of lib.types.derivation;
};
options.foundation = lib.options.create { type = lib.types.attrs.of lib.types.derivation; };
config.foundation = foundation;
}
];
config.foundation = foundation;
}
];
};
in
result.config.exported
// {
inherit (result) config;
}
result.config.exported // { inherit (result) config; }

View file

@ -9,11 +9,13 @@
};
};
outputs = inputs: let
exports = import ./default.nix {
lib = inputs.lib.lib;
foundation = inputs.foundation.packages.i686-linux;
};
in
outputs =
inputs:
let
exports = import ./default.nix {
lib = inputs.lib.lib;
foundation = inputs.foundation.packages.i686-linux;
};
in
exports;
}