-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault.nix
More file actions
91 lines (78 loc) · 1.88 KB
/
Copy pathdefault.nix
File metadata and controls
91 lines (78 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
{ pkgs ? import ./nix { }
}:
let
inherit (pkgs)
lib
callPackage
flyctl
mkShell
skopeo
sources # provided by overlay
writeShellScript
writeShellScriptBin
;
fenix = import sources.fenix { inherit pkgs; };
rustToolchain = with fenix;
combine [
stable.rustc
stable.cargo
];
app =
let
naersk = callPackage sources.naersk {
cargo = rustToolchain;
rustc = rustToolchain;
};
in
naersk.buildPackage {
src = lib.cleanSource ./app;
};
inherit (callPackage ./fly.nix {
rustLog = "info";
})
flyConfig
flyToml
;
dockerImage = callPackage ./docker-image.nix { inherit flyConfig app; };
deployScript = writeShellScript "deploy" ''
set -euo pipefail
token=$(${flyctl}/bin/flyctl auth token 2>/dev/null || true)
if [ -z "$token" ]; then
echo 'Error: Missing fly.io authentication token'
echo 'Consider running `flyctl auth login` or setting one of $FLY_ACCESS_TOKEN or $FLY_API_TOKEN'
exit 1
fi
# docker image upload target
image=registry.fly.io/${flyConfig.app}:${dockerImage.imageConfig.tag}
# upload the docker image
${skopeo}/bin/skopeo copy \
--insecure-policy \
--dest-username x \
--dest-password "$token" \
docker-archive:<(${dockerImage.archiveWriter}) \
docker://$image
# trigger deployment of the uploaded docker image
${flyctl}/bin/flyctl deploy \
--config ${flyToml} \
--image $image
'';
devShell = mkShell {
name = "website";
buildInputs = [
flyctl
rustToolchain
fenix.rust-analyzer
# an app specific flyctl command that has this app's fly.toml hardcoded
# (writeShellScriptBin "flyctl" "exec ${flyctl}/bin/flyctl --config ${flyToml} $@")
];
};
in
{
inherit
devShell
app
dockerImage
deployScript
flyToml
;
}