Skip to content

Commit

Permalink
Merge pull request #33 from GeoffreyFrogeye/use-nix-flake-archive
Browse files Browse the repository at this point in the history
Use `nix flake archive` or `nix copy`
  • Loading branch information
pinpox authored Apr 10, 2024
2 parents 23e8069 + 75a618a commit e501dfe
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 38 deletions.
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,8 @@ Setting `lollypops.deployment.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
be missing still on the first deployment. To fix this, either add it to your
$PATH on the remote side or do your first deployment with
`lollypops.deployment.local-evaluation` set to `true`.

**Note:** If your flake includes remote Git repositories in its inputs, `git` is
required to be installed on the remote host.
**Note:** If using `sudo`, the user you're connecting as still needs to be able
to access the Nix daemon. This is the default in NixOS.

### Secrets

Expand Down
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 21 additions & 20 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@
${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}}'"
'${optionalString useSudo "{{.REMOTE_SUDO_COMMAND}} {{.REMOTE_SUDO_OPTS}}"} nixos-rebuild {{.REBUILD_ACTION}} \
--flake "$(readlink -f {{.REMOTE_CONFIG_DIR}}/flake)#{{.HOSTNAME}}"'
'')
];
};
Expand All @@ -199,24 +199,25 @@
desc = "Deploy flake repository to: ${hostName}";
cmds = [
''echo "Deploying flake to: {{.HOSTNAME}}"''
(if hostConfig.config.lollypops.deployment.deploy-method == "archive" then
''
NIX_SSHOPTS="{{.REMOTE_SSH_OPTS}}" nix flake archive \
--to ssh://{{.REMOTE_USER}}@{{.REMOTE_HOST}} \
--option builders-use-substitutes true \
{{.LOCAL_FLAKE_SOURCE}}
''
else
''
NIX_SSHOPTS="{{.REMOTE_SSH_OPTS}}" nix copy \
--to ssh://{{.REMOTE_USER}}@{{.REMOTE_HOST}} \
--substitute-on-destination \
--option builders-use-substitutes true \
{{.LOCAL_FLAKE_SOURCE}}
''
)
''
source_path={{.LOCAL_FLAKE_SOURCE}}
if test -d "$source_path"; then
source_path=$source_path/
fi
${pkgs.rsync}/bin/rsync \
--verbose \
-e "{{.REMOTE_COMMAND}} -l {{.REMOTE_USER}} -T {{.REMOTE_SSH_OPTS}}" \
-FD \
--checksum \
--times \
--perms \
--recursive \
--links \
--delete-excluded \
--mkpath \
${optionalString useSudo ''--rsync-path="{{.REMOTE_SUDO_COMMAND}} {{.REMOTE_SUDO_OPTS}} rsync"''} \
$source_path {{.REMOTE_USER}}\@{{.REMOTE_HOST}}:{{.REMOTE_CONFIG_DIR}}
{{.REMOTE_COMMAND}} {{.REMOTE_SSH_OPTS}} {{.REMOTE_USER}}@{{.REMOTE_HOST}} \
"${optionalString useSudo "{{.REMOTE_SUDO_COMMAND}} {{.REMOTE_SUDO_OPTS}}"} ln -sfn {{.LOCAL_FLAKE_SOURCE}} {{.REMOTE_CONFIG_DIR}}/flake"
''
];
};
Expand Down Expand Up @@ -245,7 +246,7 @@
version = "3";
output = "prefixed";

# Don't print excuted commands. Can be overridden by -v
# Don't print executed commands. Can be overridden by -v
silent = true;

# Import the tasks once for each host, setting the HOST
Expand Down
19 changes: 15 additions & 4 deletions module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,21 @@ in
description = "Evaluate locally instead of on the remote when rebuilding";
};

deploy-method = mkOption {
type = types.enum [ "copy" "archive" ];
default = "copy";
description = ''
Method for copying flake to the remote. Using the default (`copy`) will
only deploy the flake itself, while `archive` deploys the flake and
all it's inputs to the remote machine. This is slower when deploying
from a connection with slow upload speed, but allows using inputs
which are not accessible from the remote.
When using `copy` all inputs of the flake will be substituted or
pulled from configured caches.
'';
};

config-dir = mkOption {
type = types.str;
default = "/var/src/lollypops";
Expand Down Expand Up @@ -190,8 +205,4 @@ in

};
};

config = {
environment.systemPackages = with pkgs; [ rsync ];
};
}

0 comments on commit e501dfe

Please sign in to comment.