From 23f46e51e6f607c8e0ef0830cc2c8f3b863540a3 Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Wed, 14 May 2025 15:04:49 -0400 Subject: [PATCH] zellij to trigger nix rebuild of hm and nixos or darwin --- hosts/aarch64-darwin/lookingglass/default.nix | 1 + hosts/aarch64-linux/flame/default.nix | 1 + hosts/x86_64-linux/arrow/default.nix | 1 + hosts/x86_64-linux/hydra/default.nix | 1 + hosts/x86_64-linux/staff/default.nix | 1 + hosts/x86_64-linux/swan/default.nix | 1 + hosts/x86_64-linux/tempest/default.nix | 1 + .../presets/programs/nixpkgs-darwin.nix | 6 +++++ .../nmasur/presets/programs/nixpkgs.nix | 26 ++++++++++++++++++- .../nmasur/presets/programs/zellij.nix | 26 ++++++++++++++++--- .../home-manager/modules/nmasur/settings.nix | 4 +++ 11 files changed, 64 insertions(+), 5 deletions(-) diff --git a/hosts/aarch64-darwin/lookingglass/default.nix b/hosts/aarch64-darwin/lookingglass/default.nix index 9978b41..f7938bf 100644 --- a/hosts/aarch64-darwin/lookingglass/default.nix +++ b/hosts/aarch64-darwin/lookingglass/default.nix @@ -21,6 +21,7 @@ rec { nmasur.settings = { username = nmasur.settings.username; fullName = nmasur.settings.fullName; + host = "lookingglass"; }; nmasur.profiles = { common.enable = true; diff --git a/hosts/aarch64-linux/flame/default.nix b/hosts/aarch64-linux/flame/default.nix index 9295e2e..f037c78 100644 --- a/hosts/aarch64-linux/flame/default.nix +++ b/hosts/aarch64-linux/flame/default.nix @@ -23,6 +23,7 @@ rec { nmasur.settings = { username = nmasur.settings.username; fullName = nmasur.settings.fullName; + host = networking.hostName; }; nmasur.profiles = { common.enable = true; diff --git a/hosts/x86_64-linux/arrow/default.nix b/hosts/x86_64-linux/arrow/default.nix index d9eb386..49cf09d 100644 --- a/hosts/x86_64-linux/arrow/default.nix +++ b/hosts/x86_64-linux/arrow/default.nix @@ -19,6 +19,7 @@ rec { nmasur.settings = { username = nmasur.settings.username; fullName = nmasur.settings.fullName; + host = networking.hostName; }; nmasur.profiles = { common.enable = true; diff --git a/hosts/x86_64-linux/hydra/default.nix b/hosts/x86_64-linux/hydra/default.nix index f93081e..a3cb5bf 100644 --- a/hosts/x86_64-linux/hydra/default.nix +++ b/hosts/x86_64-linux/hydra/default.nix @@ -19,6 +19,7 @@ rec { nmasur.settings = { username = nmasur.settings.username; fullName = nmasur.settings.fullName; + host = networking.hostName; }; nmasur.profiles = { common.enable = true; diff --git a/hosts/x86_64-linux/staff/default.nix b/hosts/x86_64-linux/staff/default.nix index 9ed9909..bab8bef 100644 --- a/hosts/x86_64-linux/staff/default.nix +++ b/hosts/x86_64-linux/staff/default.nix @@ -23,6 +23,7 @@ rec { nmasur.settings = { username = nmasur.settings.username; fullName = nmasur.settings.fullName; + host = networking.hostName; }; nmasur.profiles = { common.enable = true; diff --git a/hosts/x86_64-linux/swan/default.nix b/hosts/x86_64-linux/swan/default.nix index 04f28c1..e01d833 100644 --- a/hosts/x86_64-linux/swan/default.nix +++ b/hosts/x86_64-linux/swan/default.nix @@ -21,6 +21,7 @@ rec { nmasur.settings = { username = nmasur.settings.username; fullName = nmasur.settings.fullName; + host = networking.hostName; }; nmasur.profiles = { common.enable = true; diff --git a/hosts/x86_64-linux/tempest/default.nix b/hosts/x86_64-linux/tempest/default.nix index af82185..11e4916 100644 --- a/hosts/x86_64-linux/tempest/default.nix +++ b/hosts/x86_64-linux/tempest/default.nix @@ -23,6 +23,7 @@ rec { nmasur.settings = { username = nmasur.settings.username; fullName = nmasur.settings.fullName; + host = networking.hostName; }; nmasur.profiles = { common.enable = true; diff --git a/platforms/home-manager/modules/nmasur/presets/programs/nixpkgs-darwin.nix b/platforms/home-manager/modules/nmasur/presets/programs/nixpkgs-darwin.nix index 03d680c..4812d8f 100644 --- a/platforms/home-manager/modules/nmasur/presets/programs/nixpkgs-darwin.nix +++ b/platforms/home-manager/modules/nmasur/presets/programs/nixpkgs-darwin.nix @@ -21,6 +21,12 @@ in config = lib.mkIf (cfg.enable) { + # These are useful for triggering from zellij (rather than running directly in the shell) + nmasur.presets.programs.nixpkgs.commands.rebuildNixos = pkgs.writeShellScriptBin "rebuild-darwin" '' + git -C ${config.nmasur.presets.programs.dotfiles.path} add --intent-to-add --all + darwin-rebuild switch --flake "${config.nmasur.presets.programs.dotfiles.path}#${config.nmasur.settings.host}" + ''; + programs.fish = { shellAbbrs = lib.mkIf config.nmasur.presets.programs.dotfiles.enable { nr = { diff --git a/platforms/home-manager/modules/nmasur/presets/programs/nixpkgs.nix b/platforms/home-manager/modules/nmasur/presets/programs/nixpkgs.nix index 2a16041..a07d9d0 100644 --- a/platforms/home-manager/modules/nmasur/presets/programs/nixpkgs.nix +++ b/platforms/home-manager/modules/nmasur/presets/programs/nixpkgs.nix @@ -11,10 +11,34 @@ in { - options.nmasur.presets.programs.nixpkgs.enable = lib.mkEnableOption "Nixpkgs presets"; + options.nmasur.presets.programs.nixpkgs = { + enable = lib.mkEnableOption "Nixpkgs presets"; + commands = { + # These are useful for triggering from zellij (rather than running directly in the shell) + rebuildHome = lib.mkOption { + type = lib.types.package; + default = pkgs.writeShellScriptBin "rebuild-home" '' + git -C ${config.nmasur.presets.programs.dotfiles.path} add --intent-to-add --all + ${lib.getExe pkgs.home-manager} switch --flake "${config.nmasur.presets.programs.dotfiles.path}#${config.nmasur.settings.host}" + ''; + }; + rebuildNixos = lib.mkOption { + type = lib.types.package; + default = pkgs.writeShellScriptBin "rebuild-nixos" '' + git -C ${config.nmasur.presets.programs.dotfiles.path} add --intent-to-add --all + doas nixos-rebuild switch --flake ${config.nmasur.presets.programs.dotfiles.path} + ''; + }; + }; + }; config = lib.mkIf cfg.enable { + home.packages = [ + cfg.commands.rebuildHome + cfg.commands.rebuildNixos + ]; + programs.fish = { shellAbbrs = { n = "nix"; diff --git a/platforms/home-manager/modules/nmasur/presets/programs/zellij.nix b/platforms/home-manager/modules/nmasur/presets/programs/zellij.nix index 7fc21cb..c6a324f 100644 --- a/platforms/home-manager/modules/nmasur/presets/programs/zellij.nix +++ b/platforms/home-manager/modules/nmasur/presets/programs/zellij.nix @@ -121,14 +121,32 @@ in close_on_exit = true; }; }; + "bind \"Alt Shift h\"" = { + Run = { + _args = [ + (lib.getExe config.nmasur.presets.programs.nixpkgs.commands.rebuildHome) + ]; + # close_on_exit = false; + }; + }; + "bind \"Alt Shift r\"" = { + Run = { + _args = [ + (lib.getExe config.nmasur.presets.programs.nixpkgs.commands.rebuildNixos) + ]; + # close_on_exit = false; + }; + }; "bind \"Alt Shift w\"" = { Run = { _args = [ - "${pkgs.fish}/bin/fish" - "-c" - "gh-run" + (lib.getExe pkgs.gh) + "run" + "watch" ]; - close_on_exit = true; + # direction = "Right"; + # close_on_exit = false; + # start_suspended = true; }; }; "bind \"Super Shift ]\"" = { diff --git a/platforms/home-manager/modules/nmasur/settings.nix b/platforms/home-manager/modules/nmasur/settings.nix index cfe13da..2a0011e 100644 --- a/platforms/home-manager/modules/nmasur/settings.nix +++ b/platforms/home-manager/modules/nmasur/settings.nix @@ -10,6 +10,10 @@ type = lib.types.str; description = "Human readable name of the user"; }; + host = lib.mkOption { + type = lib.types.str; + description = "Name of the host of this deployment"; + }; hostnames = lib.mkOption { type = lib.types.attrsOf lib.types.str; description = "Map of service names to FQDNs";