summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authora-kenji <aks.kenji@protonmail.com>2022-04-12 09:25:25 +0200
committerGitHub <noreply@github.com>2022-04-12 09:25:25 +0200
commitbc44a77f1c80c27f5acc4be38853244977148bc5 (patch)
tree23962a4b9a4a6869d2cabe3b86a2db76503fdf5b
parentac3c09066b461d5e66bb5447741878b8a3a94642 (diff)
add: plugins to nix builds (#1314)
* add: plugins to nix builds * chore(fmt): treefmt
-rw-r--r--nix/crate2nix.nix3
-rw-r--r--nix/default.nix53
-rw-r--r--nix/plugins.nix53
3 files changed, 91 insertions, 18 deletions
diff --git a/nix/crate2nix.nix b/nix/crate2nix.nix
index c343fca9c..1d7d7ff14 100644
--- a/nix/crate2nix.nix
+++ b/nix/crate2nix.nix
@@ -3,6 +3,7 @@
crate2nix,
name,
src,
+ patchPhase,
postInstall,
nativeBuildInputs,
desktopItems,
@@ -27,7 +28,7 @@
// {
# Crate dependency overrides go here
zellij = attrs: {
- inherit postInstall desktopItems meta name nativeBuildInputs;
+ inherit postInstall desktopItems meta name nativeBuildInputs patchPhase;
};
};
};
diff --git a/nix/default.nix b/nix/default.nix
index c1d5a8868..4f967bfc6 100644
--- a/nix/default.nix
+++ b/nix/default.nix
@@ -40,10 +40,12 @@ flake-utils.lib.eachSystem [
src = pkgs.nix-gitignore.gitignoreSource ignoreSource root;
+ cargoToml = builtins.fromTOML (builtins.readFile (src + ./Cargo.toml));
rustToolchainToml = pkgs.rust-bin.fromRustupToolchainFile (src + "/rust-toolchain.toml");
+
cargoLock = {
lockFile = builtins.path {
- path = ../Cargo.lock;
+ path = src + "/Cargo.lock";
name = "Cargo.lock";
};
};
@@ -56,10 +58,14 @@ flake-utils.lib.eachSystem [
];
nativeBuildInputs = [
- rustToolchainToml
# for openssl/openssl-sys
pkgs.pkg-config
+ # default plugins
+ plugins.status-bar
+ plugins.tab-bar
+ plugins.strider
+
# generates manpages
pkgs.mandown
@@ -67,7 +73,15 @@ flake-utils.lib.eachSystem [
pkgs.copyDesktopItems
];
+ pluginNativeBuildInputs = [
+ pkgs.pkg-config
+ # optimizes wasm binaries
+ pkgs.binaryen
+ ];
+
devInputs = [
+ rustToolchainToml
+
pkgs.cargo-make
pkgs.rust-analyzer
@@ -83,6 +97,11 @@ flake-utils.lib.eachSystem [
pkgs.treefmt
];
+ plugins = import ./plugins.nix {
+ inherit root pkgs cargo rustc cargoLock buildInputs;
+ nativeBuildInputs = pluginNativeBuildInputs;
+ };
+
postInstall = ''
mandown ./docs/MANPAGE.md > ./zellij.1
installManPage ./zellij.1
@@ -99,6 +118,11 @@ flake-utils.lib.eachSystem [
copyDesktopItems
'';
+ patchPhase = ''
+ cp ${plugins.tab-bar}/bin/tab-bar.wasm assets/plugins/tab-bar.wasm
+ cp ${plugins.status-bar}/bin/status-bar.wasm assets/plugins/status-bar.wasm
+ cp ${plugins.strider}/bin/strider.wasm assets/plugins/strider.wasm
+ '';
desktopItems = [
(pkgs.makeDesktopItem {
@@ -124,10 +148,11 @@ in rec {
inherit
name
src
- nativeBuildInputs
crate2nix
+ nativeBuildInputs
desktopItems
postInstall
+ patchPhase
meta
;
};
@@ -138,26 +163,20 @@ in rec {
src
name
cargoLock
- buildInputs
nativeBuildInputs
- postInstall
- desktopItems
- meta
- ;
- };
- # musl cross-compilation - static binary
- packages.zellij-musl = (pkgsMusl.makeRustPlatform {inherit rustc cargo;}).buildRustPackage {
- inherit
- src
- name
- cargoLock
- postInstall
buildInputs
- nativeBuildInputs
+ postInstall
+ patchPhase
desktopItems
meta
;
};
+ packages.default = packages.zellij;
+
+ packages.plugins-status-bar = plugins.status-bar;
+ packages.plugins-tab-bar = plugins.tab-bar;
+ packages.plugins-strider = plugins.strider;
+
defaultPackage = packages.zellij;
# nix run
diff --git a/nix/plugins.nix b/nix/plugins.nix
new file mode 100644
index 000000000..b20f673da
--- /dev/null
+++ b/nix/plugins.nix
@@ -0,0 +1,53 @@
+{
+ pkgs,
+ root,
+ cargo,
+ rustc,
+ cargoLock,
+ nativeBuildInputs,
+ buildInputs,
+}: let
+ ignoreSource = [
+ ".git"
+ ".github"
+ "assets"
+ "docs"
+ "example"
+ "target"
+ ".editorconfig"
+ ".envrc"
+ ".git-blame-ignore-revs"
+ "CHANGELOG.md"
+ "CODE_OF_CONDUCT.md"
+ "CONTRIBUTING.md"
+ "GOVERNANCE.md"
+ "LICENSE.md"
+ "docker-compose.yml"
+ ];
+ src = pkgs.nix-gitignore.gitignoreSource ignoreSource root;
+
+ makeDefaultPlugin = name:
+ (pkgs.makeRustPlatform {inherit cargo rustc;}).buildRustPackage {
+ inherit
+ src
+ name
+ cargoLock
+ buildInputs
+ nativeBuildInputs
+ ;
+ buildPhase = ''
+ cargo build --package ${name} --release --target=wasm32-wasi
+ mkdir -p $out/bin;
+ #cp target/wasm32-wasi/release/${name}.wasm $out/bin/${name}.wasm
+ wasm-opt \
+ -O target/wasm32-wasi/release/${name}.wasm \
+ -o $out/bin/${name}.wasm
+ '';
+ installPhase = ":";
+ checkPhase = ":";
+ };
+in {
+ status-bar = makeDefaultPlugin "status-bar";
+ tab-bar = makeDefaultPlugin "tab-bar";
+ strider = makeDefaultPlugin "strider";
+}