Skip to content

Commit ba35a6d

Browse files
committed
Use more complex activation wrapper and add workaround for deploy-rs#185
1 parent a5619f5 commit ba35a6d

File tree

1 file changed

+37
-17
lines changed

1 file changed

+37
-17
lines changed

flake.nix

+37-17
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@
4848
activate = rec {
4949
custom =
5050
{
51-
__functor = customSelf: base: activate:
52-
final.buildEnv {
53-
name = ("activatable-" + base.name);
54-
paths =
55-
[
56-
base
57-
(final.writeTextFile {
51+
__functor = customSelf: base: activate:
52+
base.overrideAttrs (oldAttrs: {
53+
name = "activatable-${base.name}";
54+
buildCommand = ''
55+
set -euo pipefail
56+
${nixpkgs.lib.concatStringsSep "\n" (map (outputName:
57+
let
58+
activatePath = final.writeTextFile {
5859
name = base.name + "-activate-path";
5960
text = ''
6061
#!${final.runtimeShell}
@@ -71,20 +72,39 @@
7172
fi
7273
'';
7374
executable = true;
74-
destination = "/deploy-rs-activate";
75-
})
76-
(final.writeTextFile {
77-
name = base.name + "-activate-rs";
78-
text = ''
75+
};
76+
77+
activateRs = final.writeTextFile {
78+
name = base.name + "-activate-rs";
79+
text = ''
7980
#!${final.runtimeShell}
8081
exec ${self.packages.${system}.default}/bin/activate "$@"
8182
'';
8283
executable = true;
83-
destination = "/activate-rs";
84-
})
85-
];
86-
};
87-
};
84+
};
85+
in (''
86+
${final.coreutils}/bin/mkdir "''$${outputName}"
87+
88+
echo "Linking activation components in ${outputName}"
89+
${final.coreutils}/bin/ln -s "${activatePath}" "''$${outputName}/deploy-rs-activate"
90+
${final.coreutils}/bin/ln -s "${activateRs}" "''$${outputName}/activate-rs"
91+
92+
echo "Linking output contents of ${outputName}"
93+
${final.findutils}/bin/find "${base.${outputName}}" -maxdepth 1 | while read -r file; do
94+
${final.coreutils}/bin/ln -s "$file" "''$${outputName}/$(${final.coreutils}/bin/basename "$file")"
95+
done
96+
'' + nixpkgs.lib.optionalString
97+
(outputName == "out") ''
98+
# Workaround for https://github.com/serokell/deploy-rs/issues/185
99+
if [ -x "${base.${outputName}}/prepare-root" ]; then
100+
echo "Copying prepare-root"
101+
rm "$out/prepare-root" || :
102+
cp "${base.${outputName}}/prepare-root" "$out/prepare-root"
103+
fi
104+
'')) (base.outputs or [ "out" ]))}
105+
'';
106+
});
107+
};
88108

89109
nixos = base:
90110
(custom // {

0 commit comments

Comments
 (0)