1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-08 11:36:05 +01:00

formatter: remove script, add treefmt.toml + keep-sorted (#7056)

currently ./format does a bunch of stuff with git that was only necessary for nixfmt but not nixfmt-tree, so I deleted it (just use treefmt command directly instead). I also added keep sorted to keep the really long module lists sorted (already used in nixpkgs).
This commit is contained in:
awwpotato 2025-05-20 10:42:51 -07:00 committed by GitHub
parent 559f6d36b3
commit 3f591550a9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 494 additions and 503 deletions

View file

@ -21,7 +21,8 @@ Also make sure to read the guidelines found at
- [ ] Change is backwards compatible.
- [ ] Code formatted with `nix fmt` or `./format`.
- [ ] Code formatted with `nix fmt` or
`nix-shell -p treefmt nixfmt-rfc-style keep-sorted --run treefmt`.
- [ ] Code tested through `nix-shell --pure tests -A run.all`
or `nix build --reference-lock-file flake.lock ./tests#test-all` using Flakes.

View file

@ -23,7 +23,7 @@ jobs:
exit 1
fi
- run: nix-build --show-trace -A docs.jsonModuleMaintainers
- run: ./format --ci
- run: nix fmt -- --ci
- run: nix-shell --show-trace . -A install
- run: yes | home-manager -I home-manager=. uninstall
- name: Run tests

View file

@ -17,4 +17,4 @@ test-install:
HOME=$(shell mktemp -d) NIX_PATH=${NIX_PATH} nix-shell . -A install
format:
./format
nix-shell -p treefmt nixfmt-rfc-style keep-sorted --run "treefmt --config-file ./treefmt.toml"

View file

@ -45,22 +45,25 @@
}
// (
let
forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed;
forAllPkgs =
f:
nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed (system: f nixpkgs.legacyPackages.${system});
in
{
formatter = forAllSystems (
system:
nixpkgs.legacyPackages.${system}.nixfmt-tree.override {
settings = {
tree-root-file = "release.json";
};
formatter = forAllPkgs (
pkgs:
pkgs.treefmt.withConfig {
runtimeInputs = with pkgs; [
nixfmt-rfc-style
keep-sorted
];
settings = pkgs.lib.importTOML ./treefmt.toml;
}
);
packages = forAllSystems (
system:
packages = forAllPkgs (
pkgs:
let
pkgs = nixpkgs.legacyPackages.${system};
releaseInfo = nixpkgs.lib.importJSON ./release.json;
docs = import ./docs {
inherit pkgs;

35
format
View file

@ -1,35 +0,0 @@
#! /usr/bin/env nix-shell
#! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/42a1c966be226125b48c384171c44c651c236c22.tar.gz -i bash -p git gnugrep gnused findutils nixfmt-tree
# Avoid being affected by system and user git config.
export GIT_CONFIG_NOSYSTEM=1
export HOME=/var/empty
export XDG_CONFIG_HOME=/var/empty
nixfmt_args=()
files=()
for arg do
case $arg in
-h)
echo "$0 [-c]"
exit
;;
--ci)
nixfmt_args+=("$arg")
;;
-*)
echo "unrecognised flag: $arg" >&2
exit 1
;;
*)
files+=("$arg")
;;
esac
done
git_root=$(git rev-parse --show-toplevel)
git ls-files -z --cached --others --full-name -- "${files[@]}" |
grep -z '\.nix$' |
sed -z "s|^|$git_root/|" |
xargs -0 treefmt --no-cache "${nixfmt_args[@]}"

File diff suppressed because it is too large Load diff

View file

@ -15,11 +15,13 @@ let
modules =
[
./accounts/email.nix
# keep-sorted start case=no numeric=yes
./accounts/calendar.nix
./accounts/contacts.nix
./accounts/email.nix
./config/home-cursor.nix
./config/i18n.nix
./dbus.nix
./files.nix
./home-environment.nix
./i18n/input-method/default.nix
@ -33,6 +35,7 @@ let
./misc/lib.nix
./misc/mozilla-messaging-hosts.nix
./misc/news.nix
./misc/nix.nix
./misc/nixgl.nix
./misc/numlock.nix
./misc/pam.nix
@ -68,10 +71,10 @@ let
./programs/autojump.nix
./programs/autorandr.nix
./programs/awscli.nix
./programs/bacon.nix
./programs/bash.nix
./programs/bashmount.nix
./programs/bat.nix
./programs/bacon.nix
./programs/beets.nix
./programs/bemenu.nix
./programs/borgmatic.nix
@ -107,14 +110,15 @@ let
./programs/firefox.nix
./programs/fish.nix
./programs/floorp.nix
./programs/foliate.nix
./programs/foot.nix
./programs/freetube.nix
./programs/fuzzel.nix
./programs/fzf.nix
./programs/gallery-dl.nix
./programs/getmail.nix
./programs/gh.nix
./programs/gh-dash.nix
./programs/gh.nix
./programs/ghostty.nix
./programs/git-cliff.nix
./programs/git-credential-oauth.nix
@ -149,11 +153,11 @@ let
./programs/irssi.nix
./programs/java.nix
./programs/jetbrains-remote.nix
./programs/joplin-desktop.nix
./programs/joshuto.nix
./programs/jq.nix
./programs/jqp.nix
./programs/jujutsu.nix
./programs/joshuto.nix
./programs/joplin-desktop.nix
./programs/just.nix
./programs/k9s.nix
./programs/kakoune.nix
@ -238,15 +242,17 @@ let
./programs/pubs.nix
./programs/pyenv.nix
./programs/pylint.nix
./programs/pywal.nix
./programs/qcal.nix
./programs/qutebrowser.nix
./programs/ranger.nix
./programs/rbenv.nix
./programs/rbw.nix
./programs/rclone.nix
./programs/readline.nix
./programs/rio.nix
./programs/ripgrep.nix
./programs/ripgrep-all.nix
./programs/ripgrep.nix
./programs/rmpc.nix
./programs/rofi-pass.nix
./programs/rofi.nix
@ -288,8 +294,8 @@ let
./programs/tiny.nix
./programs/tmate.nix
./programs/tmux.nix
./programs/tofi.nix
./programs/todoman.nix
./programs/tofi.nix
./programs/topgrade.nix
./programs/translate-shell.nix
./programs/urxvt.nix
@ -300,16 +306,14 @@ let
./programs/vim-vint.nix
./programs/vim.nix
./programs/vinegar.nix
./programs/visidata.nix
./programs/vscode.nix
./programs/vscode/haskell.nix
./programs/visidata.nix
./programs/pywal.nix
./programs/rbenv.nix
./programs/wallust.nix
./programs/watson.nix
./programs/waveterm.nix
./programs/waylogout.nix
./programs/waybar.nix
./programs/waylogout.nix
./programs/wayprompt.nix
./programs/wezterm.nix
./programs/wlogout.nix
@ -359,12 +363,11 @@ let
./services/dwm-status.nix
./services/easyeffects.nix
./services/emacs.nix
./services/etesync-dav.nix
./services/espanso.nix
./services/etesync-dav.nix
./services/flameshot.nix
./services/fluidsynth.nix
./services/fnott.nix
./programs/foliate.nix
./services/fusuma.nix
./services/getmail.nix
./services/git-sync.nix
@ -398,11 +401,11 @@ let
./services/mbsync.nix
./services/megasync.nix
./services/mopidy.nix
./services/mpd-discord-rpc.nix
./services/mpd-mpris.nix
./services/mpd.nix
./services/mpdris2.nix
./services/mpdscribble.nix
./services/mpd-discord-rpc.nix
./services/mpd-mpris.nix
./services/mpris-proxy.nix
./services/muchsync.nix
./services/network-manager-applet.nix
@ -492,13 +495,12 @@ let
./services/xsuspender.nix
./services/yubikey-agent.nix
./systemd.nix
./dbus.nix
./targets/darwin
./targets/generic-linux.nix
./wayland.nix
./xresources.nix
./xsession.nix
./misc/nix.nix
# keep-sorted end
(pkgs.path + "/nixos/modules/misc/assertions.nix")
(pkgs.path + "/nixos/modules/misc/meta.nix")

View file

@ -4,6 +4,7 @@ let
# List of packages that need to be scrubbed on Darwin
# Packages are scrubbed on Linux and expected in test output
packagesToScrub = [
# keep-sorted start case=no numeric=yes
"aerc"
"aerospace"
"alacritty"
@ -14,9 +15,9 @@ let
"autojump"
"bacon"
"bash"
"bashInteractive"
"bash-completion"
"bash-preexec"
"bashInteractive"
"bat"
"borgmatic"
"bottom"
@ -29,8 +30,8 @@ let
"cmus"
"comodoro"
"darcs"
"dircolors"
"delta"
"dircolors"
"direnv"
"earthly"
"element-desktop"
@ -45,12 +46,11 @@ let
"gh-dash"
"ghostty"
"git"
"patdiff"
"gitMinimal"
"git-cliff"
"git-credential-oauth"
"git-lfs"
"git-worktree-switcher"
"gitMinimal"
"gnupg"
"go"
"gradle"
@ -66,9 +66,9 @@ let
"irssi"
"isync"
"jankyborders"
"jujutsu"
"joplin-desktop"
"jqp"
"jujutsu"
"k9s"
"kakoune"
"khal"
@ -82,16 +82,16 @@ let
"less"
"lesspipe"
"lf"
"lsd"
"lieer"
"lsd"
"mbsync"
"mergiraf"
"micro"
"mise"
"mpv"
"msmtp"
"mu"
"mujmap"
"msmtp"
"ncmpcpp"
"ne"
"neomutt"
@ -112,6 +112,7 @@ let
"onlyoffice-desktopeditors"
"openstackclient"
"papis"
"patdiff"
"pay-respects"
"pet"
"pistol"
@ -164,6 +165,7 @@ let
"zoxide"
"zplug"
"zsh"
# keep-sorted end
];
# Create an overlay that scrubs packages in the scrublist

View file

@ -158,6 +158,7 @@ import nmtSrc {
];
tests = builtins.foldl' (a: b: a // (import b)) { } (
[
# keep-sorted start case=no numeric=yes
./lib/generators
./lib/types
./modules/files
@ -219,9 +220,9 @@ import nmtSrc {
./modules/programs/i3status
./modules/programs/inori
./modules/programs/irssi
./modules/programs/jujutsu
./modules/programs/joplin-desktop
./modules/programs/jqp
./modules/programs/jujutsu
./modules/programs/k9s
./modules/programs/kakoune
./modules/programs/keepassxc
@ -230,13 +231,13 @@ import nmtSrc {
./modules/programs/kitty
./modules/programs/kubecolor
./modules/programs/lapce
./modules/programs/ledger
./modules/programs/lazydocker
./modules/programs/ledger
./modules/programs/less
./modules/programs/lesspipe
./modules/programs/lf
./modules/programs/lsd
./modules/programs/lieer
./modules/programs/lsd
./modules/programs/man
./modules/programs/mbsync
./modules/programs/mergiraf
@ -326,8 +327,10 @@ import nmtSrc {
./modules/services/gpg-agent
./modules/services/syncthing/common
./modules/xresources
# keep-sorted end
]
++ lib.optionals isDarwin [
# keep-sorted start case=no numeric=yes
./modules/launchd
./modules/programs/aerospace
./modules/programs/element-desktop/darwin.nix
@ -344,11 +347,13 @@ import nmtSrc {
./modules/services/skhd
./modules/services/yubikey-agent-darwin
./modules/targets-darwin
# keep-sorted end
]
++ lib.optionals isLinux [
./modules/misc/xdg/linux.nix
# keep-sorted start case=no numeric=yes
./modules/config/home-cursor
./modules/config/i18n
./modules/dbus
./modules/i18n/input-method
./modules/misc/debug
./modules/misc/editorconfig
@ -356,6 +361,7 @@ import nmtSrc {
./modules/misc/numlock
./modules/misc/pam
./modules/misc/qt
./modules/misc/xdg/linux.nix
./modules/misc/xsession
./modules/programs/abook
./modules/programs/anyrun
@ -382,8 +388,8 @@ import nmtSrc {
./modules/programs/i3blocks
./modules/programs/i3status-rust
./modules/programs/imv
./modules/programs/kodi
./modules/programs/kickoff
./modules/programs/kodi
./modules/programs/looking-glass-client
./modules/programs/lutris
./modules/programs/mangohud
@ -423,8 +429,8 @@ import nmtSrc {
./modules/services/clipman
./modules/services/clipse
./modules/services/comodoro
./modules/services/copyq
./modules/services/conky
./modules/services/copyq
./modules/services/darkman
./modules/services/davmail
./modules/services/devilspie2
@ -506,7 +512,7 @@ import nmtSrc {
./modules/services/yubikey-agent
./modules/systemd
./modules/targets-linux
./modules/dbus
# keep-sorted end
]
);
}

10
treefmt.toml Normal file
View file

@ -0,0 +1,10 @@
on-unmatched = "info"
tree-root-file = "release.json"
[formatter.nixfmt]
command = "nixfmt"
includes = [ "*.nix" ]
[formatter.keep-sorted]
command = "keep-sorted"
includes = [ "*" ]