diff options
Diffstat (limited to '')
| -rw-r--r-- | flake/scripts/default.nix | 4 | ||||
| -rw-r--r-- | flake/scripts/remote.nix | 134 | ||||
| -rw-r--r-- | machines/darwin/aarch64-darwin/mba-m2.nix | 2 | ||||
| -rw-r--r-- | profiles/defaults.nix | 1 | ||||
| -rw-r--r-- | profiles/remote-builder.nix (renamed from profiles/nix/remote-builder.nix) | 4 |
5 files changed, 141 insertions, 4 deletions
diff --git a/flake/scripts/default.nix b/flake/scripts/default.nix index db6febe..6b16e75 100644 --- a/flake/scripts/default.nix +++ b/flake/scripts/default.nix @@ -6,10 +6,12 @@ let common = import ./common.nix { inherit pkgs; }; darwin = import ./darwin.nix { inherit pkgs system inputs; }; + remote = import ./remote.nix { inherit pkgs system inputs; }; in { common = common; + remote = remote; darwin = if pkgs.lib.hasSuffix "darwin" system then darwin else [ ]; - all = common ++ (if pkgs.lib.hasSuffix "darwin" system then darwin else [ ]); + all = common ++ remote ++ (if pkgs.lib.hasSuffix "darwin" system then darwin else [ ]); } diff --git a/flake/scripts/remote.nix b/flake/scripts/remote.nix new file mode 100644 index 0000000..c96aa81 --- /dev/null +++ b/flake/scripts/remote.nix @@ -0,0 +1,134 @@ +{ + pkgs, +}: +[ + (pkgs.writeScriptBin "rbuild" '' + #!${pkgs.bash}/bin/bash + set -e + + # Check if host argument is provided + if [ -z "$1" ]; then + echo "❌ Error: Please specify a host" + echo "Usage: rbuild <hostname>" + echo "Example: rbuild rivendell" + exit 1 + fi + + HOST="$1" + echo "> Running nixos-rebuild build for $HOST..." + + ${pkgs.nixos-rebuild}/bin/nixos-rebuild build \ + --keep-going \ + --flake ".#$HOST" \ + --target-host "$HOST" \ + --fast \ + --use-remote-sudo \ + --use-substitutes + + echo "> nixos-rebuild build for $HOST was successful ✅" + '') + + (pkgs.writeScriptBin "rswitch" '' + #!${pkgs.bash}/bin/bash + set -e + + # Check if host argument is provided + if [ -z "$1" ]; then + echo "❌ Error: Please specify a host" + echo "Usage: rswitch <hostname>" + echo "Example: rswitch rivendell" + exit 1 + fi + + HOST="$1" + echo "> Running nixos-rebuild switch for $HOST..." + + ${pkgs.nixos-rebuild}/bin/nixos-rebuild switch \ + --keep-going \ + --flake ".#$HOST" \ + --target-host "$HOST" \ + --fast \ + --use-remote-sudo \ + --use-substitutes + + echo "> NixOS config was successfully applied to $HOST 🚀" + '') + + (pkgs.writeScriptBin "rdeploy" '' + #!${pkgs.bash}/bin/bash + set -e + + # Check if host argument is provided + if [ -z "$1" ]; then + echo "❌ Error: Please specify a host" + echo "Usage: rdeploy <hostname>" + echo "Example: rdeploy rivendell" + exit 1 + fi + + HOST="$1" + echo "> Deploying NixOS configuration to $HOST..." + echo "" + + # First build + echo "📦 Step 1/2: Building configuration..." + ${pkgs.nixos-rebuild}/bin/nixos-rebuild build \ + --keep-going \ + --flake ".#$HOST" \ + --target-host "$HOST" \ + --fast \ + --use-remote-sudo \ + --use-substitutes + + echo "" + echo "🔄 Step 2/2: Switching configuration..." + ${pkgs.nixos-rebuild}/bin/nixos-rebuild switch \ + --keep-going \ + --flake ".#$HOST" \ + --target-host "$HOST" \ + --fast \ + --use-remote-sudo \ + --use-substitutes + + echo "" + echo "> NixOS deployment to $HOST completed successfully! 🎉" + '') + + (pkgs.writeScriptBin "rhosts" '' + #!${pkgs.bash}/bin/bash + echo "> Available NixOS hosts in your flake:" + echo "" + + # This attempts to list nixosConfigurations from the flake + # You might need to adjust this based on your flake structure + nix flake show --json 2>/dev/null | \ + ${pkgs.jq}/bin/jq -r '.nixosConfigurations | keys[]' 2>/dev/null || \ + echo "Unable to list hosts automatically. Check your flake/hosts.nix" + '') + + (pkgs.writeScriptBin "rtest" '' + #!${pkgs.bash}/bin/bash + set -e + + # Check if host argument is provided + if [ -z "$1" ]; then + echo "❌ Error: Please specify a host" + echo "Usage: rtest <hostname>" + echo "Example: rtest rivendell" + exit 1 + fi + + HOST="$1" + echo "> Running dry-run build for $HOST..." + + ${pkgs.nixos-rebuild}/bin/nixos-rebuild dry-build \ + --keep-going \ + --flake ".#$HOST" \ + --target-host "$HOST" \ + --fast \ + --use-remote-sudo \ + --use-substitutes + + echo "> Dry-run build for $HOST completed ✅" + '') +] diff --git a/machines/darwin/aarch64-darwin/mba-m2.nix b/machines/darwin/aarch64-darwin/mba-m2.nix index 943ccf0..d4c444a 100644 --- a/machines/darwin/aarch64-darwin/mba-m2.nix +++ b/machines/darwin/aarch64-darwin/mba-m2.nix @@ -11,7 +11,7 @@ imports = [ ../../../profiles/darwin.nix ../../../profiles/home-manager.nix - ../../../profiles/nix/remote-builder.nix + ../../../profiles/remote-builder.nix ]; # https://github.com/nix-darwin/nix-darwin/issues/1339 diff --git a/profiles/defaults.nix b/profiles/defaults.nix index 80292b6..573bf68 100644 --- a/profiles/defaults.nix +++ b/profiles/defaults.nix @@ -103,6 +103,7 @@ security.sudo.wheelNeedsPassword = false; environment.systemPackages = with pkgs; [ + bottom curl dysk fd diff --git a/profiles/nix/remote-builder.nix b/profiles/remote-builder.nix index 50d3e84..3aa772f 100644 --- a/profiles/nix/remote-builder.nix +++ b/profiles/remote-builder.nix @@ -13,7 +13,7 @@ "x86_64-linux" ]; - maxJobs = 1; + maxJobs = 4; supportedFeatures = [ "nixos-test" @@ -26,7 +26,7 @@ programs.ssh.extraConfig = '' Host builder User builder - HostName vm-synology + HostName rivendell IdentityFile ${config.age.secrets.ssh-remote-builder.path} ''; } |
