From 5b9d021b59a5dca0c9e9a7afa397fca606d9dcae Mon Sep 17 00:00:00 2001 From: Gerg-L Date: Sat, 24 May 2025 23:44:44 -0400 Subject: [PATCH] refactor: move zellij to shared module --- nixosConfigurations/gerg-desktop/main.nix | 18 --------- nixosModules/zellij/default.nix | 39 +++++++++++++++++++ .../zellij}/monitor.ps | 0 3 files changed, 39 insertions(+), 18 deletions(-) create mode 100644 nixosModules/zellij/default.nix rename {nixosConfigurations/gerg-desktop => nixosModules/zellij}/monitor.ps (100%) diff --git a/nixosConfigurations/gerg-desktop/main.nix b/nixosConfigurations/gerg-desktop/main.nix index 960d59b..2935475 100644 --- a/nixosConfigurations/gerg-desktop/main.nix +++ b/nixosConfigurations/gerg-desktop/main.nix @@ -41,7 +41,6 @@ vesktop gh nixfmt-rfc-style - zellij tidal-hifi hyperfine @@ -135,23 +134,6 @@ zsh = { shellAliases.cd = "z"; - interactiveShellInit = - let - monitorScript = pkgs.replaceVarsWith { - src = ./monitor.ps; - replacements = builtins.mapAttrs (_: lib.getExe) { - inherit (pkgs) perl xdotool; - }; - isExecutable = true; - }; - in - '' - if [[ -z "$ZELLIJ" ]]; then - MONITOR="$(${monitorScript} || true)" - zellij attach -c "''${MONITOR:+"$MONITOR@"}$USER" - exit - fi - ''; }; nix-index = { diff --git a/nixosModules/zellij/default.nix b/nixosModules/zellij/default.nix new file mode 100644 index 0000000..b023b38 --- /dev/null +++ b/nixosModules/zellij/default.nix @@ -0,0 +1,39 @@ +{ + lib, + pkgs, + config, +}: +{ + options.local.zellij = lib.mkEnableOption "zellij" // { + default = true; + }; + + config = lib.mkIf config.local.zellij { + local.packages = { + inherit (pkgs) zellij; + }; + + programs.zsh.interactiveShellInit = + let + monitorScript = pkgs.replaceVarsWith { + src = ./monitor.ps; + replacements = builtins.mapAttrs (_: lib.getExe) { + inherit (pkgs) perl xdotool; + }; + isExecutable = true; + }; + in + '' + if [[ -z "$ZELLIJ" ]]; then + if [[ -n "$SSH_TTY" ]]; then + zellij attach -c "SSH@$USER" + else + MONITOR="$(${monitorScript} || true)" + zellij attach -c "''${MONITOR:+"$MONITOR@"}$USER" + fi + exit + fi + ''; + + }; +} diff --git a/nixosConfigurations/gerg-desktop/monitor.ps b/nixosModules/zellij/monitor.ps similarity index 100% rename from nixosConfigurations/gerg-desktop/monitor.ps rename to nixosModules/zellij/monitor.ps