Repository navigation
Expand file tree
/
Copy pathdeploy.nix
More file actions
97 lines (90 loc) · 2.62 KB
/
Copy pathdeploy.nix
File metadata and controls
97 lines (90 loc) · 2.62 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
92
93
94
95
96
97
{ deploy-rs, self }:
let
system = "x86_64-linux";
inherit (deploy-rs.lib.${system}) activate;
profileBase = "/nix/var/nix/profiles/per-service";
apiPackage = self.packages.${system}.raindex-api;
serviceDefinitions = import ./services.nix;
enabledServices = builtins.attrNames (
builtins.removeAttrs serviceDefinitions (
builtins.filter (name: !serviceDefinitions.${name}.enabled) (builtins.attrNames serviceDefinitions)
)
);
mkServiceProfile =
name:
activate.custom apiPackage (
builtins.concatStringsSep " && " [
"systemctl stop ${name} || true"
"systemctl restart ${name}"
]
);
mkProfile = name: {
path = mkServiceProfile name;
profilePath = "${profileBase}/${name}";
};
serviceProfiles = builtins.listToAttrs (
map (name: {
inherit name;
value = mkProfile name;
}) enabledServices
);
in
{
config.nodes.raindex-api = {
hostname = builtins.getEnv "DEPLOY_HOST";
sshUser = "root";
user = "root";
profilesOrder = [ "system" ] ++ enabledServices;
profiles = {
system.path = activate.nixos self.nixosConfigurations.raindex-api;
}
// serviceProfiles;
};
wrappers =
{
pkgs,
infraPkgs,
localSystem,
}:
let
deployInputs = infraPkgs.buildInputs ++ [ deploy-rs.packages.${localSystem}.deploy-rs ];
preamble = ''
${infraPkgs.resolveIp}
export DEPLOY_HOST="$host_ip"
export NIX_SSHOPTS="-o IgnoreUnknown=UseKeychain -i $identity"
ssh_flag="--ssh-opts=-o IgnoreUnknown=UseKeychain -i $identity"
'';
deployFlags = if localSystem == "x86_64-linux" then "" else "--skip-checks --remote-build";
in
{
deployNixos = pkgs.writeShellApplication {
name = "deploy-nixos";
runtimeInputs = deployInputs;
text = ''
${preamble}
deploy ${deployFlags} ''${ssh_flag:+"$ssh_flag"} .#raindex-api.system \
-- --impure "$@"
'';
};
deployService = pkgs.writeShellApplication {
name = "deploy-service";
runtimeInputs = deployInputs;
text = ''
${preamble}
profile="''${1:?usage: deploy-service <profile>}"
shift
deploy ${deployFlags} ''${ssh_flag:+"$ssh_flag"} ".#raindex-api.$profile" \
-- --impure "$@"
'';
};
deployAll = pkgs.writeShellApplication {
name = "deploy-all";
runtimeInputs = deployInputs;
text = ''
${preamble}
deploy ${deployFlags} ''${ssh_flag:+"$ssh_flag"} .#raindex-api \
-- --impure "$@"
'';
};
};
}