From 54a1b1dcf9294debad266fe7983b28889a4116be Mon Sep 17 00:00:00 2001 From: notgne2 Date: Sun, 8 Jan 2023 14:13:51 -0700 Subject: [PATCH 1/2] Use more complex activation wrapper and add workaround for deploy-rs#185 --- flake.nix | 86 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 33 deletions(-) diff --git a/flake.nix b/flake.nix index 9b8e6eb4..0a311e1b 100644 --- a/flake.nix +++ b/flake.nix @@ -49,41 +49,61 @@ 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 { + 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; - destination = "/activate-rs"; - }) - ]; - }; + #!${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: From 0c0980368b674f317d1278168f2b464186388c58 Mon Sep 17 00:00:00 2001 From: notgne2 Date: Fri, 13 Jan 2023 02:51:48 -0700 Subject: [PATCH 2/2] fixup! Use more complex activation wrapper and add workaround for deploy-rs#185 --- flake.nix | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/flake.nix b/flake.nix index 0a311e1b..61480d00 100644 --- a/flake.nix +++ b/flake.nix @@ -55,33 +55,23 @@ 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; - }; + activatePath = final.writeShellScript (base.name + "-activate-path") '' + 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 + ''; + + activateRs = final.writeShellScript (base.name + "-activate-rs") '' + exec ${self.packages.${system}.default}/bin/activate "$@" + ''; in ('' ${final.coreutils}/bin/mkdir "''$${outputName}"