add(nix): treefmt / alejandra (#1201)

* add(nix): treefmt / alejandra

* fmt the nix tree

* add fmt check for nix to ci

* switch `nixpkgs-fmt` -> `alejandra`
This commit is contained in:
a-kenji 2022-03-10 16:27:39 +01:00 committed by GitHub
parent a25fd88dbb
commit bd849574be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 211 additions and 177 deletions

View file

@ -9,26 +9,28 @@ on:
- main - main
jobs: jobs:
#check: check:
#runs-on: ubuntu-latest runs-on: ubuntu-latest
#name: "flake check" name: "flake check"
#environment: cachix environment: cachix
#timeout-minutes: 5 timeout-minutes: 5
#steps: steps:
#- uses: actions/checkout@v3 - uses: actions/checkout@v3
#with: with:
## Nix Flakes doesn't work on shallow clones # Nix Flakes doesn't work on shallow clones
#fetch-depth: 0 fetch-depth: 0
#- uses: cachix/install-nix-action@v16 - uses: cachix/install-nix-action@v16
#with: with:
#extra_nix_config: | extra_nix_config: |
#experimental-features = nix-command flakes experimental-features = nix-command flakes
#fetch-depth: 0 fetch-depth: 0
#- uses: cachix/cachix-action@v10 - uses: cachix/cachix-action@v10
#with: with:
#name: zellij name: zellij
## If you chose API tokens for write access OR if you have a private cache # If you chose API tokens for write access OR if you have a private cache
#authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- run: nix develop .#fmtShell --command treefmt --fail-on-change
## nix flake check still fails on IFD
#- run: nix flake check --print-build-logs --show-trace #- run: nix flake check --print-build-logs --show-trace
build: build:

View file

@ -10,4 +10,5 @@
) )
{ {
src = ./.; src = ./.;
}).defaultNix })
.defaultNix

View file

@ -1,16 +1,17 @@
{ pkgs {
, crate2nix pkgs,
, name crate2nix,
, src name,
, postInstall src,
, nativeBuildInputs postInstall,
, desktopItems nativeBuildInputs,
, meta desktopItems,
}: meta,
}: let
let inherit
inherit (import "${crate2nix}/tools.nix" { inherit pkgs; }) (import "${crate2nix}/tools.nix" {inherit pkgs;})
generatedCargoNix; generatedCargoNix
;
project = import project = import
(generatedCargoNix { (generatedCargoNix {
@ -20,15 +21,15 @@ let
inherit pkgs; inherit pkgs;
buildRustCrateForPkgs = pkgs: buildRustCrateForPkgs = pkgs:
pkgs.buildRustCrate.override { pkgs.buildRustCrate.override {
defaultCrateOverrides = pkgs.defaultCrateOverrides // { defaultCrateOverrides =
pkgs.defaultCrateOverrides
// {
# Crate dependency overrides go here # Crate dependency overrides go here
zellij = attrs: { zellij = attrs: {
inherit postInstall desktopItems meta name nativeBuildInputs; inherit postInstall desktopItems meta name nativeBuildInputs;
}; };
}; };
}; };
}; };
in in
project.workspaceMembers.zellij.build project.workspaceMembers.zellij.build

View file

