-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
98 lines (79 loc) · 2.9 KB
/
flake.nix
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
98
{
description = "Deploy VM to GCP with Mina Node running in container";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/master";
arion.url = "github:hercules-ci/arion/master";
};
outputs = { self, nixpkgs, arion }: {
devShells.x86_64-linux.default =
let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
terraform = pkgs.terraform;
gcloud = pkgs.google-cloud-sdk;
in
pkgs.mkShell {
nativeBuildInputs = [ gcloud terraform ];
};
packages.x86_64-linux.default =
let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
terraform = pkgs.terraform;
gcloud = pkgs.google-cloud-sdk;
in
pkgs.writeShellApplication
{
name = "deploy-mina-node";
runtimeInputs = [ terraform ];
text = ''
set -e
TF_VAR_nixos_gce_image_path=$(echo ${self.nixosConfigurations.mina.config.system.build.googleComputeImage}/*.tar.gz)
export TF_VAR_nixos_gce_image_path
TF_VAR_nixos_gce_image=$(basename "$TF_VAR_nixos_gce_image_path")
export TF_VAR_nixos_gce_image
TF_VAR_nixos_gce_image_id=$(echo "$TF_VAR_nixos_gce_image" | sed 's|.raw.tar.gz$||;s|\.|-|g;s|_|-|g')
export TF_VAR_nixos_gce_image_id
TF_VAR_nixos_gce_image_family=$(echo "$TF_VAR_nixos_gce_image_id" | cut -d - -f1-4)
export TF_VAR_nixos_gce_image_family
pushd infrastructure
terraform init
terraform apply
popd
'';
};
packages.x86_64-linux.destroy =
let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
terraform = pkgs.terraform;
gcloud = pkgs.google-cloud-sdk;
in
pkgs.writeShellApplication
{
name = "destroy-mina-node";
runtimeInputs = [ terraform ];
text = ''
set -e
TF_VAR_nixos_gce_image_path=$(echo ${self.nixosConfigurations.mina.config.system.build.googleComputeImage}/*.tar.gz)
export TF_VAR_nixos_gce_image_path
TF_VAR_nixos_gce_image=$(basename "$TF_VAR_nixos_gce_image_path")
export TF_VAR_nixos_gce_image
TF_VAR_nixos_gce_image_id=$(echo "$TF_VAR_nixos_gce_image" | sed 's|.raw.tar.gz$||;s|\.|-|g;s|_|-|g')
export TF_VAR_nixos_gce_image_id
TF_VAR_nixos_gce_image_family=$(echo "$TF_VAR_nixos_gce_image_id" | cut -d - -f1-4)
export TF_VAR_nixos_gce_image_family
pushd infrastructure
terraform init
terraform destroy
popd
'';
};
nixosConfigurations.mina = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules =
[
"${nixpkgs}/nixos/modules/virtualisation/google-compute-image.nix"
arion.nixosModules.arion
./conf/configuration.nix
];
};
};
}