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
jobs:
#check:
#runs-on: ubuntu-latest
#name: "flake check"
#environment: cachix
#timeout-minutes: 5
#steps:
#- uses: actions/checkout@v3
#with:
## Nix Flakes doesn't work on shallow clones
#fetch-depth: 0
#- uses: cachix/install-nix-action@v16
#with:
#extra_nix_config: |
#experimental-features = nix-command flakes
#fetch-depth: 0
#- uses: cachix/cachix-action@v10
#with:
#name: zellij
## If you chose API tokens for write access OR if you have a private cache
#authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
check:
runs-on: ubuntu-latest
name: "flake check"
environment: cachix
timeout-minutes: 5
steps:
- uses: actions/checkout@v3
with:
# Nix Flakes doesn't work on shallow clones
fetch-depth: 0
- uses: cachix/install-nix-action@v16
with:
extra_nix_config: |
experimental-features = nix-command flakes
fetch-depth: 0
- uses: cachix/cachix-action@v10
with:
name: zellij
# If you chose API tokens for write access OR if you have a private cache
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
build:

View file

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

View file

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

View file

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

View file

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

3
treefmt.toml Normal file
View file

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