1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-08 19:46: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. - [ ] 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` - [ ] Code tested through `nix-shell --pure tests -A run.all`
or `nix build --reference-lock-file flake.lock ./tests#test-all` using Flakes. or `nix build --reference-lock-file flake.lock ./tests#test-all` using Flakes.

View file

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

View file

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

View file

@ -45,22 +45,25 @@
} }
// ( // (
let let
forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed; forAllPkgs =
f:
nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed (system: f nixpkgs.legacyPackages.${system});
in in
{ {
formatter = forAllSystems ( formatter = forAllPkgs (
system: pkgs:
nixpkgs.legacyPackages.${system}.nixfmt-tree.override { pkgs.treefmt.withConfig {
settings = { runtimeInputs = with pkgs; [
tree-root-file = "release.json"; nixfmt-rfc-style
}; keep-sorted
];
settings = pkgs.lib.importTOML ./treefmt.toml;
} }
); );
packages = forAllSystems ( packages = forAllPkgs (
system: pkgs:
let let
pkgs = nixpkgs.legacyPackages.${system};
releaseInfo = nixpkgs.lib.importJSON ./release.json; releaseInfo = nixpkgs.lib.importJSON ./release.json;
docs = import ./docs { docs = import ./docs {
inherit pkgs; 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 = modules =
[ [
./accounts/email.nix # keep-sorted start case=no numeric=yes
./accounts/calendar.nix ./accounts/calendar.nix
./accounts/contacts.nix ./accounts/contacts.nix
./accounts/email.nix
./config/home-cursor.nix ./config/home-cursor.nix
./config/i18n.nix ./config/i18n.nix
./dbus.nix
./files.nix ./files.nix
./home-environment.nix ./home-environment.nix
./i18n/input-method/default.nix ./i18n/input-method/default.nix
@ -33,6 +35,7 @@ let
./misc/lib.nix ./misc/lib.nix
./misc/mozilla-messaging-hosts.nix ./misc/mozilla-messaging-hosts.nix
./misc/news.nix ./misc/news.nix
./misc/nix.nix
./misc/nixgl.nix ./misc/nixgl.nix
./misc/numlock.nix ./misc/numlock.nix
./misc/pam.nix ./misc/pam.nix
@ -68,10 +71,10 @@ let
./programs/autojump.nix ./programs/autojump.nix
./programs/autorandr.nix ./programs/autorandr.nix
./programs/awscli.nix ./programs/awscli.nix
./programs/bacon.nix
./programs/bash.nix ./programs/bash.nix
./programs/bashmount.nix ./programs/bashmount.nix
./programs/bat.nix ./programs/bat.nix
./programs/bacon.nix
./programs/beets.nix ./programs/beets.nix
./programs/bemenu.nix ./programs/bemenu.nix
./programs/borgmatic.nix ./programs/borgmatic.nix
@ -107,14 +110,15 @@ let
./programs/firefox.nix ./programs/firefox.nix
./programs/fish.nix ./programs/fish.nix
./programs/floorp.nix ./programs/floorp.nix
./programs/foliate.nix
./programs/foot.nix ./programs/foot.nix
./programs/freetube.nix ./programs/freetube.nix
./programs/fuzzel.nix ./programs/fuzzel.nix
./programs/fzf.nix ./programs/fzf.nix
./programs/gallery-dl.nix ./programs/gallery-dl.nix
./programs/getmail.nix ./programs/getmail.nix
./programs/gh.nix
./programs/gh-dash.nix ./programs/gh-dash.nix
./programs/gh.nix
./programs/ghostty.nix ./programs/ghostty.nix
./programs/git-cliff.nix ./programs/git-cliff.nix
./programs/git-credential-oauth.nix ./programs/git-credential-oauth.nix
@ -149,11 +153,11 @@ let
./programs/irssi.nix ./programs/irssi.nix
./programs/java.nix ./programs/java.nix
./programs/jetbrains-remote.nix ./programs/jetbrains-remote.nix
./programs/joplin-desktop.nix
./programs/joshuto.nix
./programs/jq.nix ./programs/jq.nix
./programs/jqp.nix ./programs/jqp.nix
./programs/jujutsu.nix ./programs/jujutsu.nix
./programs/joshuto.nix
./programs/joplin-desktop.nix
./programs/just.nix ./programs/just.nix
./programs/k9s.nix ./programs/k9s.nix
./programs/kakoune.nix ./programs/kakoune.nix
@ -238,15 +242,17 @@ let
./programs/pubs.nix ./programs/pubs.nix
./programs/pyenv.nix ./programs/pyenv.nix
./programs/pylint.nix ./programs/pylint.nix
./programs/pywal.nix
./programs/qcal.nix ./programs/qcal.nix
./programs/qutebrowser.nix ./programs/qutebrowser.nix
./programs/ranger.nix ./programs/ranger.nix
./programs/rbenv.nix
./programs/rbw.nix ./programs/rbw.nix
./programs/rclone.nix ./programs/rclone.nix
./programs/readline.nix ./programs/readline.nix
./programs/rio.nix ./programs/rio.nix
./programs/ripgrep.nix
./programs/ripgrep-all.nix ./programs/ripgrep-all.nix
./programs/ripgrep.nix
./programs/rmpc.nix ./programs/rmpc.nix
./programs/rofi-pass.nix ./programs/rofi-pass.nix
./programs/rofi.nix ./programs/rofi.nix
@ -288,8 +294,8 @@ let
./programs/tiny.nix ./programs/tiny.nix
./programs/tmate.nix ./programs/tmate.nix
./programs/tmux.nix ./programs/tmux.nix
./programs/tofi.nix
./programs/todoman.nix ./programs/todoman.nix
./programs/tofi.nix
./programs/topgrade.nix ./programs/topgrade.nix
./programs/translate-shell.nix ./programs/translate-shell.nix
./programs/urxvt.nix ./programs/urxvt.nix
@ -300,16 +306,14 @@ let
./programs/vim-vint.nix ./programs/vim-vint.nix
./programs/vim.nix ./programs/vim.nix
./programs/vinegar.nix ./programs/vinegar.nix
./programs/visidata.nix
./programs/vscode.nix ./programs/vscode.nix
./programs/vscode/haskell.nix ./programs/vscode/haskell.nix
./programs/visidata.nix
./programs/pywal.nix
./programs/rbenv.nix
./programs/wallust.nix ./programs/wallust.nix
./programs/watson.nix ./programs/watson.nix
./programs/waveterm.nix ./programs/waveterm.nix
./programs/waylogout.nix
./programs/waybar.nix ./programs/waybar.nix
./programs/waylogout.nix
./programs/wayprompt.nix ./programs/wayprompt.nix
./programs/wezterm.nix ./programs/wezterm.nix
./programs/wlogout.nix ./programs/wlogout.nix
@ -359,12 +363,11 @@ let
./services/dwm-status.nix ./services/dwm-status.nix
./services/easyeffects.nix ./services/easyeffects.nix
./services/emacs.nix ./services/emacs.nix
./services/etesync-dav.nix
./services/espanso.nix ./services/espanso.nix
./services/etesync-dav.nix
./services/flameshot.nix ./services/flameshot.nix
./services/fluidsynth.nix ./services/fluidsynth.nix
./services/fnott.nix ./services/fnott.nix
./programs/foliate.nix
./services/fusuma.nix ./services/fusuma.nix
./services/getmail.nix ./services/getmail.nix
./services/git-sync.nix ./services/git-sync.nix
@ -398,11 +401,11 @@ let
./services/mbsync.nix ./services/mbsync.nix
./services/megasync.nix ./services/megasync.nix
./services/mopidy.nix ./services/mopidy.nix
./services/mpd-discord-rpc.nix
./services/mpd-mpris.nix
./services/mpd.nix ./services/mpd.nix
./services/mpdris2.nix ./services/mpdris2.nix
./services/mpdscribble.nix ./services/mpdscribble.nix
./services/mpd-discord-rpc.nix
./services/mpd-mpris.nix
./services/mpris-proxy.nix ./services/mpris-proxy.nix
./services/muchsync.nix ./services/muchsync.nix
./services/network-manager-applet.nix ./services/network-manager-applet.nix
@ -492,13 +495,12 @@ let
./services/xsuspender.nix ./services/xsuspender.nix
./services/yubikey-agent.nix ./services/yubikey-agent.nix
./systemd.nix ./systemd.nix
./dbus.nix
./targets/darwin ./targets/darwin
./targets/generic-linux.nix ./targets/generic-linux.nix
./wayland.nix ./wayland.nix
./xresources.nix ./xresources.nix
./xsession.nix ./xsession.nix
./misc/nix.nix # keep-sorted end
(pkgs.path + "/nixos/modules/misc/assertions.nix") (pkgs.path + "/nixos/modules/misc/assertions.nix")
(pkgs.path + "/nixos/modules/misc/meta.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 # List of packages that need to be scrubbed on Darwin
# Packages are scrubbed on Linux and expected in test output # Packages are scrubbed on Linux and expected in test output
packagesToScrub = [ packagesToScrub = [
# keep-sorted start case=no numeric=yes
"aerc" "aerc"
"aerospace" "aerospace"
"alacritty" "alacritty"
@ -14,9 +15,9 @@ let
"autojump" "autojump"
"bacon" "bacon"
"bash" "bash"
"bashInteractive"
"bash-completion" "bash-completion"
"bash-preexec" "bash-preexec"
"bashInteractive"
"bat" "bat"
"borgmatic" "borgmatic"
"bottom" "bottom"
@ -29,8 +30,8 @@ let
"cmus" "cmus"
"comodoro" "comodoro"
"darcs" "darcs"
"dircolors"
"delta" "delta"
"dircolors"
"direnv" "direnv"
"earthly" "earthly"
"element-desktop" "element-desktop"
@ -45,12 +46,11 @@ let
"gh-dash" "gh-dash"
"ghostty" "ghostty"
"git" "git"
"patdiff"
"gitMinimal"
"git-cliff" "git-cliff"
"git-credential-oauth" "git-credential-oauth"
"git-lfs" "git-lfs"
"git-worktree-switcher" "git-worktree-switcher"
"gitMinimal"
"gnupg" "gnupg"
"go" "go"
"gradle" "gradle"
@ -66,9 +66,9 @@ let
"irssi" "irssi"
"isync" "isync"
"jankyborders" "jankyborders"
"jujutsu"
"joplin-desktop" "joplin-desktop"
"jqp" "jqp"
"jujutsu"
"k9s" "k9s"
"kakoune" "kakoune"
"khal" "khal"
@ -82,16 +82,16 @@ let
"less" "less"
"lesspipe" "lesspipe"
"lf" "lf"
"lsd"
"lieer" "lieer"
"lsd"
"mbsync" "mbsync"
"mergiraf" "mergiraf"
"micro" "micro"
"mise" "mise"
"mpv" "mpv"
"msmtp"
"mu" "mu"
"mujmap" "mujmap"
"msmtp"
"ncmpcpp" "ncmpcpp"
"ne" "ne"
"neomutt" "neomutt"
@ -112,6 +112,7 @@ let
"onlyoffice-desktopeditors" "onlyoffice-desktopeditors"
"openstackclient" "openstackclient"
"papis" "papis"
"patdiff"
"pay-respects" "pay-respects"
"pet" "pet"
"pistol" "pistol"
@ -164,6 +165,7 @@ let
"zoxide" "zoxide"
"zplug" "zplug"
"zsh" "zsh"
# keep-sorted end
]; ];
# Create an overlay that scrubs packages in the scrublist # 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)) { } ( tests = builtins.foldl' (a: b: a // (import b)) { } (
[ [
# keep-sorted start case=no numeric=yes
./lib/generators ./lib/generators
./lib/types ./lib/types
./modules/files ./modules/files
@ -219,9 +220,9 @@ import nmtSrc {
./modules/programs/i3status ./modules/programs/i3status
./modules/programs/inori ./modules/programs/inori
./modules/programs/irssi ./modules/programs/irssi
./modules/programs/jujutsu
./modules/programs/joplin-desktop ./modules/programs/joplin-desktop
./modules/programs/jqp ./modules/programs/jqp
./modules/programs/jujutsu
./modules/programs/k9s ./modules/programs/k9s
./modules/programs/kakoune ./modules/programs/kakoune
./modules/programs/keepassxc ./modules/programs/keepassxc
@ -230,13 +231,13 @@ import nmtSrc {
./modules/programs/kitty ./modules/programs/kitty
./modules/programs/kubecolor ./modules/programs/kubecolor
./modules/programs/lapce ./modules/programs/lapce
./modules/programs/ledger
./modules/programs/lazydocker ./modules/programs/lazydocker
./modules/programs/ledger
./modules/programs/less ./modules/programs/less
./modules/programs/lesspipe ./modules/programs/lesspipe
./modules/programs/lf ./modules/programs/lf
./modules/programs/lsd
./modules/programs/lieer ./modules/programs/lieer
./modules/programs/lsd
./modules/programs/man ./modules/programs/man
./modules/programs/mbsync ./modules/programs/mbsync
./modules/programs/mergiraf ./modules/programs/mergiraf
@ -326,8 +327,10 @@ import nmtSrc {
./modules/services/gpg-agent ./modules/services/gpg-agent
./modules/services/syncthing/common ./modules/services/syncthing/common
./modules/xresources ./modules/xresources
# keep-sorted end
] ]
++ lib.optionals isDarwin [ ++ lib.optionals isDarwin [
# keep-sorted start case=no numeric=yes
./modules/launchd ./modules/launchd
./modules/programs/aerospace ./modules/programs/aerospace
./modules/programs/element-desktop/darwin.nix ./modules/programs/element-desktop/darwin.nix
@ -344,11 +347,13 @@ import nmtSrc {
./modules/services/skhd ./modules/services/skhd
./modules/services/yubikey-agent-darwin ./modules/services/yubikey-agent-darwin
./modules/targets-darwin ./modules/targets-darwin
# keep-sorted end
] ]
++ lib.optionals isLinux [ ++ lib.optionals isLinux [
./modules/misc/xdg/linux.nix # keep-sorted start case=no numeric=yes
./modules/config/home-cursor ./modules/config/home-cursor
./modules/config/i18n ./modules/config/i18n
./modules/dbus
./modules/i18n/input-method ./modules/i18n/input-method
./modules/misc/debug ./modules/misc/debug
./modules/misc/editorconfig ./modules/misc/editorconfig
@ -356,6 +361,7 @@ import nmtSrc {
./modules/misc/numlock ./modules/misc/numlock
./modules/misc/pam ./modules/misc/pam
./modules/misc/qt ./modules/misc/qt
./modules/misc/xdg/linux.nix
./modules/misc/xsession ./modules/misc/xsession
./modules/programs/abook ./modules/programs/abook
./modules/programs/anyrun ./modules/programs/anyrun
@ -382,8 +388,8 @@ import nmtSrc {
./modules/programs/i3blocks ./modules/programs/i3blocks
./modules/programs/i3status-rust ./modules/programs/i3status-rust
./modules/programs/imv ./modules/programs/imv
./modules/programs/kodi
./modules/programs/kickoff ./modules/programs/kickoff
./modules/programs/kodi
./modules/programs/looking-glass-client ./modules/programs/looking-glass-client
./modules/programs/lutris ./modules/programs/lutris
./modules/programs/mangohud ./modules/programs/mangohud
@ -423,8 +429,8 @@ import nmtSrc {
./modules/services/clipman ./modules/services/clipman
./modules/services/clipse ./modules/services/clipse
./modules/services/comodoro ./modules/services/comodoro
./modules/services/copyq
./modules/services/conky ./modules/services/conky
./modules/services/copyq
./modules/services/darkman ./modules/services/darkman
./modules/services/davmail ./modules/services/davmail
./modules/services/devilspie2 ./modules/services/devilspie2
@ -506,7 +512,7 @@ import nmtSrc {
./modules/services/yubikey-agent ./modules/services/yubikey-agent
./modules/systemd ./modules/systemd
./modules/targets-linux ./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 = [ "*" ]