Nix Zellij
A quick blog post on using nix with Zellij.
Where I can't get my favourite Tmux configuration going, I often turn to Zellij. Zellij is a great alternative to Tmux and offers some cool elements, which I may revisit in a future blog post. For now, I just want to outline how to perform a similar layout configuration to the Tmux one I recently wrote.
You can amend the configuration used to setup the screen however you wish.
Just amend the dev.kdl script to realign your screen layout however you want.
Nix Scripts
To get started we need to define an external script to represent the environment requirement. Zellij uses kdl files to represent screen layouts, so the configuration slightly different to Tmux.
-
Lets create a zellij layout script
dev.kdl:1layout { 2 tab name="Go Dev" focus=true { 3 pane split_direction="vertical" { 4 pane { 5 name "Terminal#1" 6 } 7 pane split_direction="horizontal" { 8 pane { 9 name "Termina#2" 10 } 11 pane { 12 name "Terminal#3" 13 } 14 } 15 } 16 } 17}In the above
dev.kdlscript we create a new layout. -
We now need to tell Nix to add the
dev.kdlexternal script as a dependency.1let 2 # External Script: This reads './dev.kdl' and puts it into a binary named 'dev-kdl' 3 # The layout is then set as a dependency for the `zellijLayout` which will be used in the script. 4 scriptZellijLayout = pkgs.writeText "dev.kdl" (builtins.readFile ./dev.kdl); 5 zellijLayout = pkgs.writeShellScriptBin "dev-zellij" '' 6 ${pkgs.zellij}/bin/zellij --layout ${scriptZellijLayout} 7 ''; 8in -
Now we can create a
shell.nixscript:1with import <nixpkgs> {}; 2 3let 4 scriptZellijLayout = pkgs.writeText "dev.kdl" (builtins.readFile ./dev.kdl); 5 zellijLayout = pkgs.writeShellScriptBin "dev-zellij" '' 6 ${pkgs.zellij}/bin/zellij --layout ${scriptZellijLayout} 7 ''; 8in 9pkgs.mkShell { 10 11 name = "go-dev"; 12 nativeBuildInputs = with pkgs; [ 13 go 14 zellij 15 zellijLayout # Custom Zellij script with layout 16 ]; 17 18 LANGUAGE = "Go"; 19 VERSION = "go version"; 20 21 shellHook = '' 22 # Optional: Script environment start up 23 echo "Welcome to $LANGUAGE Development Environment" 24 $VERSION 25 26 # Perform Zellij Dev Layout 27 dev-zellij 28 ''; 29}The above script will initiate a
zellijenvironment. When the nix script executes it will automatically call the dev-zellij to handle the screen layout. -
Run the script:
1nix-shell --pureRemember a pure environment tries to ignore the existing host configuration 😂 Nix will automatically look for the file
shell.nixso you dont need to added this parameter 🥰Expected Output:
1Welcome to Go Development Environment 2go version go1.25.5 darwin/arm64Awesome, Zellij is configured and ready to go!
-
Exit the Nix Shell
To exit, you will need to exit each screen individually.
1exit
Nice we now have a super easy way to run Zellij on a Nix machine.