Skip to content

Commit

Permalink
Use more complex activation wrapper and add workaround for deploy-rs#185
Browse files Browse the repository at this point in the history
  • Loading branch information
notgne2 committed Jan 8, 2023
1 parent a5619f5 commit 6245ab9
Showing 1 changed file with 78 additions and 58 deletions.
136 changes: 78 additions & 58 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,64 +27,84 @@
];
};
in
{
deploy-rs = {

deploy-rs = final.rustPlatform.buildRustPackage (darwinOptions // {
pname = "deploy-rs";
version = "0.1.0";

src = ./.;

cargoLock.lockFile = ./Cargo.lock;
}) // { meta.description = "A Simple multi-profile Nix-flake deploy tool"; };

lib = rec {

setActivate = builtins.trace
"deploy-rs#lib.setActivate is deprecated, use activate.noop, activate.nixos or activate.custom instead"
activate.custom;

activate = rec {
custom =
{
__functor = customSelf: base: activate:
final.buildEnv {
name = ("activatable-" + base.name);
paths =
[
base
(final.writeTextFile {
name = base.name + "-activate-path";
text = ''
#!${final.runtimeShell}
set -euo pipefail
if [[ "''${DRY_ACTIVATE:-}" == "1" ]]
then
${customSelf.dryActivate or "echo ${final.writeScript "activate" activate}"}
elif [[ "''${BOOT:-}" == "1" ]]
then
${customSelf.boot or "echo ${final.writeScript "activate" activate}"}
else
${activate}
fi
'';
executable = true;
destination = "/deploy-rs-activate";
})
(final.writeTextFile {
name = base.name + "-activate-rs";
text = ''
#!${final.runtimeShell}
exec ${self.packages.${system}.default}/bin/activate "$@"
'';
executable = true;
destination = "/activate-rs";
})
];
};
};
{
deploy-rs = {

deploy-rs = final.rustPlatform.buildRustPackage (darwinOptions // {
pname = "deploy-rs";
version = "0.1.0";

src = ./.;

cargoLock.lockFile = ./Cargo.lock;
}) // { meta.description = "A Simple multi-profile Nix-flake deploy tool"; };

lib = rec {

setActivate = builtins.trace
"deploy-rs#lib.setActivate is deprecated, use activate.noop, activate.nixos or activate.custom instead"
activate.custom;

activate = rec {
custom =
{
__functor = customSelf: base: activate:
base.overrideAttrs (oldAttrs: {
name = "activatable-${base.name}";
buildCommand = ''
set -euo pipefail
${nixpkgs.lib.concatStringsSep "\n" (map (outputName:
let
activatePath = final.writeTextFile {
name = base.name + "-activate-path";
text = ''
#!${final.runtimeShell}
set -euo pipefail
if [[ "''${DRY_ACTIVATE:-}" == "1" ]]
then
${customSelf.dryActivate or "echo ${final.writeScript "activate" activate}"}
elif [[ "''${BOOT:-}" == "1" ]]
then
${customSelf.boot or "echo ${final.writeScript "activate" activate}"}
else
${activate}
fi
'';
executable = true;
};
activateRs = final.writeTextFile {
name = base.name + "-activate-rs";
text = ''
#!${final.runtimeShell}
exec ${self.packages.${system}.default}/bin/activate "$@"
'';
executable = true;
};
in (''
${final.coreutils}/bin/mkdir "''$${outputName}"
echo "Linking activation components in ${outputName}"
${final.coreutils}/bin/ln -s "${activatePath}" "''$${outputName}/deploy-rs-activate"
${final.coreutils}/bin/ln -s "${activateRs}" "''$${outputName}/activate-rs"
echo "Linking output contents of ${outputName}"
${final.findutils}/bin/find "${base.${outputName}}" -maxdepth 1 | while read -r file; do
${final.coreutils}/bin/ln -s "$file" "''$${outputName}/$(${final.coreutils}/bin/basename "$file")"
done
'' + nixpkgs.lib.optionalString
(outputName == "out") ''
# Workaround for https://github.com/serokell/deploy-rs/issues/185
if [ -x "${base.${outputName}}/prepare-root" ]; then
echo "Copying prepare-root"
rm "$out/prepare-root" || :
cp "${base.${outputName}}/prepare-root" "$out/prepare-root"
fi
'')) (base.outputs or [ "out" ]))}
'';
});
};

nixos = base:
(custom // {
Expand Down

0 comments on commit 6245ab9

Please sign in to comment.