Skip to content

Commit

Permalink
Merge pull request #347 from nix-community/nix-tidy
Browse files Browse the repository at this point in the history
Add nix-tidy-fix ci check
  • Loading branch information
Mic92 authored Dec 11, 2024
2 parents 8e82a79 + 6b3566e commit b1f94fe
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dev/treefmt.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
programs.yamlfmt.enable = true;

programs.clang-format.enable = true;
programs.clang-format.package = pkgs.llvmPackages_latest.clang-tools;

programs.deadnix.enable = true;
programs.nixfmt.enable = true;
programs.nixfmt.package = pkgs.nixfmt-rfc-style;
programs.ruff.format = true;
programs.ruff.check = true;
}
30 changes: 30 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,36 @@

checks = builtins.removeAttrs self'.packages [ "default" ] // {
shell = self'.devShells.default;
clang-tidy-fix = self'.packages.nix-eval-jobs.overrideAttrs (old: {
nativeBuildInputs = old.nativeBuildInputs ++ [
pkgs.git
(lib.hiPrio pkgs.llvmPackages_latest.clang-tools)
];
buildPhase = ''
export HOME=$TMPDIR
cat > $HOME/.gitconfig <<EOF
[user]
name = Nix
email = nix@localhost
[init]
defaultBranch = main
EOF
pushd ..
git init
git add .
git commit -m init --quiet
popd
ninja clang-tidy-fix
git status
if ! git --no-pager diff --exit-code; then
echo "clang-tidy-fix failed, please run `ninja clang-tidy-fix` and commit the changes"
exit 1
fi
'';
installPhase = ''
touch $out
'';
});
};
};
};
Expand Down
2 changes: 1 addition & 1 deletion shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ in
inherit (nix-eval-jobs) buildInputs;
nativeBuildInputs = nix-eval-jobs.nativeBuildInputs ++ [
(pkgs.python3.withPackages (ps: [ ps.pytest ]))
(lib.hiPrio pkgs.clang-tools)
(lib.hiPrio pkgs.llvmPackages_latest.clang-tools)
];

shellHook = lib.optionalString stdenv.isLinux ''
Expand Down
7 changes: 4 additions & 3 deletions src/drv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@

namespace {

auto queryCacheStatus(nix::Store &store,
std::map<std::string, std::optional<std::string>>
&outputs) -> Drv::CacheStatus {
auto queryCacheStatus(
nix::Store &store,
std::map<std::string, std::optional<std::string>> &outputs)
-> Drv::CacheStatus {
uint64_t downloadSize = 0;
uint64_t narSize = 0;
nix::StorePathSet willBuild;
Expand Down
5 changes: 3 additions & 2 deletions src/nix-eval-jobs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@

namespace {
MyArgs myArgs; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
}

using Processor = std::function<void(MyArgs &myArgs, nix::AutoCloseFD &to,
nix::AutoCloseFD &from)>;
Expand Down Expand Up @@ -374,6 +373,7 @@ void collector(nix::Sync<State> &state_, std::condition_variable &wakeup) {
wakeup.notify_all();
}
}
} // namespace

auto main(int argc, char **argv) -> int {

Expand Down Expand Up @@ -429,7 +429,7 @@ auto main(int argc, char **argv) -> int {
}

if (myArgs.gcRootsDir.empty()) {
nix::Path tmpDir = nix::createTempDir();
const nix::Path tmpDir = nix::createTempDir();
gcRootsDir.emplace(tmpDir, true);
myArgs.gcRootsDir = tmpDir;
} else {
Expand All @@ -445,6 +445,7 @@ auto main(int argc, char **argv) -> int {
/* Start a collector thread per worker process. */
std::vector<Thread> threads;
std::condition_variable wakeup;
threads.reserve(myArgs.nrWorkers);
for (size_t i = 0; i < myArgs.nrWorkers; i++) {
threads.emplace_back(
[&state_, &wakeup] { collector(state_, wakeup); });
Expand Down
1 change: 1 addition & 0 deletions src/strings-portable.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <cstring>
#include "strings-portable.hh"

#ifdef __APPLE__
// for sys_siglist and sys_errlist
Expand Down
2 changes: 1 addition & 1 deletion src/worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ void worker(
reply["attrs"] = nlohmann::json::array();
}
} catch (nix::EvalError &e) {
auto err = e.info();
const auto &err = e.info();
std::ostringstream oss;
nix::showErrorInfo(oss, err, nix::loggerSettings.showTrace.get());
auto msg = oss.str();
Expand Down

0 comments on commit b1f94fe

Please sign in to comment.