pinpox / lollypops

Lollypop Operations - NixOS Deployment Tool
https://pinpox.github.io/lollypops/
GNU General Public License v3.0
118 stars 17 forks source link

Rebuilding on local machine? #29

Closed jhakonen closed 4 months ago

jhakonen commented 6 months ago

How do I rebuild my configuration to my local NixOS laptop?

I have so far used this command to rebuild it:

sudo nixos-rebuild switch --flake '.#dellxps13'

Now I'm trying to take lollypops into use and I wonder what would be the equivalent with it?

I tried this but lollypops starts fiddling with ssh:

$ nix run '.' -- dellxps13
warning: Git tree '/home/jhakonen/nixos-config' is dirty
[dellxps13:deploy-flake] Deploying flake to: dellxps13
[dellxps13:deploy-flake] ssh: connect to host dellxps13 port 22: Connection refused
[dellxps13:deploy-flake] rsync: connection unexpectedly closed (0 bytes received so far) [sender]
[dellxps13:deploy-flake] rsync error: unexplained error (code 255) at io.c(231) [sender=3.2.7]
task: Failed to run task "dellxps13": exit status 255

I have set lollypops.deployment.local-evaluation = true; but it doesn't seem to have any effect. I don't have ssh server setup on the laptop, so its expected that connect would fail. The flake config is at current working directory, so there shouldn't be any reason to connect anywhere. Do I need some extra configuration to get this working?

pinpox commented 6 months ago

Hello :wave:, lollypops expects an SSH server running and treats localhost as any other host. If you don't want to expose your laptop via ssh, you can configure it to only accept connections on port 22 at the 127.0.0.1 address.

local-evaluation causes nixos-rebuild to evaluate locally, but the --target-host is stil reached via SSH. Also the copying operation is done via rsync over ssh.

jhakonen commented 6 months ago

Ah, thank you, now I understand. Used to do local deployment for my laptop, I was confused how to do it with lollypops. Using ssh as you suggested worked just fine!

In my old way of deploying configs to remote hosts (nixos vm on synology, nixos gaming/kodi pc, and nixos rpi3) I had remote commands for running:

I cooked up custom tasks for doing those like so:

lollypops.extraTasks.reboot = {
  desc = "Reboot machine";
  cmds = [
    "echo Rebooting machine"
    "ssh ${config.lollypops.deployment.ssh.user}@${config.lollypops.deployment.ssh.host} reboot"
  ];
};
lollypops.extraTasks.rebuild-debug = {
  desc = "Rebuild with debug output";
  cmds = [
    "echo Rebuilding with debug information"
    ''
    ssh ${config.lollypops.deployment.ssh.user}@${config.lollypops.deployment.ssh.host} \
      nixos-rebuild switch \
        --flake '${config.lollypops.deployment.config-dir}#${config.lollypops.deployment.ssh.host}' \
        --show-trace --verbose --option eval-cache false
    ''
  ];
};

In order to figure out how to run remote commands I had to check lollypops's sources and come up with a similar ssh command to do it. Would it make sense have some custom command that would allow running commands on the remote host, e.g. remote-run reboot that would be exposed to the task cmds?

Also exposing something like e.g. the flake's path#config as a variable would be useful.

pinpox commented 4 months ago

Would it make sense have some custom command that would allow running commands on the remote host, e.g. remote-run reboot that would be exposed to the task cmds? Also exposing something like e.g. the flake's path#config as a variable would be useful.

I'm open to review PR's on this if you want to give it a go. I think that is a separate issue though, so I'll close this one as the original question seems fixed