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:
parent
a25fd88dbb
commit
bd849574be
8 changed files with 211 additions and 177 deletions
42
.github/workflows/nix.yml
vendored
42
.github/workflows/nix.yml
vendored
|
|
@ -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:
|
||||||
|
|
|
||||||
17
default.nix
17
default.nix
|
|
@ -1,13 +1,14 @@
|
||||||
(import
|
(import
|
||||||
(
|
(
|
||||||
let
|
let
|
||||||
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
|
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
|
||||||
in
|
in
|
||||||
fetchTarball {
|
fetchTarball {
|
||||||
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
|
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
|
||||||
sha256 = lock.nodes.flake-compat.locked.narHash;
|
sha256 = lock.nodes.flake-compat.locked.narHash;
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
src = ./.;
|
src = ./.;
|
||||||
}).defaultNix
|
})
|
||||||
|
.defaultNix
|
||||||
|
|
|
||||||
|
|
@ -14,5 +14,5 @@
|
||||||
crate2nix.flake = false;
|
crate2nix.flake = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = { ... } @ args: import ./nix args;
|
outputs = {...} @ args: import ./nix args;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,34 +1,35 @@
|
||||||
{ 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 {
|
||||||
inherit name src;
|
inherit name src;
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
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
|
||||||
|
|
|
||||||
246
nix/default.nix
246
nix/default.nix
|
|
@ -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,128 +13,153 @@ 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 {
|
||||||
overlays = [
|
inherit system;
|
||||||
(self: _: {
|
overlays = [
|
||||||
rustc = rustToolchainToml;
|
(self: _: {
|
||||||
cargo = rustToolchainToml;
|
rustc = rustToolchainToml;
|
||||||
})
|
cargo = rustToolchainToml;
|
||||||
|
})
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
];};
|
name = "zellij";
|
||||||
|
pname = name;
|
||||||
|
root = toString ../.;
|
||||||
|
|
||||||
name = "zellij";
|
ignoreSource = [".git" "target" "example"];
|
||||||
pname = name;
|
|
||||||
root = toString ../.;
|
|
||||||
|
|
||||||
ignoreSource = [ ".git" "target" "example" ];
|
src = pkgs.nix-gitignore.gitignoreSource ignoreSource root;
|
||||||
|
|
||||||
src = pkgs.nix-gitignore.gitignoreSource ignoreSource root;
|
rustToolchainToml = pkgs.rust-bin.fromRustupToolchainFile ../rust-toolchain;
|
||||||
|
cargoLock = {
|
||||||
|
lockFile = (builtins.path {
|
||||||
|
path = ../Cargo.lock;
|
||||||
|
name = "Cargo.lock";
|
||||||
|
});
|
||||||
|
};
|
||||||
|
cargo = rustToolchainToml;
|
||||||
|
rustc = rustToolchainToml;
|
||||||
|
|
||||||
rustToolchainToml = pkgs.rust-bin.fromRustupToolchainFile ../rust-toolchain;
|
buildInputs = [
|
||||||
cargoLock = {
|
rustToolchainToml
|
||||||
lockFile = (builtins.path { path = ../Cargo.lock; name = "Cargo.lock"; });
|
|
||||||
};
|
|
||||||
cargo = rustToolchainToml;
|
|
||||||
rustc = rustToolchainToml;
|
|
||||||
|
|
||||||
buildInputs = [
|
# in order to run tests
|
||||||
rustToolchainToml
|
pkgs.openssl
|
||||||
|
];
|
||||||
|
|
||||||
# in order to run tests
|
nativeBuildInputs = [
|
||||||
pkgs.openssl
|
# generates manpages
|
||||||
];
|
pkgs.mandown
|
||||||
|
|
||||||
nativeBuildInputs = [
|
pkgs.installShellFiles
|
||||||
# generates manpages
|
pkgs.copyDesktopItems
|
||||||
pkgs.mandown
|
|
||||||
|
|
||||||
pkgs.installShellFiles
|
# for openssl/openssl-sys
|
||||||
pkgs.copyDesktopItems
|
pkgs.pkg-config
|
||||||
|
];
|
||||||
|
|
||||||
# for openssl/openssl-sys
|
devInputs = [
|
||||||
pkgs.pkg-config
|
pkgs.cargo-make
|
||||||
];
|
pkgs.rust-analyzer
|
||||||
|
|
||||||
devInputs = [
|
# optimizes wasm binaries
|
||||||
pkgs.cargo-make
|
pkgs.binaryen
|
||||||
pkgs.rust-analyzer
|
|
||||||
pkgs.nixpkgs-fmt
|
|
||||||
|
|
||||||
# optimizes wasm binaries
|
# used for snapshotting the e2e tests
|
||||||
pkgs.binaryen
|
pkgs.cargo-insta
|
||||||
|
];
|
||||||
|
|
||||||
# used for snapshotting the e2e tests
|
fmtInputs = [
|
||||||
pkgs.cargo-insta
|
pkgs.alejandra
|
||||||
];
|
pkgs.treefmt
|
||||||
|
];
|
||||||
|
|
||||||
postInstall = ''
|
postInstall = ''
|
||||||
mandown ./docs/MANPAGE.md > ./zellij.1
|
mandown ./docs/MANPAGE.md > ./zellij.1
|
||||||
installManPage ./zellij.1
|
installManPage ./zellij.1
|
||||||
|
|
||||||
# explicit behavior
|
# explicit behavior
|
||||||
$out/bin/zellij setup --generate-completion bash > ./completions.bash
|
$out/bin/zellij setup --generate-completion bash > ./completions.bash
|
||||||
installShellCompletion --bash --name ${pname}.bash ./completions.bash
|
installShellCompletion --bash --name ${pname}.bash ./completions.bash
|
||||||
$out/bin/zellij setup --generate-completion fish > ./completions.fish
|
$out/bin/zellij setup --generate-completion fish > ./completions.fish
|
||||||
installShellCompletion --fish --name ${pname}.fish ./completions.fish
|
installShellCompletion --fish --name ${pname}.fish ./completions.fish
|
||||||
$out/bin/zellij setup --generate-completion zsh > ./completions.zsh
|
$out/bin/zellij setup --generate-completion zsh > ./completions.zsh
|
||||||
installShellCompletion --zsh --name _${pname} ./completions.zsh
|
installShellCompletion --zsh --name _${pname} ./completions.zsh
|
||||||
|
|
||||||
install -Dm644 ./assets/logo.png $out/share/icons/hicolor/scalable/apps/zellij.png
|
install -Dm644 ./assets/logo.png $out/share/icons/hicolor/scalable/apps/zellij.png
|
||||||
|
|
||||||
copyDesktopItems
|
copyDesktopItems
|
||||||
'';
|
'';
|
||||||
|
|
||||||
desktopItems = [
|
|
||||||
(pkgs.makeDesktopItem {
|
|
||||||
type = "Application";
|
|
||||||
inherit name;
|
|
||||||
desktopName = "zellij";
|
|
||||||
terminal = true;
|
|
||||||
genericName = "Terminal multiplexer";
|
|
||||||
comment = "Manage your terminal applications";
|
|
||||||
exec = "zellij";
|
|
||||||
icon = "zellij";
|
|
||||||
categories = [ "ConsoleOnly;System" ];
|
|
||||||
})
|
|
||||||
];
|
|
||||||
meta = with pkgs.lib; {
|
|
||||||
homepage = "https://github.com/zellij-org/zellij/";
|
|
||||||
description = "A terminal workspace with batteries included";
|
|
||||||
license = [ licenses.mit ];
|
|
||||||
};
|
|
||||||
in
|
|
||||||
rec {
|
|
||||||
|
|
||||||
# crate2nix - better incremental builds, but uses ifd
|
|
||||||
packages.zellij = crate2nixPkgs.callPackage ./crate2nix.nix {
|
|
||||||
inherit crate2nix name src desktopItems postInstall
|
|
||||||
meta nativeBuildInputs;
|
|
||||||
};
|
|
||||||
|
|
||||||
# native nixpkgs support - keep supported
|
|
||||||
packages.zellij-native =
|
|
||||||
(pkgs.makeRustPlatform { inherit cargo rustc; }).buildRustPackage {
|
|
||||||
inherit src name cargoLock
|
|
||||||
buildInputs nativeBuildInputs
|
|
||||||
postInstall desktopItems meta;
|
|
||||||
};
|
|
||||||
|
|
||||||
defaultPackage = packages.zellij;
|
|
||||||
|
|
||||||
# nix run
|
|
||||||
apps.zellij = flake-utils.lib.mkApp { drv = packages.zellij; };
|
|
||||||
defaultApp = apps.zellij;
|
|
||||||
|
|
||||||
|
|
||||||
devShell = pkgs.callPackage ./devShell.nix {
|
|
||||||
inherit buildInputs;
|
|
||||||
nativeBuildInputs = nativeBuildInputs ++ devInputs;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
desktopItems = [
|
||||||
|
(pkgs.makeDesktopItem {
|
||||||
|
type = "Application";
|
||||||
|
inherit name;
|
||||||
|
desktopName = "zellij";
|
||||||
|
terminal = true;
|
||||||
|
genericName = "Terminal multiplexer";
|
||||||
|
comment = "Manage your terminal applications";
|
||||||
|
exec = "zellij";
|
||||||
|
icon = "zellij";
|
||||||
|
categories = ["ConsoleOnly;System"];
|
||||||
})
|
})
|
||||||
|
];
|
||||||
|
meta = with pkgs.lib; {
|
||||||
|
homepage = "https://github.com/zellij-org/zellij/";
|
||||||
|
description = "A terminal workspace with batteries included";
|
||||||
|
license = [licenses.mit];
|
||||||
|
};
|
||||||
|
in rec {
|
||||||
|
# crate2nix - better incremental builds, but uses ifd
|
||||||
|
packages.zellij = crate2nixPkgs.callPackage ./crate2nix.nix {
|
||||||
|
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
|
||||||
|
;
|
||||||
|
};
|
||||||
|
|
||||||
|
defaultPackage = packages.zellij;
|
||||||
|
|
||||||
|
# nix run
|
||||||
|
apps.zellij = flake-utils.lib.mkApp {drv = packages.zellij;};
|
||||||
|
defaultApp = apps.zellij;
|
||||||
|
|
||||||
|
devShells = {
|
||||||
|
zellij = pkgs.callPackage ./devShell.nix {
|
||||||
|
inherit buildInputs;
|
||||||
|
nativeBuildInputs = nativeBuildInputs ++ devInputs ++ fmtInputs;
|
||||||
|
};
|
||||||
|
fmtShell = pkgs.mkShell {
|
||||||
|
name = "fmt-shell";
|
||||||
|
nativeBuildInputs = fmtInputs;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
devShell = devShells.zellij;
|
||||||
|
})
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
17
shell.nix
17
shell.nix
|
|
@ -1,13 +1,14 @@
|
||||||
(import
|
(import
|
||||||
(
|
(
|
||||||
let
|
let
|
||||||
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
|
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
|
||||||
in
|
in
|
||||||
fetchTarball {
|
fetchTarball {
|
||||||
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
|
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
|
||||||
sha256 = lock.nodes.flake-compat.locked.narHash;
|
sha256 = lock.nodes.flake-compat.locked.narHash;
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
src = ./.;
|
src = ./.;
|
||||||
}).shellNix
|
})
|
||||||
|
.shellNix
|
||||||
|
|
|
||||||
3
treefmt.toml
Normal file
3
treefmt.toml
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
[formatter.nix]
|
||||||
|
command = "alejandra"
|
||||||
|
includes = ["*.nix"]
|
||||||
Loading…
Add table
Reference in a new issue