Skip to content

Commit 6245ab9

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

File tree

1 file changed

+78
-58
lines changed

1 file changed

+78
-58
lines changed

flake.nix

+78-58
Original file line numberDiff line numberDiff line change
@@ -27,64 +27,84 @@
2727
];
2828
};
2929
in
30-
{
31-
deploy-rs = {
32-
33-
deploy-rs = final.rustPlatform.buildRustPackage (darwinOptions // {
34-
pname = "deploy-rs";
35-
version = "0.1.0";
36-
37-
src = ./.;
38-
39-
cargoLock.lockFile = ./Cargo.lock;
40-
}) // { meta.description = "A Simple multi-profile Nix-flake deploy tool"; };
41-
42-
lib = rec {
43-
44-
setActivate = builtins.trace
45-
"deploy-rs#lib.setActivate is deprecated, use activate.noop, activate.nixos or activate.custom instead"
46-
activate.custom;
47-
48-
activate = rec {
49-
custom =
50-
{
51-
__functor = customSelf: base: activate:
52-
final.buildEnv {
53-
name = ("activatable-" + base.name);
54-
paths =
55-
[
56-
base
57-
(final.writeTextFile {
58-
name = base.name + "-activate-path";
59-
text = ''
60-
#!${final.runtimeShell}
61-
set -euo pipefail
62-
63-
if [[ "''${DRY_ACTIVATE:-}" == "1" ]]
64-
then
65-
${customSelf.dryActivate or "echo ${final.writeScript "activate" activate}"}
66-
elif [[ "''${BOOT:-}" == "1" ]]
67-
then
68-
${customSelf.boot or "echo ${final.writeScript "activate" activate}"}
69-
else
70-
${activate}
71-
fi
72-
'';
73-
executable = true;
74-
destination = "/deploy-rs-activate";
75-
})
76-
(final.writeTextFile {
77-
name = base.name + "-activate-rs";
78-
text = ''
79-
#!${final.runtimeShell}
80-
exec ${self.packages.${system}.default}/bin/activate "$@"
81-
'';
82-
executable = true;
83-
destination = "/activate-rs";
84-
})
85-
];
86-
};
87-
};
30+
{
31+
deploy-rs = {
32+
33+
deploy-rs = final.rustPlatform.buildRustPackage (darwinOptions // {
34+
pname = "deploy-rs";
35+
version = "0.1.0";
36+
37+
src = ./.;
38+
39+
cargoLock.lockFile = ./Cargo.lock;
40+
}) // { meta.description = "A Simple multi-profile Nix-flake deploy tool"; };
41+
42+
lib = rec {
43+
44+
setActivate = builtins.trace
45+
"deploy-rs#lib.setActivate is deprecated, use activate.noop, activate.nixos or activate.custom instead"
46+
activate.custom;
47+
48+
activate = rec {
49+
custom =
50+
{
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 {
59+
name = base.name + "-activate-path";
60+
text = ''
61+
#!${final.runtimeShell}
62+
set -euo pipefail
63+
64+
if [[ "''${DRY_ACTIVATE:-}" == "1" ]]
65+
then
66+
${customSelf.dryActivate or "echo ${final.writeScript "activate" activate}"}
67+
elif [[ "''${BOOT:-}" == "1" ]]
68+
then
69+
${customSelf.boot or "echo ${final.writeScript "activate" activate}"}
70+
else
71+
${activate}
72+
fi
73+
'';
74+
executable = true;
75+
};
76+
77+
activateRs = final.writeTextFile {
78+
name = base.name + "-activate-rs";
79+
text = ''
80+
#!${final.runtimeShell}
81+
exec ${self.packages.${system}.default}/bin/activate "$@"
82+
'';
83+
executable = true;
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)