From 56b232aa54990a8b883fceaa89dce7f489bd973d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Geoffrey=20=E2=80=9CFrogeye=E2=80=9D=20Preud=27homme?= Date: Sat, 6 Apr 2024 16:14:27 +0200 Subject: [PATCH] Make local-evaluation overridable at runtime Adds an environment variable `LP_LOCAL_EVALUATION` which overrides `lollypops.deployment.local-evaluation` at runtime. Use case: Sometimes I'm deploying from my main workstation which is more powerful than the servers, so building locally makes sense. Other times I'm deploying from my crappy ARM laptop which is barely capable of building itself. I'd like to switch from one to the other without having to modify the flake of my system. --- README.md | 6 +++--- flake.nix | 17 ++++++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 1f96fda..5177e93 100644 --- a/README.md +++ b/README.md @@ -213,9 +213,9 @@ lollypops.deployment = { }; ``` -Setting `lollypops.deployment.local-evaluation` to true, will result in -evaluation being done on the local side. This requires `nixos-rebuild` in your -`$PATH` +Setting `lollypops.deployment.local-evaluation` or the environment variable +`LP_LOCAL_EVALUATION` to true, will result in evaluation being done on the +local side. This requires `nixos-rebuild` in your `$PATH`. **Note:** Rsync is required on the remote for remote evaluation to work. While the lollypops module will add the package to `environment.systemPackages` it may diff --git a/flake.nix b/flake.nix index 57845d2..ef90f13 100644 --- a/flake.nix +++ b/flake.nix @@ -104,6 +104,7 @@ REBUILD_ACTION = ''{{default "switch" .REBUILD_ACTION}}''; REMOTE_CONFIG_DIR = deployment.config-dir; LOCAL_FLAKE_SOURCE = configFlake; + LOCAL_EVALUATION = ''{{default "${pkgs.lib.optionalString deployment.local-evaluation "true"}" .LP_LOCAL_EVALUATION}}''; HOSTNAME = hostName; }; @@ -179,17 +180,19 @@ desc = "Rebuild configuration of: ${hostName}"; deps = [ "check-vars" ]; cmds = [ - (if hostConfig.config.lollypops.deployment.local-evaluation then - '' + '' + if [ "{{.LOCAL_EVALUATION}}" = "true" ] + then NIX_SSHOPTS="{{.REMOTE_SSH_OPTS}}" nixos-rebuild {{.REBUILD_ACTION}} \ --flake '{{.LOCAL_FLAKE_SOURCE}}#{{.HOSTNAME}}' \ --target-host {{.REMOTE_USER}}@{{.REMOTE_HOST}} \ ${optionalString useSudo "--use-remote-sudo"} - '' else '' - {{.REMOTE_COMMAND}} {{.REMOTE_SSH_OPTS}} {{.REMOTE_USER}}@{{.REMOTE_HOST}} \ - "${optionalString useSudo "{{.REMOTE_SUDO_COMMAND}} {{.REMOTE_SUDO_OPTS}}"} nixos-rebuild {{.REBUILD_ACTION}} \ - --flake '{{.REMOTE_CONFIG_DIR}}#{{.HOSTNAME}}'" - '') + else + echo {{.REMOTE_COMMAND}} {{.REMOTE_SSH_OPTS}} {{.REMOTE_USER}}@{{.REMOTE_HOST}} \ + "${optionalString useSudo "{{.REMOTE_SUDO_COMMAND}} {{.REMOTE_SUDO_OPTS}}"} nixos-rebuild {{.REBUILD_ACTION}} \ + --flake '{{.REMOTE_CONFIG_DIR}}#{{.HOSTNAME}}'" + fi + '' ]; };