@ -1,9 +1,10 @@
{ self {
, nixpkgs self,
, rust-overlay nixpkgs,
, flake-utils rust-overlay,
, flake-compat flake-utils,
, crate2nix flake-compat,
crate2nix,
}: }:
flake-utils.lib.eachSystem [ flake-utils.lib.eachSystem [
"aarch64-linux" "aarch64-linux"
@ -12,20 +13,20 @@ flake-utils.lib.eachSystem [
"x86_64-darwin" "x86_64-darwin"
"x86_64-linux" "x86_64-linux"
] ]
(system: (system: let
let
overlays = [(import rust-overlay)]; overlays = [(import rust-overlay)];
pkgs = import nixpkgs {inherit system overlays;}; pkgs = import nixpkgs {inherit system overlays;};
crate2nixPkgs = import nixpkgs { inherit system; crate2nixPkgs = import nixpkgs {
inherit system;
overlays = [ overlays = [
(self: _: { (self: _: {
rustc = rustToolchainToml; rustc = rustToolchainToml;
cargo = rustToolchainToml; cargo = rustToolchainToml;
}) })
];
];}; };
name = "zellij"; name = "zellij";
pname = name; pname = name;
@ -37,7 +38,10 @@ flake-utils.lib.eachSystem [
rustToolchainToml = pkgs.rust-bin.fromRustupToolchainFile ../rust-toolchain; rustToolchainToml = pkgs.rust-bin.fromRustupToolchainFile ../rust-toolchain;
cargoLock = { cargoLock = {
lockFile = (builtins.path { path = ../Cargo.lock; name = "Cargo.lock"; }); lockFile = (builtins.path {
path = ../Cargo.lock;
name = "Cargo.lock";
});
}; };
cargo = rustToolchainToml; cargo = rustToolchainToml;
rustc = rustToolchainToml; rustc = rustToolchainToml;
@ -63,7 +67,6 @@ flake-utils.lib.eachSystem [
devInputs = [ devInputs = [
pkgs.cargo-make pkgs.cargo-make
pkgs.rust-analyzer pkgs.rust-analyzer
pkgs.nixpkgs-fmt
# optimizes wasm binaries # optimizes wasm binaries
pkgs.binaryen pkgs.binaryen
@ -72,6 +75,11 @@ flake-utils.lib.eachSystem [
pkgs.cargo-insta pkgs.cargo-insta
]; ];
fmtInputs = [
pkgs.alejandra
pkgs.treefmt
];
postInstall = '' postInstall = ''
mandown ./docs/MANPAGE.md > ./zellij.1 mandown ./docs/MANPAGE.md > ./zellij.1
installManPage ./zellij.1 installManPage ./zellij.1
@ -107,21 +115,33 @@ flake-utils.lib.eachSystem [
description = "A terminal workspace with batteries included"; description = "A terminal workspace with batteries included";
license = [licenses.mit]; license = [licenses.mit];
}; };
in in rec {
rec {
# crate2nix - better incremental builds, but uses ifd # crate2nix - better incremental builds, but uses ifd
packages.zellij = crate2nixPkgs.callPackage ./crate2nix.nix { packages.zellij = crate2nixPkgs.callPackage ./crate2nix.nix {
inherit crate2nix name src desktopItems postInstall inherit
meta nativeBuildInputs; name
src
nativeBuildInputs
crate2nix
desktopItems
postInstall
meta
;
}; };
# native nixpkgs support - keep supported # native nixpkgs support - keep supported
packages.zellij-native = packages.zellij-native =
(pkgs.makeRustPlatform {inherit cargo rustc;}).buildRustPackage { (pkgs.makeRustPlatform {inherit cargo rustc;}).buildRustPackage {
inherit src name cargoLock inherit
buildInputs nativeBuildInputs src
postInstall desktopItems meta; name
cargoLock
buildInputs
nativeBuildInputs
postInstall
desktopItems
meta
;
}; };
defaultPackage = packages.zellij; defaultPackage = packages.zellij;
@ -130,10 +150,16 @@ flake-utils.lib.eachSystem [
apps.zellij = flake-utils.lib.mkApp {drv = packages.zellij;}; apps.zellij = flake-utils.lib.mkApp {drv = packages.zellij;};
defaultApp = apps.zellij; defaultApp = apps.zellij;
devShells = {
devShell = pkgs.callPackage ./devShell.nix { zellij = pkgs.callPackage ./devShell.nix {
inherit buildInputs; inherit buildInputs;
nativeBuildInputs = nativeBuildInputs ++ devInputs; nativeBuildInputs = nativeBuildInputs ++ devInputs ++ fmtInputs;
};
fmtShell = pkgs.mkShell {
name = "fmt-shell";
nativeBuildInputs = fmtInputs;
};
}; };
devShell = devShells.zellij;
}) })

View file

@ -1,8 +1,8 @@
{ mkShell {
, buildInputs mkShell,
, nativeBuildInputs buildInputs,
nativeBuildInputs,
}: }:
mkShell { mkShell {
name = "zj-dev-env"; name = "zj-dev-env";
inherit buildInputs nativeBuildInputs; inherit buildInputs nativeBuildInputs;

View file

@ -10,4 +10,5 @@
) )
{ {
src = ./.; src = ./.;
}).shellNix })
.shellNix

3
treefmt.toml Normal file
View file

@ -0,0 +1,3 @@
[formatter.nix]
command = "alejandra"
includes = ["*.nix"]