-
-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Format Rust, Nix and Bash via treefmt #47
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8e5a54f
Switch to treefmt for Rust files
infinisil 50ac546
Format Nix files treewide
infinisil c8525b8
Fix test failures after formatting Nix files
infinisil b1306dd
Format scripts using shfmt
infinisil ff95d9b
Add .git-blame-ignore-revs file for recent treewide reformats
infinisil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# This file contains a list of commits that are not likely what you | ||
# are looking for in a blame, such as mass reformatting or renaming. | ||
# You can set this file as a default ignore file for blame by running | ||
# the following command. | ||
# | ||
# $ git config blame.ignoreRevsFile .git-blame-ignore-revs | ||
|
||
# Reformatted all Nix files | ||
81d712a6c4e020bf545fb931b3106aff64871962 | ||
|
||
# Reformatted all Bash scripts | ||
b1306dd5ae96b0fb934256d91708733c1f850016 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,13 @@ in | |
{ | ||
system ? builtins.currentSystem, | ||
nixpkgs ? sources.nixpkgs, | ||
treefmt-nix ? sources.treefmt-nix, | ||
}: | ||
let | ||
pkgs = import nixpkgs { | ||
inherit system; | ||
config = {}; | ||
overlays = []; | ||
config = { }; | ||
overlays = [ ]; | ||
}; | ||
inherit (pkgs) lib; | ||
|
||
|
@@ -34,12 +35,28 @@ let | |
# Determine version from Cargo.toml | ||
version = (lib.importTOML ./Cargo.toml).package.version; | ||
|
||
treefmtEval = (import treefmt-nix).evalModule pkgs { | ||
# Used to find the project root | ||
projectRootFile = ".git/config"; | ||
|
||
programs.rustfmt.enable = true; | ||
programs.nixfmt-rfc-style.enable = true; | ||
programs.shfmt.enable = true; | ||
settings.formatter.shfmt.options = [ "--space-redirects" ]; | ||
}; | ||
|
||
results = { | ||
# We're using this value as the root result. By default, derivations expose all of their | ||
# internal attributes, which is very messy. We prevent this using lib.lazyDerivation | ||
build = lib.lazyDerivation { | ||
derivation = pkgs.callPackage ./package.nix { | ||
inherit nixpkgsLibPath initNix runtimeExprPath testNixpkgsPath version; | ||
inherit | ||
nixpkgsLibPath | ||
initNix | ||
runtimeExprPath | ||
testNixpkgsPath | ||
version | ||
; | ||
}; | ||
}; | ||
|
||
|
@@ -51,18 +68,25 @@ let | |
nativeBuildInputs = with pkgs; [ | ||
npins | ||
rust-analyzer | ||
treefmtEval.config.build.wrapper | ||
]; | ||
}; | ||
|
||
# This checks that all Git-tracked files are formatted appropriately | ||
treefmt = treefmtEval.config.build.check ( | ||
lib.fileset.toSource { | ||
root = ./.; | ||
fileset = lib.fileset.gitTracked ./.; | ||
Comment on lines
+77
to
+79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Look at that dogfooding! |
||
} | ||
); | ||
|
||
# Run regularly by CI and turned into a PR | ||
autoPrUpdate = | ||
let | ||
updateScripts = { | ||
npins = pkgs.writeShellApplication { | ||
name = "update-npins"; | ||
runtimeInputs = with pkgs; [ | ||
npins | ||
]; | ||
runtimeInputs = with pkgs; [ npins ]; | ||
text = '' | ||
echo "<details><summary>npins changes</summary>" | ||
# Needed because GitHub's rendering of the first body line breaks down otherwise | ||
|
@@ -75,9 +99,7 @@ let | |
}; | ||
cargo = pkgs.writeShellApplication { | ||
name = "update-cargo"; | ||
runtimeInputs = with pkgs; [ | ||
cargo | ||
]; | ||
runtimeInputs = with pkgs; [ cargo ]; | ||
text = '' | ||
echo "<details><summary>cargo changes</summary>" | ||
# Needed because GitHub's rendering of the first body line breaks down otherwise | ||
|
@@ -113,21 +135,25 @@ let | |
}; | ||
|
||
# Tests the tool on the pinned Nixpkgs tree, this is a good sanity check | ||
nixpkgsCheck = pkgs.runCommand "test-nixpkgs-check-by-name" { | ||
nativeBuildInputs = [ | ||
results.build | ||
pkgs.nix | ||
]; | ||
nixpkgsPath = nixpkgs; | ||
} '' | ||
${initNix} | ||
nixpkgs-check-by-name --base "$nixpkgsPath" "$nixpkgsPath" | ||
touch $out | ||
''; | ||
nixpkgsCheck = | ||
pkgs.runCommand "test-nixpkgs-check-by-name" | ||
{ | ||
nativeBuildInputs = [ | ||
results.build | ||
pkgs.nix | ||
]; | ||
nixpkgsPath = nixpkgs; | ||
} | ||
'' | ||
${initNix} | ||
nixpkgs-check-by-name --base "$nixpkgsPath" "$nixpkgsPath" | ||
touch $out | ||
''; | ||
}; | ||
|
||
in | ||
results.build // results // { | ||
results.build | ||
// results | ||
// { | ||
|
||
# Good for debugging | ||
inherit pkgs; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
81d712a