style: Switch to nixfmt from nixpkgs-fmt

Most of the ecosystem has moved to this formatter,
and many people configured their editors to autoformat it with this formatter.

Closes: https://git.snix.dev/snix/snix/issues/62
Change-Id: Icf39e7836c91fc2ae49fbe22a40a639105bfb0bd
Reviewed-on: https://cl.snix.dev/c/snix/+/30671
Reviewed-by: Florian Klink <flokli@flokli.de>
Tested-by: besadii
Autosubmit: Ilan Joselevich <personal@ilanjoselevich.com>
This commit is contained in:
Ilan Joselevich 2025-08-09 21:08:41 +02:00
parent 3443e6bd08
commit 91d02d8c84
136 changed files with 39952 additions and 11007 deletions

View file

@ -17,75 +17,82 @@ let
# Create the case statement for a command invocations, optionally
# overriding the `TARGET_TOOL` variable.
invoke = name: { attr, cmd ? null }: ''
${name})
attr="${attr}"
${if cmd != null then "TARGET_TOOL=\"${cmd}\"\n;;" else ";;"}
'';
invoke =
name:
{
attr,
cmd ? null,
}:
''
${name})
attr="${attr}"
${if cmd != null then "TARGET_TOOL=\"${cmd}\"\n;;" else ";;"}
'';
# Create command to symlink to the dispatch script for each tool.
link = name: "ln -s $target $out/bin/${name}";
invocations = tools: concatStringsSep "\n" (attrValues (mapAttrs invoke tools));
in
fix (self:
fix (
self:
# Attribute set of tools that should be lazily-added to the $PATH.
#
# The name of each attribute is used as the command name (on $PATH).
# It must contain the keys 'attr' (containing the Nix attribute path
# to the tool's derivation from the top-level), and may optionally
# contain the key 'cmd' to override the name of the binary inside the
# derivation.
tools:
# Attribute set of tools that should be lazily-added to the $PATH.
#
# The name of each attribute is used as the command name (on $PATH).
# It must contain the keys 'attr' (containing the Nix attribute path
# to the tool's derivation from the top-level), and may optionally
# contain the key 'cmd' to override the name of the binary inside the
# derivation.
tools:
pkgs.runCommandNoCC "lazy-dispatch"
{
passthru.overrideDeps = newTools: self (tools // newTools);
passthru.tools = tools;
pkgs.runCommandNoCC "lazy-dispatch"
{
passthru.overrideDeps = newTools: self (tools // newTools);
passthru.tools = tools;
text = ''
#!${pkgs.runtimeShell}
set -ue
text = ''
#!${pkgs.runtimeShell}
set -ue
if ! type git>/dev/null || ! type nix-build>/dev/null; then
echo "The 'git' and 'nix-build' commands must be available." >&2
exit 127
fi
if ! type git>/dev/null || ! type nix-build>/dev/null; then
echo "The 'git' and 'nix-build' commands must be available." >&2
exit 127
fi
readonly REPO_ROOT=$(git rev-parse --show-toplevel)
TARGET_TOOL=$(basename "$0")
readonly REPO_ROOT=$(git rev-parse --show-toplevel)
TARGET_TOOL=$(basename "$0")
case "''${TARGET_TOOL}" in
${invocations tools}
*)
echo "''${TARGET_TOOL} is currently not installed in this repository." >&2
exit 127
;;
esac
case "''${TARGET_TOOL}" in
${invocations tools}
*)
echo "''${TARGET_TOOL} is currently not installed in this repository." >&2
exit 127
;;
esac
result=$(nix-build --no-out-link --attr "''${attr}" "''${REPO_ROOT}")
PATH="''${result}/bin:$PATH"
exec "''${TARGET_TOOL}" "''${@}"
'';
result=$(nix-build --no-out-link --attr "''${attr}" "''${REPO_ROOT}")
PATH="''${result}/bin:$PATH"
exec "''${TARGET_TOOL}" "''${@}"
'';
# Access this to get a compatible nix-shell
passthru.devShell = pkgs.mkShellNoCC {
name = "${self.name}-shell";
packages = [ self ];
};
}
''
# Write the dispatch code
target=$out/bin/__dispatch
mkdir -p "$(dirname "$target")"
echo "$text" > $target
chmod +x $target
# Access this to get a compatible nix-shell
passthru.devShell = pkgs.mkShellNoCC {
name = "${self.name}-shell";
packages = [ self ];
};
}
''
# Write the dispatch code
target=$out/bin/__dispatch
mkdir -p "$(dirname "$target")"
echo "$text" > $target
chmod +x $target
# Add symlinks from all the tools to the dispatch
${concatStringsSep "\n" (map link (attrNames tools))}
# Add symlinks from all the tools to the dispatch
${concatStringsSep "\n" (map link (attrNames tools))}
# Check that it's working-ish
${pkgs.stdenv.shellDryRun} $target
''
# Check that it's working-ish
${pkgs.stdenv.shellDryRun} $target
''
)