From ba35a6df121a892f466848ef5e83f76fd3930adc Mon Sep 17 00:00:00 2001 From: notgne2 Date: Sun, 8 Jan 2023 14:13:51 -0700 Subject: [PATCH] Use more complex activation wrapper and add workaround for deploy-rs#185 --- flake.nix | 54 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/flake.nix b/flake.nix index 9b8e6eb4..503d18c4 100644 --- a/flake.nix +++ b/flake.nix @@ -48,13 +48,14 @@ activate = rec { custom = { - __functor = customSelf: base: activate: - final.buildEnv { - name = ("activatable-" + base.name); - paths = - [ - base - (final.writeTextFile { + __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} @@ -71,20 +72,39 @@ fi ''; executable = true; - destination = "/deploy-rs-activate"; - }) - (final.writeTextFile { - name = base.name + "-activate-rs"; - text = '' + }; + + activateRs = final.writeTextFile { + name = base.name + "-activate-rs"; + text = '' #!${final.runtimeShell} 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: (custom // {