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
|
||||
|
||||
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:
|
||||
|
|
|
|||
17
default.nix
17
default.nix
|
|
@ -1,13 +1,14 @@
|
|||
(import
|
||||
(
|
||||
let
|
||||
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
|
||||
in
|
||||
(
|
||||
let
|
||||
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
|
||||
in
|
||||
fetchTarball {
|
||||
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
|
||||
sha256 = lock.nodes.flake-compat.locked.narHash;
|
||||
}
|
||||
)
|
||||
{
|
||||
src = ./.;
|
||||
}).defaultNix
|
||||
)
|
||||
{
|
||||
src = ./.;
|
||||
})
|
||||
.defaultNix
|
||||
|
|
|
|||
|
|
@ -14,5 +14,5 @@
|
|||
crate2nix.flake = false;
|
||||
};
|
||||
|
||||
outputs = { ... } @ args: import ./nix args;
|
||||
outputs = {...} @ args: import ./nix args;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,34 +1,35 @@
|
|||
{ 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 {
|
||||
inherit name src;
|
||||
})
|
||||
{
|
||||
inherit pkgs;
|
||||
buildRustCrateForPkgs = pkgs:
|
||||
pkgs.buildRustCrate.override {
|
||||
defaultCrateOverrides = pkgs.defaultCrateOverrides // {
|
||||
(generatedCargoNix {
|
||||
inherit name src;
|
||||
})
|
||||
{
|
||||
inherit pkgs;
|
||||
buildRustCrateForPkgs = pkgs:
|
||||
pkgs.buildRustCrate.override {
|
||||
defaultCrateOverrides =
|
||||
pkgs.defaultCrateOverrides
|
||||
// {
|
||||
# Crate dependency overrides go here
|
||||
zellij = attrs: {
|
||||
inherit postInstall desktopItems meta name nativeBuildInputs;
|
||||
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
};
|
||||
in
|
||||
project.workspaceMembers.zellij.build
|
||||
project.workspaceMembers.zellij.build
|
||||
|
|
|
|||
246
nix/default.nix
246
nix/default.nix
|
|
@ -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,128 +13,153 @@ flake-utils.lib.eachSystem [
|
|||
"x86_64-darwin"
|
||||
"x86_64-linux"
|
||||
]
|
||||
(system:
|
||||
let
|
||||
overlays = [ (import rust-overlay) ];
|
||||
(system: let
|
||||
overlays = [(import rust-overlay)];
|
||||
|
||||
pkgs = import nixpkgs { inherit system overlays; };
|
||||
pkgs = import nixpkgs {inherit system overlays;};
|
||||
|
||||
crate2nixPkgs = import nixpkgs { inherit system;
|
||||
overlays = [
|
||||
(self: _: {
|
||||
rustc = rustToolchainToml;
|
||||
cargo = rustToolchainToml;
|
||||
})
|
||||
crate2nixPkgs = import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [
|
||||
(self: _: {
|
||||
rustc = rustToolchainToml;
|
||||
cargo = rustToolchainToml;
|
||||
})
|
||||
];
|
||||
};
|
||||
|
||||
];};
|
||||
name = "zellij";
|
||||
pname = name;
|
||||
root = toString ../.;
|
||||
|
||||
name = "zellij";
|
||||
pname = name;
|
||||
root = toString ../.;
|
||||
ignoreSource = [".git" "target" "example"];
|
||||
|
||||
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;
|
||||
cargoLock = {
|
||||
lockFile = (builtins.path { path = ../Cargo.lock; name = "Cargo.lock"; });
|
||||
};
|
||||
cargo = rustToolchainToml;
|
||||
rustc = rustToolchainToml;
|
||||
buildInputs = [
|
||||
rustToolchainToml
|
||||
|
||||
buildInputs = [
|
||||
rustToolchainToml
|
||||
# in order to run tests
|
||||
pkgs.openssl
|
||||
];
|
||||
|
||||
# in order to run tests
|
||||
pkgs.openssl
|
||||
];
|
||||
nativeBuildInputs = [
|
||||
# generates manpages
|
||||
pkgs.mandown
|
||||
|
||||
nativeBuildInputs = [
|
||||
# generates manpages
|
||||
pkgs.mandown
|
||||
pkgs.installShellFiles
|
||||
pkgs.copyDesktopItems
|
||||
|
||||
pkgs.installShellFiles
|
||||
pkgs.copyDesktopItems
|
||||
# for openssl/openssl-sys
|
||||
pkgs.pkg-config
|
||||
];
|
||||
|
||||
# for openssl/openssl-sys
|
||||
pkgs.pkg-config
|
||||
];
|
||||
devInputs = [
|
||||
pkgs.cargo-make
|
||||
pkgs.rust-analyzer
|
||||
|
||||
devInputs = [
|
||||
pkgs.cargo-make
|
||||
pkgs.rust-analyzer
|
||||
pkgs.nixpkgs-fmt
|
||||
# optimizes wasm binaries
|
||||
pkgs.binaryen
|
||||
|
||||
# optimizes wasm binaries
|
||||
pkgs.binaryen
|
||||
# used for snapshotting the e2e tests
|
||||
pkgs.cargo-insta
|
||||
];
|
||||
|
||||
# used for snapshotting the e2e tests
|
||||
pkgs.cargo-insta
|
||||
];
|
||||
fmtInputs = [
|
||||
pkgs.alejandra
|
||||
pkgs.treefmt
|
||||
];
|
||||
|
||||
postInstall = ''
|
||||
mandown ./docs/MANPAGE.md > ./zellij.1
|
||||
installManPage ./zellij.1
|
||||
postInstall = ''
|
||||
mandown ./docs/MANPAGE.md > ./zellij.1
|
||||
installManPage ./zellij.1
|
||||
|
||||
# explicit behavior
|
||||
$out/bin/zellij setup --generate-completion bash > ./completions.bash
|
||||
installShellCompletion --bash --name ${pname}.bash ./completions.bash
|
||||
$out/bin/zellij setup --generate-completion fish > ./completions.fish
|
||||
installShellCompletion --fish --name ${pname}.fish ./completions.fish
|
||||
$out/bin/zellij setup --generate-completion zsh > ./completions.zsh
|
||||
installShellCompletion --zsh --name _${pname} ./completions.zsh
|
||||
# explicit behavior
|
||||
$out/bin/zellij setup --generate-completion bash > ./completions.bash
|
||||
installShellCompletion --bash --name ${pname}.bash ./completions.bash
|
||||
$out/bin/zellij setup --generate-completion fish > ./completions.fish
|
||||
installShellCompletion --fish --name ${pname}.fish ./completions.fish
|
||||
$out/bin/zellij setup --generate-completion zsh > ./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
|
||||
'';
|
||||
|
||||
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;
|
||||
};
|
||||
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
|
||||
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
|
||||
, nativeBuildInputs
|
||||
{
|
||||
mkShell,
|
||||
buildInputs,
|
||||
nativeBuildInputs,
|
||||
}:
|
||||
|
||||
mkShell {
|
||||
name = "zj-dev-env";
|
||||
inherit buildInputs nativeBuildInputs;
|
||||
|
|
|
|||
17
shell.nix
17
shell.nix
|
|
@ -1,13 +1,14 @@
|
|||
(import
|
||||
(
|
||||
let
|
||||
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
|
||||
in
|
||||
(
|
||||
let
|
||||
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
|
||||
in
|
||||
fetchTarball {
|
||||
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
|
||||
sha256 = lock.nodes.flake-compat.locked.narHash;
|
||||
}
|
||||
)
|
||||
{
|
||||
src = ./.;
|
||||
}).shellNix
|
||||
)
|
||||
{
|
||||
src = ./.;
|
||||
})
|
||||
.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