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 untrusted user: 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

View file

@ -7,31 +7,27 @@
};
};
outputs = inputs: let
outputs =
inputs:
let
inherit (inputs.lib) lib;
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
{
extras =
let
result = lib.modules.run { modules = builtins.attrValues modules; };
in
result.config.exports.resolved.extras;
packages = forEachSystem (
system: let
system:
let
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

View file

@ -25,53 +25,50 @@ let
./src/versions/default.test.nix
];
resolve = file: let
resolve =
file:
let
imported = import file;
value =
if builtins.isFunction imported
then imported {inherit lib;}
else imported;
value = if builtins.isFunction imported then imported { inherit lib; } else imported;
relative = lib.strings.removePrefix (builtins.toString root) (builtins.toString file);
in {
in
{
inherit file value;
relative =
if lib.strings.hasPrefix "/" relative
then "." + relative
else relative;
relative = if lib.strings.hasPrefix "/" relative then "." + relative else relative;
namespace = getNamespace file;
};
resolved = builtins.map resolve files;
getNamespace = path: let
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;
if builtins.length parts > 2 then builtins.elemAt parts 2 else relative;
results = let
getTests = file: prefix: suite: let
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 [
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;
relative = if lib.strings.hasPrefix "/" relative then "." + relative else relative;
}
];
base =
builtins.map (entry: getTests entry.file [entry.namespace] entry.value) resolved;
base = builtins.map (entry: getTests entry.file [ entry.namespace ] entry.value) resolved;
in
builtins.concatLists base;
@ -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
}:
let
modules = import ./src/modules.nix;
result = lib.modules.run {
modules =
(builtins.attrValues modules)
++ [
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;
}
];
};
in
result.config.exported
// {
inherit (result) config;
}
result.config.exported // { inherit (result) config; }

View file

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