Switch to alejandra for formatting

Use treefmt

For context, see upstream PR: https://github.com/divnix/digga/pull/491
This commit is contained in:
teutat3s 2022-11-20 23:10:39 +01:00
parent f6062d0019
commit 24b8b9f060
Signed by untrusted user: teutat3s
GPG key ID: 4FA1D3FA524F22C1
5 changed files with 151 additions and 115 deletions

View file

@ -1,75 +1,78 @@
{ config, pkgs, lib, ... }:
with lib;
let
{
config,
pkgs,
lib,
...
}:
with lib; let
psCfg = config.pub-solar;
cfg = config.pub-solar.core;
in
{
in {
environment = {
systemPackages = with pkgs; [
# Core unix utility packages
coreutils-full
dnsutils
inetutils
progress
pciutils
usbutils
systemPackages = with pkgs;
[
# Core unix utility packages
coreutils-full
dnsutils
inetutils
progress
pciutils
usbutils
wget
openssl
openssh
curl
htop
lsof
psmisc
file
wget
openssl
openssh
curl
htop
lsof
psmisc
file
# zippit
zip
unzip
# zippit
zip
unzip
# Modern modern utilities
p7zip
croc
jq
]
# Modern modern utilities
p7zip
croc
jq
]
++ lib.optionals (!cfg.lite) [
mtr
++ lib.optionals (!cfg.lite) [
mtr
gitFull
git-lfs
git-bug
gitFull
git-lfs
git-bug
xdg-utils
sysfsutils
renameutils
nfs-utils
moreutils
mailutils
keyutils
input-utils
elfutils
binutils
dateutils
diffutils
findutils
exfat
xdg-utils
sysfsutils
renameutils
nfs-utils
moreutils
mailutils
keyutils
input-utils
elfutils
binutils
dateutils
diffutils
findutils
exfat
# Nix specific utilities
alejandra
niv
manix
nix-index
nix-tree
nixpkgs-review
# Build broken, python2.7-PyJWT-2.0.1.drv' failed
#nixops
psos
nvd
# Nix specific utilities
niv
manix
nix-index
nix-tree
nixpkgs-review
# Build broken, python2.7-PyJWT-2.0.1.drv' failed
#nixops
psos
nvd
# Fun
neofetch
];
# Fun
neofetch
];
};
}

View file

@ -1,36 +1,37 @@
channels: final: prev: {
__dontExport = true; # overrides clutter up actual creations
inherit (channels.latest)
inherit
(channels.latest)
cachix
dhall
discord
element-desktop
rage
nix-index
nixpkgs-fmt
qutebrowser
alejandra
signal-desktop
starship
deploy-rs
nix
tdesktop
arduino
arduino-cli
;
haskellPackages = prev.haskellPackages.override
haskellPackages =
prev.haskellPackages.override
(old: {
overrides = prev.lib.composeExtensions (old.overrides or (_: _: { })) (hfinal: hprev:
let version = prev.lib.replaceChars [ "." ] [ "" ] prev.ghc.version;
in
{
# same for haskell packages, matching ghc versions
inherit (channels.latest.haskell.packages."ghc${version}")
haskell-language-server;
});
overrides = prev.lib.composeExtensions (old.overrides or (_: _: {})) (hfinal: hprev: let
version = prev.lib.replaceChars ["."] [""] prev.ghc.version;
in {
# same for haskell packages, matching ghc versions
inherit
(channels.latest.haskell.packages."ghc${version}")
haskell-language-server
;
});
});
}

View file

@ -1,29 +1,40 @@
{ pkgs, extraModulesPath, inputs, lib, ... }:
let
inherit (pkgs)
{
pkgs,
extraModulesPath,
inputs,
lib,
...
}: let
inherit
(pkgs)
agenix
cachix
editorconfig-checker
mdbook
nix
nixpkgs-fmt
alejandra
nvfetcher
shellcheck
shfmt
treefmt
;
inherit
(pkgs.nodePackages)
prettier
;
hooks = import ./hooks;
pkgWithCategory = category: package: { inherit package category; };
pkgWithCategory = category: package: {inherit package category;};
devos = pkgWithCategory "devos";
linter = pkgWithCategory "linter";
docs = pkgWithCategory "docs";
in
{
in {
_file = toString ./.;
imports = [ "${extraModulesPath}/git/hooks.nix" ];
git = { inherit hooks; };
imports = ["${extraModulesPath}/git/hooks.nix"];
git = {inherit hooks;};
# override for our own welcome
devshell.name = pkgs.lib.mkForce "PubSolarOS";
@ -37,17 +48,20 @@ in
help = pkgs.nvfetcher.meta.description;
command = "cd $PRJ_ROOT/pkgs; ${pkgs.nvfetcher}/bin/nvfetcher -c ./sources.toml $@";
}
(linter nixpkgs-fmt)
(linter editorconfig-checker)
(linter alejandra)
(linter editorconfig-checker)
(linter nodePackages.prettier)
(linter shfmt)
(linter shellcheck)
(linter treefmt)
(docs mdbook)
]
++ lib.optionals (!pkgs.stdenv.buildPlatform.isi686) [
(devos cachix)
]
++ lib.optionals (pkgs.stdenv.hostPlatform.isLinux && !pkgs.stdenv.buildPlatform.isDarwin) [
(devos inputs.nixos-generators.defaultPackage.${pkgs.system})
(devos deploy-rs)
]
;
(docs mdbook)
]
++ lib.optionals (!pkgs.stdenv.buildPlatform.isi686) [
(devos cachix)
]
++ lib.optionals (pkgs.stdenv.hostPlatform.isLinux && !pkgs.stdenv.buildPlatform.isDarwin) [
(devos inputs.nixos-generators.defaultPackage.${pkgs.system})
(devos deploy-rs)
];
}

View file

@ -1,7 +1,6 @@
#!/usr/bin/env bash
if git rev-parse --verify HEAD >/dev/null 2>&1
then
if git rev-parse --verify HEAD >/dev/null 2>&1; then
against=HEAD
else
# Initial commit: diff against an empty tree object
@ -10,23 +9,20 @@ fi
diff="git diff-index --name-only --cached $against --diff-filter d"
nix_files=($($diff -- '*.nix'))
all_files=($($diff))
# Format staged nix files.
if (( ${#nix_files[@]} != 0 )); then
nixpkgs-fmt "${nix_files[@]}" \
&& git add "${nix_files[@]}"
# Format staged files.
if ((${#all_files[@]} != 0)); then
treefmt "${all_files[@]}" &&
git add "${all_files[@]}"
fi
# check editorconfig
if (( ${#all_files[@]} != 0 )); then
editorconfig-checker -- "${all_files[@]}"
fi
if [[ $? != '0' ]]; then
printf "%b\n" \
"\nCode is not aligned with .editorconfig" \
"Review the output and commit your fixes" >&2
exit 1
if ((${#all_files[@]} != 0)); then
if ! editorconfig-checker -- "${all_files[@]}"; then
printf "%b\n" \
"\nCode is not aligned with .editorconfig" \
"Review the output and commit your fixes" >&2
exit 1
fi
fi

22
treefmt.toml Normal file
View file

@ -0,0 +1,22 @@
[formatter.nix]
command = "alejandra"
includes = ["*.nix"]
[formatter.prettier]
command = "prettier"
options = ["--write"]
includes = [
"*.json",
"*.yaml",
"*.md",
]
[formatter.shell]
command = "shfmt"
options = [
"-s",
"-w",
"-i",
"2",
]
includes = ["*.sh"]