diff --git a/nix/crate2nix.nix b/nix/crate2nix.nix index c343fca9..1d7d7ff1 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 c1d5a886..4f967bfc 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 + buildInputs postInstall + patchPhase desktopItems meta ; }; - # musl cross-compilation - static binary - packages.zellij-musl = (pkgsMusl.makeRustPlatform {inherit rustc cargo;}).buildRustPackage { - inherit - src - name - cargoLock - postInstall - buildInputs - nativeBuildInputs - 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 00000000..b20f673d --- /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"; +}