refactor: add formatting script
This commit is contained in:
parent
403420fd4b
commit
3479354ec9
4
format.sh
Executable file
4
format.sh
Executable 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
|
|
@ -1,14 +1,13 @@
|
||||||
{system ? builtins.currentSystem}: let
|
{
|
||||||
|
system ? builtins.currentSystem,
|
||||||
|
}:
|
||||||
|
let
|
||||||
lib = import ./../lib;
|
lib = import ./../lib;
|
||||||
|
|
||||||
modules = import ./src;
|
modules = import ./src;
|
||||||
|
|
||||||
result = lib.modules.run {
|
result = lib.modules.run {
|
||||||
modules =
|
modules = (builtins.attrValues modules) ++ [ { config.aux.system = system; } ];
|
||||||
(builtins.attrValues modules)
|
|
||||||
++ [
|
|
||||||
{config.aux.system = system;}
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
result.config.exports.resolved.packages
|
result.config.exports.resolved.packages
|
||||||
|
|
|
@ -7,31 +7,27 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = inputs: let
|
outputs =
|
||||||
|
inputs:
|
||||||
|
let
|
||||||
inherit (inputs.lib) lib;
|
inherit (inputs.lib) lib;
|
||||||
|
|
||||||
modules = import ./src;
|
modules = import ./src;
|
||||||
|
|
||||||
forEachSystem = lib.attrs.generate [
|
forEachSystem = lib.attrs.generate [ "i686-linux" ];
|
||||||
"i686-linux"
|
in
|
||||||
];
|
{
|
||||||
in {
|
extras =
|
||||||
extras = let
|
let
|
||||||
result = lib.modules.run {
|
result = lib.modules.run { modules = builtins.attrValues modules; };
|
||||||
modules =
|
|
||||||
builtins.attrValues modules;
|
|
||||||
};
|
|
||||||
in
|
in
|
||||||
result.config.exports.resolved.extras;
|
result.config.exports.resolved.extras;
|
||||||
|
|
||||||
packages = forEachSystem (
|
packages = forEachSystem (
|
||||||
system: let
|
system:
|
||||||
|
let
|
||||||
result = lib.modules.run {
|
result = lib.modules.run {
|
||||||
modules =
|
modules = (builtins.attrValues modules) ++ [ { config.aux.system = system; } ];
|
||||||
(builtins.attrValues modules)
|
|
||||||
++ [
|
|
||||||
{config.aux.system = system;}
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
result.config.exports.resolved.packages
|
result.config.exports.resolved.packages
|
||||||
|
|
|
@ -25,53 +25,50 @@ let
|
||||||
./src/versions/default.test.nix
|
./src/versions/default.test.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
resolve = file: let
|
resolve =
|
||||||
|
file:
|
||||||
|
let
|
||||||
imported = import file;
|
imported = import file;
|
||||||
value =
|
value = if builtins.isFunction imported then imported { inherit lib; } else imported;
|
||||||
if builtins.isFunction imported
|
|
||||||
then imported {inherit lib;}
|
|
||||||
else imported;
|
|
||||||
relative = lib.strings.removePrefix (builtins.toString root) (builtins.toString file);
|
relative = lib.strings.removePrefix (builtins.toString root) (builtins.toString file);
|
||||||
in {
|
in
|
||||||
|
{
|
||||||
inherit file value;
|
inherit file value;
|
||||||
relative =
|
relative = if lib.strings.hasPrefix "/" relative then "." + relative else relative;
|
||||||
if lib.strings.hasPrefix "/" relative
|
|
||||||
then "." + relative
|
|
||||||
else relative;
|
|
||||||
namespace = getNamespace file;
|
namespace = getNamespace file;
|
||||||
};
|
};
|
||||||
|
|
||||||
resolved = builtins.map resolve files;
|
resolved = builtins.map resolve files;
|
||||||
|
|
||||||
getNamespace = path: let
|
getNamespace =
|
||||||
|
path:
|
||||||
|
let
|
||||||
relative = lib.strings.removePrefix (builtins.toString root) (builtins.toString path);
|
relative = lib.strings.removePrefix (builtins.toString root) (builtins.toString path);
|
||||||
parts = lib.strings.split "/" relative;
|
parts = lib.strings.split "/" relative;
|
||||||
in
|
in
|
||||||
if builtins.length parts > 2
|
if builtins.length parts > 2 then builtins.elemAt parts 2 else relative;
|
||||||
then builtins.elemAt parts 2
|
|
||||||
else relative;
|
|
||||||
|
|
||||||
results = let
|
results =
|
||||||
getTests = file: prefix: suite: let
|
let
|
||||||
|
getTests =
|
||||||
|
file: prefix: suite:
|
||||||
|
let
|
||||||
nested = lib.attrs.mapToList (name: value: getTests file (prefix ++ [ name ]) value) suite;
|
nested = lib.attrs.mapToList (name: value: getTests file (prefix ++ [ name ]) value) suite;
|
||||||
relative = lib.strings.removePrefix (builtins.toString root) (builtins.toString file);
|
relative = lib.strings.removePrefix (builtins.toString root) (builtins.toString file);
|
||||||
in
|
in
|
||||||
if builtins.isAttrs suite
|
if builtins.isAttrs suite then
|
||||||
then builtins.concatLists nested
|
builtins.concatLists nested
|
||||||
else [
|
else
|
||||||
|
[
|
||||||
{
|
{
|
||||||
inherit prefix file;
|
inherit prefix file;
|
||||||
name = builtins.concatStringsSep " > " prefix;
|
name = builtins.concatStringsSep " > " prefix;
|
||||||
value = suite;
|
value = suite;
|
||||||
relative =
|
relative = if lib.strings.hasPrefix "/" relative then "." + relative else relative;
|
||||||
if lib.strings.hasPrefix "/" relative
|
|
||||||
then "." + relative
|
|
||||||
else relative;
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
base =
|
base = builtins.map (entry: getTests entry.file [ entry.namespace ] entry.value) resolved;
|
||||||
builtins.map (entry: getTests entry.file [entry.namespace] entry.value) resolved;
|
|
||||||
in
|
in
|
||||||
builtins.concatLists base;
|
builtins.concatLists base;
|
||||||
|
|
||||||
|
@ -80,29 +77,23 @@ let
|
||||||
|
|
||||||
total = "${builtins.toString (builtins.length successes)} / ${builtins.toString (builtins.length results)}";
|
total = "${builtins.toString (builtins.length successes)} / ${builtins.toString (builtins.length results)}";
|
||||||
in
|
in
|
||||||
if failures == []
|
if failures == [ ] then
|
||||||
then let
|
let
|
||||||
message =
|
message = lib.strings.concatMapSep "\n" (test: "✅ ${test.name}") successes;
|
||||||
lib.strings.concatMapSep "\n"
|
in
|
||||||
(test: "✅ ${test.name}")
|
''
|
||||||
successes;
|
|
||||||
in ''
|
|
||||||
SUCCESS (${total})
|
SUCCESS (${total})
|
||||||
|
|
||||||
${message}
|
${message}
|
||||||
''
|
''
|
||||||
else let
|
else
|
||||||
successMessage =
|
let
|
||||||
lib.strings.concatMapSep "\n"
|
successMessage = lib.strings.concatMapSep "\n" (test: "✅ ${test.name}") successes;
|
||||||
(test: "✅ ${test.name}")
|
failureMessage = lib.strings.concatMapSep "\n\n" (
|
||||||
successes;
|
test: "❎ ${test.name}\n" + " -> ${test.relative}"
|
||||||
failureMessage =
|
) failures;
|
||||||
lib.strings.concatMapSep "\n\n"
|
in
|
||||||
(test:
|
''
|
||||||
"❎ ${test.name}\n"
|
|
||||||
+ " -> ${test.relative}")
|
|
||||||
failures;
|
|
||||||
in ''
|
|
||||||
FAILURE (${total})
|
FAILURE (${total})
|
||||||
|
|
||||||
${failureMessage}
|
${failureMessage}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
{
|
{
|
||||||
description = "A NixPkgs library replacement containing helper functions and a module system.";
|
description = "A NixPkgs library replacement containing helper functions and a module system.";
|
||||||
|
|
||||||
outputs = _: {
|
outputs = _: { lib = import ./src; };
|
||||||
lib = import ./src;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,27 +1,21 @@
|
||||||
{
|
{
|
||||||
lib ? import ./../lib,
|
lib ? import ./../lib,
|
||||||
foundation ? import ./../foundation { system = "i686-linux"; },
|
foundation ? import ./../foundation { system = "i686-linux"; },
|
||||||
}: let
|
}:
|
||||||
|
let
|
||||||
modules = import ./src/modules.nix;
|
modules = import ./src/modules.nix;
|
||||||
|
|
||||||
result = lib.modules.run {
|
result = lib.modules.run {
|
||||||
modules =
|
modules = (builtins.attrValues modules) ++ [
|
||||||
(builtins.attrValues modules)
|
|
||||||
++ [
|
|
||||||
./src/export.nix
|
./src/export.nix
|
||||||
{
|
{
|
||||||
__file__ = ./default.nix;
|
__file__ = ./default.nix;
|
||||||
|
|
||||||
options.foundation = lib.options.create {
|
options.foundation = lib.options.create { type = lib.types.attrs.of lib.types.derivation; };
|
||||||
type = lib.types.attrs.of lib.types.derivation;
|
|
||||||
};
|
|
||||||
|
|
||||||
config.foundation = foundation;
|
config.foundation = foundation;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
result.config.exported
|
result.config.exported // { inherit (result) config; }
|
||||||
// {
|
|
||||||
inherit (result) config;
|
|
||||||
}
|
|
||||||
|
|
|
@ -9,7 +9,9 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = inputs: let
|
outputs =
|
||||||
|
inputs:
|
||||||
|
let
|
||||||
exports = import ./default.nix {
|
exports = import ./default.nix {
|
||||||
lib = inputs.lib.lib;
|
lib = inputs.lib.lib;
|
||||||
foundation = inputs.foundation.packages.i686-linux;
|
foundation = inputs.foundation.packages.i686-linux;
|
||||||
|
|
Loading…
Reference in a new issue