summaryrefslogtreecommitdiffstats
path: root/.nix
diff options
context:
space:
mode:
authora-kenji <aks.kenji@protonmail.com>2022-07-10 15:31:41 +0200
committerGitHub <noreply@github.com>2022-07-10 15:31:41 +0200
commit47540d7cabae144f032c0fc4972e7c9af5ab5e8d (patch)
treebff664648ae4b772ee89e88a1aa971d07c4fcc56 /.nix
parentea3d73c105e92e808ca5319a3d259e2a454d4131 (diff)
chore(nix): hide `nix` directory (#1579)
Diffstat (limited to '.nix')
-rw-r--r--.nix/crate2nix.nix37
-rw-r--r--.nix/default.nix249
-rw-r--r--.nix/devShell.nix11
-rw-r--r--.nix/plugins.nix54
4 files changed, 351 insertions, 0 deletions
diff --git a/.nix/crate2nix.nix b/.nix/crate2nix.nix
new file mode 100644
index 000000000..1d7d7ff14
--- /dev/null
+++ b/.nix/crate2nix.nix
@@ -0,0 +1,37 @@
+{
+ pkgs,
+ crate2nix,
+ name,
+ src,
+ patchPhase,
+ 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
+ // {
+ # Crate dependency overrides go here
+ zellij = attrs: {
+ inherit postInstall desktopItems meta name nativeBuildInputs patchPhase;
+ };
+ };
+ };
+ };
+in
+ project.workspaceMembers.zellij.build
diff --git a/.nix/default.nix b/.nix/default.nix
new file mode 100644
index 000000000..c87221d81
--- /dev/null
+++ b/.nix/default.nix
@@ -0,0 +1,249 @@
+{
+ self,
+ nixpkgs,
+ rust-overlay,
+ flake-utils,
+ flake-compat,
+ crate2nix,
+}:
+flake-utils.lib.eachSystem [
+ "aarch64-linux"
+ "aarch64-darwin"
+ "i686-linux"
+ "x86_64-darwin"
+ "x86_64-linux"
+]
+(system: let
+ overlays = [(import rust-overlay)];
+
+ pkgs = import nixpkgs {inherit system overlays;};
+ pkgsMusl = import nixpkgs {
+ inherit system overlays;
+ crossSystem = {config = "x86_64-unknown-linux-musl";};
+ };
+
+ crate2nixPkgs = import nixpkgs {
+ inherit system;
+ overlays = [
+ (self: _: {
+ rustc = rustToolchainToml;
+ cargo = rustToolchainToml;
+ })
+ ];
+ };
+
+ crate2nixMsrvPkgs = import nixpkgs {
+ inherit system;
+ overlays = [
+ (self: _: {
+ rustc = msrvToolchain;
+ cargo = msrvToolchain;
+ })
+ ];
+ };
+
+ name = "zellij";
+ pname = name;
+ root = self;
+
+ ignoreSource = [".git" "target" "example"];
+
+ src = pkgs.nix-gitignore.gitignoreSource ignoreSource root;
+
+ cargoToml = builtins.fromTOML (builtins.readFile (src + "/Cargo.toml"));
+ toolchainToml = builtins.fromTOML (builtins.readFile (src + "/rust-toolchain.toml"));
+ rustToolchainToml = pkgs.rust-bin.fromRustupToolchainFile (src + "/rust-toolchain.toml");
+
+ msrvToolchain = pkgs.rust-bin.fromRustupToolchain {
+ channel = cargoToml.package.rust-version;
+ components = toolchainToml.toolchain.components;
+ targets = toolchainToml.toolchain.targets;
+ };
+
+ cargoLock = {
+ lockFile = builtins.path {
+ path = src + "/Cargo.lock";
+ name = "Cargo.lock";
+ };
+ };
+ cargo = rustToolchainToml;
+ rustc = rustToolchainToml;
+
+ buildInputs = [
+ # in order to run tests
+ pkgs.openssl
+ ];
+
+ nativeBuildInputs = [
+ # for openssl/openssl-sys
+ pkgs.pkg-config
+
+ # generates manpages
+ pkgs.mandown
+
+ pkgs.installShellFiles
+ pkgs.copyDesktopItems
+ ];
+
+ defaultPlugins = [
+ plugins.compact-bar
+ plugins.status-bar
+ plugins.tab-bar
+ plugins.strider
+ ];
+
+ pluginNativeBuildInputs = [
+ pkgs.pkg-config
+ # optimizes wasm binaries
+ pkgs.binaryen
+ ];
+
+ devInputs = [
+ rustToolchainToml
+
+ pkgs.cargo-make
+ pkgs.rust-analyzer
+
+ # optimizes wasm binaries
+ pkgs.binaryen
+
+ # used for snapshotting the e2e tests
+ pkgs.cargo-insta
+ ];
+
+ fmtInputs = [
+ pkgs.alejandra
+ 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
+
+ # 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
+
+ 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
+ cp ${plugins.compact-bar}/bin/compact-bar.wasm assets/plugins/compact-bar.wasm
+ '';
+
+ 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"];
+ })
+ ];
+ 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
+ crate2nix
+ desktopItems
+ postInstall
+ patchPhase
+ meta
+ ;
+ nativeBuildInputs = nativeBuildInputs ++ defaultPlugins;
+ };
+
+ packages.zellij-msrv = crate2nixMsrvPkgs.callPackage ./crate2nix.nix {
+ inherit
+ name
+ src
+ crate2nix
+ desktopItems
+ postInstall
+ patchPhase
+ meta
+ ;
+ nativeBuildInputs = nativeBuildInputs ++ defaultPlugins;
+ };
+
+ # native nixpkgs support - keep supported
+ packages.zellij-native = (pkgs.makeRustPlatform {inherit cargo rustc;}).buildRustPackage {
+ inherit
+ src
+ name
+ cargoLock
+ buildInputs
+ postInstall
+ patchPhase
+ desktopItems
+ meta
+ ;
+ nativeBuildInputs = nativeBuildInputs ++ defaultPlugins;
+ };
+ packages.default = packages.zellij;
+
+ packages.plugins-compact = plugins.compact-bar;
+ packages.plugins-status-bar = plugins.status-bar;
+ packages.plugins-tab-bar = plugins.tab-bar;
+ packages.plugins-strider = plugins.strider;
+
+ 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;
+ };
+ e2eShell = pkgs.pkgsMusl.mkShell {
+ name = "e2e-shell";
+ nativeBuildInputs = [
+ pkgs.cargo-make
+ pkgs.pkgsMusl.cargo
+ ];
+ };
+ };
+
+ devShell = devShells.zellij;
+})
+// rec {
+ overlays = {
+ default = final: prev: rec {
+ zellij = self.packages.${prev.system}.zellij;
+ };
+ nightly = final: prev: rec {
+ zellij-nightly = self.packages.${prev.system}.zellij;
+ };
+ };
+}
diff --git a/.nix/devShell.nix b/.nix/devShell.nix
new file mode 100644
index 000000000..261234f65
--- /dev/null
+++ b/.nix/devShell.nix
@@ -0,0 +1,11 @@
+{
+ mkShell,
+ buildInputs,
+ nativeBuildInputs,
+}:
+mkShell {
+ name = "zj-dev-env";
+ inherit buildInputs nativeBuildInputs;
+ ### Environment Variables
+ RUST_BACKTRACE = 1;
+}
diff --git a/.nix/plugins.nix b/.nix/plugins.nix
new file mode 100644
index 000000000..270544c95
--- /dev/null
+++ b/.nix/plugins.nix
@@ -0,0 +1,54 @@
+{
+ 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";
+ compact-bar = makeDefaultPlugin "compact-bar";
+}