Skip to content

Commit

Permalink
Make local-evaluation overridable at runtime
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
GeoffreyFrogeye committed Apr 6, 2024
1 parent 17239c6 commit 703d55e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 10 additions & 7 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down Expand Up @@ -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
{{.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
''
];
};

Expand Down

0 comments on commit 703d55e

Please sign in to comment.