Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use more complex activation wrapper and add workaround for deploy-rs#185 #188

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 31 additions & 21 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,13 @@
custom =
{
__functor = customSelf: base: activate:
final.buildEnv {
name = ("activatable-" + base.name);
paths =
[
base
(final.writeTextFile {
name = base.name + "-activate-path";
text = ''
#!${final.runtimeShell}
base.overrideAttrs (oldAttrs: {
name = "activatable-${base.name}";
buildCommand = ''
set -euo pipefail
${nixpkgs.lib.concatStringsSep "\n" (map (outputName:
let
activatePath = final.writeShellScript (base.name + "-activate-path") ''
set -euo pipefail

if [[ "''${DRY_ACTIVATE:-}" == "1" ]]
Expand All @@ -70,20 +68,32 @@
${activate}
fi
'';
executable = true;
destination = "/deploy-rs-activate";
})
(final.writeTextFile {
name = base.name + "-activate-rs";
text = ''
#!${final.runtimeShell}

activateRs = final.writeShellScript (base.name + "-activate-rs") ''
exec ${self.packages.${system}.default}/bin/activate "$@"
'';
executable = true;
destination = "/activate-rs";
})
];
};
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:
Expand Down