2021-06-29 12:01:37 +03:00
|
|
|
{ system ? builtins.currentSystem
|
|
|
|
, inputs ? import ./flake.lock.nix { }
|
2021-09-23 22:59:28 +03:00
|
|
|
, nixpkgs ? import inputs.nixpkgs {
|
2021-03-03 15:45:46 +03:00
|
|
|
inherit system;
|
2021-06-29 12:01:37 +03:00
|
|
|
# Makes the config pure as well. See <nixpkgs>/top-level/impure.nix:
|
|
|
|
config = { };
|
2021-09-23 22:59:28 +03:00
|
|
|
overlays = [ ];
|
|
|
|
}
|
2021-12-12 00:43:02 +03:00
|
|
|
, rustPackages ? nixpkgs.rustPackages
|
2021-09-23 22:59:28 +03:00
|
|
|
}:
|
|
|
|
let
|
2022-07-05 12:17:10 +03:00
|
|
|
lib = nixpkgs.lib;
|
|
|
|
|
2021-11-12 02:04:27 +03:00
|
|
|
cargoToml = with builtins; (fromTOML (readFile ./Cargo.toml));
|
2021-12-12 00:43:02 +03:00
|
|
|
|
2021-06-29 12:01:37 +03:00
|
|
|
# What is used when invoking `nix run github:numtide/treefmt`
|
2021-12-12 00:43:02 +03:00
|
|
|
treefmt = rustPackages.rustPlatform.buildRustPackage {
|
2021-09-23 22:59:28 +03:00
|
|
|
inherit (cargoToml.package) name version;
|
|
|
|
|
2022-06-07 20:52:38 +03:00
|
|
|
src = builtins.path {
|
|
|
|
path = ./.;
|
|
|
|
filter = name: type:
|
|
|
|
name == toString ./Cargo.toml
|
|
|
|
|| name == toString ./Cargo.lock
|
|
|
|
|| lib.hasPrefix (toString ./src) name
|
|
|
|
|| lib.hasPrefix (toString ./benches) name
|
|
|
|
;
|
|
|
|
};
|
2021-09-23 22:59:28 +03:00
|
|
|
|
2022-05-12 12:42:14 +03:00
|
|
|
buildInputs = with nixpkgs; lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.Security libiconv ];
|
|
|
|
|
|
|
|
doCheck = true;
|
|
|
|
|
|
|
|
cargoLock.lockFile = ./Cargo.lock;
|
|
|
|
|
|
|
|
meta.description = "one CLI to format the code tree";
|
|
|
|
};
|
|
|
|
|
|
|
|
# Add all the dependencies of treefmt, plus more build tools
|
|
|
|
devShell = treefmt.overrideAttrs (prev: {
|
|
|
|
shellHook = ''
|
|
|
|
# Put the treefmt binary on the PATH when it's built
|
|
|
|
export PATH=$PWD/target/debug:$PATH
|
|
|
|
'';
|
|
|
|
|
|
|
|
nativeBuildInputs = prev.nativeBuildInputs ++ (with nixpkgs; [
|
2021-09-23 22:59:28 +03:00
|
|
|
# Build tools
|
2021-12-12 00:43:02 +03:00
|
|
|
rustPackages.clippy
|
2021-09-23 22:59:28 +03:00
|
|
|
rust-analyzer
|
|
|
|
|
|
|
|
# Code formatters
|
|
|
|
elmPackages.elm-format
|
|
|
|
go
|
|
|
|
haskellPackages.cabal-fmt
|
|
|
|
haskellPackages.ormolu
|
2021-12-18 14:33:12 +03:00
|
|
|
mdsh
|
2021-09-23 22:59:28 +03:00
|
|
|
nixpkgs-fmt
|
|
|
|
nodePackages.prettier
|
|
|
|
python3.pkgs.black
|
|
|
|
rufo
|
2021-12-17 20:19:46 +03:00
|
|
|
rustPackages.rustfmt
|
2021-12-17 20:19:20 +03:00
|
|
|
shellcheck
|
2021-09-23 22:59:28 +03:00
|
|
|
shfmt
|
|
|
|
terraform
|
|
|
|
|
|
|
|
mdbook
|
2022-05-12 12:42:14 +03:00
|
|
|
]);
|
|
|
|
});
|
2021-12-12 00:43:02 +03:00
|
|
|
in
|
|
|
|
{
|
2022-05-12 12:42:14 +03:00
|
|
|
inherit treefmt devShell;
|
2021-06-29 12:01:37 +03:00
|
|
|
|
|
|
|
# A collection of packages for the project
|
|
|
|
docs = nixpkgs.callPackage ./docs { };
|
2021-12-12 00:43:02 +03:00
|
|
|
|
|
|
|
# Flake attributes
|
2022-05-18 21:25:12 +03:00
|
|
|
default = treefmt;
|
2022-07-07 18:09:23 +03:00
|
|
|
|
|
|
|
# Test that no HOME is needed when --no-cache is passed
|
|
|
|
treefmt-no-cache-no-home = nixpkgs.runCommandLocal "format"
|
|
|
|
{
|
|
|
|
buildInputs = [ treefmt ];
|
|
|
|
}
|
|
|
|
''
|
|
|
|
cat <<CONFIG > treefmt.toml
|
|
|
|
[formatter.nix]
|
|
|
|
command = "${nixpkgs.nixpkgs-fmt}/bin/nixpkgs-fmt"
|
|
|
|
includes = ["*.nix"]
|
|
|
|
CONFIG
|
|
|
|
# uncommenting this makes it work fine
|
|
|
|
# export HOME=$TMP
|
|
|
|
treefmt --no-cache --fail-on-change -C ./.
|
|
|
|
touch $out
|
|
|
|
'';
|
2021-06-29 12:01:37 +03:00
|
|
|
}
|