Skip to content

Commit

Permalink
✅ add treefmt as module, devShell, check, ci integration
Browse files Browse the repository at this point in the history
Adds `treefmt` through the `treefmt-nix` module.

This allows the following integration:

- `nix fmt`: format the code through `nix fmt`
- `treefmt`: exposes a wrapped, configured `treefmt` inside the
  `devShell`
- `nix flake check`: check and lint the code locally, or the ci

All of these options use the same configuration and will share
evaluation cache.

Initalize with the following formatters/linters:
- deadnix
- nixfmt
- rustfmt
- statix
- taplo
- yamllint
  • Loading branch information
a-kenji committed Feb 15, 2024
1 parent e70660b commit 8144bc4
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 84 deletions.
9 changes: 2 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
[workspace]
resolver = "2"

default-members = [
"client",
]
default-members = ["client"]

members = [
"client",
"services/index-git-repositories",
]
members = ["client", "services/index-git-repositories"]

[workspace.package]
version = "0.8.0"
9 changes: 7 additions & 2 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ edition = "2021"
[dependencies]
# general
anyhow = { version = "1.0.78", features = ["backtrace"] }
clap = { version = "4.4.16", features = ["derive",] }
clap = { version = "4.4.16", features = ["derive"] }
log = { version = "0.4.20", features = ["kv_unstable_serde"] }
simple_logger = { version = "4.3.3", features = ["colors", "threads", "timestamps", "stderr"] }
simple_logger = { version = "4.3.3", features = [
"colors",
"threads",
"timestamps",
"stderr",
] }

# application window
iced = { version = "0.10.0", features = ["svg"] }
Expand Down
37 changes: 36 additions & 1 deletion flake.lock

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

119 changes: 46 additions & 73 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,19 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
home-manager.url = "github:nix-community/home-manager";
treefmt-nix.url = "github:numtide/treefmt-nix/";
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs =
{
self,
nixpkgs,
crane,
home-manager,
}:
outputs = { self, nixpkgs, crane, treefmt-nix, ... }:
let
system = "x86_64-linux";
pkgs = import nixpkgs { inherit system; };

devInputs = with pkgs; [
rustc
rustfmt
cargo
];
devInputs = with pkgs; [ rustc rustfmt cargo ];

nativeBuildInputs = with pkgs; [
makeWrapper
Expand All @@ -44,38 +35,29 @@

craneLib = crane.lib.${system};
assetFilter = path: _type: builtins.match ".*ttf$" path != null;
assetOrCargo =
path: type: (assetFilter path type) || (craneLib.filterCargoSources path type);
assetOrCargo = path: type:
(assetFilter path type) || (craneLib.filterCargoSources path type);
commonArgs = {
src = pkgs.lib.cleanSourceWith {
src = craneLib.path ./.;
filter = assetOrCargo;
};
inherit
pname
version
buildInputs
nativeBuildInputs
;
inherit pname version buildInputs nativeBuildInputs;
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
cargoClippy = craneLib.cargoClippy (
commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets --all-features";
}
);
cargoClippy = craneLib.cargoClippy (commonArgs // {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets --all-features";
});
GIT_DATE = "${builtins.substring 0 4 self.lastModifiedDate}-${
builtins.substring 4 2 self.lastModifiedDate
}-${builtins.substring 6 2 self.lastModifiedDate}";
GIT_REV = self.shortRev or "Not committed yet.";
in
{
treefmt = (treefmt-nix.lib.evalModule pkgs ./formatter.nix).config.build;
in {
devShells.${system}.default = pkgs.mkShell {
inherit nativeBuildInputs buildInputs
GIT_DATE GIT_REV;
packages = devInputs;
inherit nativeBuildInputs buildInputs GIT_DATE GIT_REV;
packages = devInputs ++ [ treefmt.wrapper ];
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
pkgs.wayland
pkgs.libxkbcommon
Expand All @@ -84,55 +66,46 @@
];
};
packages.${system} = {
default = craneLib.buildPackage (
commonArgs
// {
inherit
cargoArtifacts
nativeBuildInputs
buildInputs
pname
GIT_REV
GIT_DATE
;
postInstall = ''
wrapProgram "$out/bin/${pname}" \
--prefix LD_LIBRARY_PATH : ${
pkgs.lib.makeLibraryPath [
pkgs.wayland
pkgs.libxkbcommon
pkgs.vulkan-loader
pkgs.libGL
]
}
'';
meta = with pkgs.lib; {
description = "Your trusty omnibox search.";
homepage = "https://github.com/friedow/centerpiece";
platforms = platforms.linux;
license = licenses.mit;
maintainers = [ "friedow" ];
};
}
);
index-git-repositories = craneLib.buildPackage (
commonArgs
// rec {
inherit cargoArtifacts;
pname = "index-git-repositories";
cargoExtraArgs = "-p ${pname}";
meta.mainProgram = pname;
}
);
default = craneLib.buildPackage (commonArgs // {
inherit cargoArtifacts nativeBuildInputs buildInputs pname GIT_REV
GIT_DATE;
postInstall = ''
wrapProgram "$out/bin/${pname}" \
--prefix LD_LIBRARY_PATH : ${
pkgs.lib.makeLibraryPath [
pkgs.wayland
pkgs.libxkbcommon
pkgs.vulkan-loader
pkgs.libGL
]
}
'';
meta = with pkgs.lib; {
description = "Your trusty omnibox search.";
homepage = "https://github.com/friedow/centerpiece";
platforms = platforms.linux;
license = licenses.mit;
maintainers = [ "friedow" ];
};
});
index-git-repositories = craneLib.buildPackage (commonArgs // rec {
inherit cargoArtifacts;
pname = "index-git-repositories";
cargoExtraArgs = "-p ${pname}";
meta.mainProgram = pname;
});
};
checks.${system} = {
inherit (self.outputs.packages.${system}) default index-git-repositories;
inherit (self.outputs.packages.${system})
default index-git-repositories;
shell = self.outputs.devShells.${system}.default;
treefmt = treefmt.check self;
inherit cargoClippy;
};
hmModules.${system}.default = import ./home-manager-module.nix {
centerpiece = self.outputs.packages.${system}.default;
inherit (self.outputs.packages.${system}) index-git-repositories;
};
formatter.${system} = treefmt.wrapper;
};
}
12 changes: 12 additions & 0 deletions formatter.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
_: {
projectRootFile = "flake.nix";

programs = {
deadnix.enable = true;
nixfmt.enable = true;
rustfmt.enable = true;
statix.enable = true;
taplo.enable = true;
yamlfmt.enable = true;
};
}
7 changes: 6 additions & 1 deletion services/index-git-repositories/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ edition = "2021"

[dependencies]
log = { version = "0.4.20", features = ["kv_unstable_serde"] }
simple_logger = { version = "4.3.3", features = ["colors", "threads", "timestamps", "stderr"] }
simple_logger = { version = "4.3.3", features = [
"colors",
"threads",
"timestamps",
"stderr",
] }

serde_json = "1.0.113"
rust_search = "2.0.0"
Expand Down

0 comments on commit 8144bc4

Please sign in to comment.