diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..e3a6c5e --- /dev/null +++ b/default.nix @@ -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 diff --git a/docs/faq.md b/docs/faq.md index 54c09ae..1cd3f46 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -2,19 +2,19 @@ ## 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: @@ -22,7 +22,7 @@ The file is located in: ~/.cache/treefmt/eval-cache/.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 \ No newline at end of file +[BoltDB]: https://github.com/etcd-io/bbolt diff --git a/flake.lock b/flake.lock index 19e8ea0..9f3c00b 100644 --- a/flake.lock +++ b/flake.lock @@ -21,6 +21,21 @@ "type": "github" } }, + "flake-compat": { + "locked": { + "lastModified": 1688025799, + "narHash": "sha256-ktpB4dRtnksm9F5WawoIkEneh1nrEvuxb5lJFt1iOyw=", + "owner": "nix-community", + "repo": "flake-compat", + "rev": "8bf105319d44f6b9f0d764efa4fdef9f1cc9ba1c", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "flake-compat", + "type": "github" + } + }, "flake-parts": { "inputs": { "nixpkgs-lib": "nixpkgs-lib" @@ -163,6 +178,7 @@ "root": { "inputs": { "devshell": "devshell", + "flake-compat": "flake-compat", "flake-parts": "flake-parts", "flake-root": "flake-root", "gomod2nix": "gomod2nix", diff --git a/flake.nix b/flake.nix index fb7511e..cd2ff35 100644 --- a/flake.nix +++ b/flake.nix @@ -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 = { @@ -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, ...}: diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..a322436 --- /dev/null +++ b/shell.nix @@ -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