Skip to content

Commit

Permalink
feat: add flake compat
Browse files Browse the repository at this point in the history
Signed-off-by: Brian McGee <[email protected]>
  • Loading branch information
brianmcgee committed May 2, 2024
1 parent 8e840a9 commit ad3e661
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 10 deletions.
17 changes: 17 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file provides backward compatibility to nix < 2.4 clients
{system ? builtins.currentSystem}: let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);

inherit (lock.nodes.flake-compat.locked) owner repo rev narHash;

flake-compat = fetchTarball {
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
sha256 = narHash;
};

flake = import flake-compat {
inherit system;
src = ./.;
};
in
flake.defaultNix
16 changes: 8 additions & 8 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@

## How does treefmt function?

`Treefmt` traverses all your project's folders, maps files to specific code formatters, and formats the code
`Treefmt` traverses all your project's folders, maps files to specific code formatters, and formats the code
accordingly. Other tools also traverse the filesystem, but not necessarily starting from the root of the project.

Contrary to other formatters, `treefmt` doesn't preview the changes before writing them to a file. If you want to view
the changes, you can always check the diff in your version control (we assume that your project is checked into a
version control system).
Contrary to other formatters, `treefmt` doesn't preview the changes before writing them to a file. If you want to view
the changes, you can always check the diff in your version control (we assume that your project is checked into a
version control system).

You can also rely on version control if errors were introduced into your code as a result of disruptions in the
You can also rely on version control if errors were introduced into your code as a result of disruptions in the
formatter's work.

## How is the cache organized?

At the moment, the cache is a [BoltDB] database file in which file paths are mapped to `mtimes`.
At the moment, the cache is a [BoltDB] database file in which file paths are mapped to `mtimes`.

The file is located in:

```
~/.cache/treefmt/eval-cache/<hash-of-the-treefmt.toml-path>.db
```

At the end of each run, the database is updated with the last formatting time entries. In this way, we can
At the end of each run, the database is updated with the last formatting time entries. In this way, we can
compare the last change time of the file to the last formatting time, and figure out which files need re-formatting.

[BoltDB]: https://github.com/etcd-io/bbolt
[BoltDB]: https://github.com/etcd-io/bbolt
16 changes: 16 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";

flake-parts.url = "github:hercules-ci/flake-parts";
flake-root.url = "github:srid/flake-root";
treefmt-nix = {
Expand All @@ -19,8 +18,8 @@
url = "github:nix-community/gomod2nix";
inputs.nixpkgs.follows = "nixpkgs";
};

nix-filter.url = "github:numtide/nix-filter";
flake-compat.url = "github:nix-community/flake-compat";
};

outputs = inputs @ {flake-parts, ...}:
Expand Down
17 changes: 17 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file provides backward compatibility to nix < 2.4 clients
{system ? builtins.currentSystem}: let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);

inherit (lock.nodes.flake-compat.locked) owner repo rev narHash;

flake-compat = fetchTarball {
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
sha256 = narHash;
};

flake = import flake-compat {
inherit system;
src = ./.;
};
in
flake.shellNix

0 comments on commit ad3e661

Please sign in to comment.