diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-04-25 19:41:41 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-04-25 19:41:41 +0200 |
commit | c79bb68270abd6e5a59e36bf09d64b2eb0d23fb8 (patch) | |
tree | cd86d2c91ebf20c045a55ed541a8cbccf8034d4a | |
parent | 8db8e666707a0e51af9353c76c5863e1a5482ed5 (diff) | |
download | Nix-c79bb68270abd6e5a59e36bf09d64b2eb0d23fb8.tar.gz Nix-c79bb68270abd6e5a59e36bf09d64b2eb0d23fb8.tar.zst Nix-c79bb68270abd6e5a59e36bf09d64b2eb0d23fb8.zip |
Add makefile and remove nixops dependency
-rw-r--r-- | nixops/Makefile | 51 | ||||
-rwxr-xr-x | nixops/scripts/pull_deployment | 9 | ||||
-rwxr-xr-x | nixops/scripts/push_deployment | 3 | ||||
-rwxr-xr-x | nixops/scripts/setup | 27 |
4 files changed, 62 insertions, 28 deletions
diff --git a/nixops/Makefile b/nixops/Makefile new file mode 100644 index 0000000..1d76a9c --- /dev/null +++ b/nixops/Makefile | |||
@@ -0,0 +1,51 @@ | |||
1 | setup: | ||
2 | ./scripts/setup | ||
3 | |||
4 | ssh-eldiron: | ||
5 | ./scripts/nixops_wrap ssh eldiron | ||
6 | |||
7 | info: | ||
8 | ./scripts/nixops_wrap list | ||
9 | ./scripts/nixops_wrap info | ||
10 | |||
11 | debug: | ||
12 | ./scripts/nixops_wrap deploy --build-only --show-trace | ||
13 | |||
14 | dry-run: | ||
15 | ./scripts/nixops_wrap deploy --dry-run | ||
16 | |||
17 | build: | ||
18 | ./scripts/nixops_wrap deploy --build-only | ||
19 | |||
20 | upload: | ||
21 | ./scripts/nixops_wrap deploy --copy-only | ||
22 | |||
23 | deploy: | ||
24 | ./scripts/nixops_wrap deploy | ||
25 | |||
26 | push: | ||
27 | ./scripts/push_deployment | ||
28 | ./scripts/push_environment | ||
29 | |||
30 | pull: | ||
31 | ./scripts/pull_environment | ||
32 | |||
33 | pull-deployment: | ||
34 | ./scripts/pull_deployment | ||
35 | |||
36 | profile = $(shell ./scripts/nixops_wrap info | grep "^Nix profile: " | sed -e "s/^Nix profile: //") | ||
37 | GEN ?= "+3" | ||
38 | |||
39 | list-generations: | ||
40 | nix-env -p $(profile) --list-generations | ||
41 | ./scripts/nixops_wrap ssh eldiron -- nix-env -p /nix/var/nix/profiles/system --list-generations | ||
42 | |||
43 | delete-generations: | ||
44 | nix-env -p $(profile) --delete-generations $(GEN) | ||
45 | ./scripts/nixops_wrap ssh eldiron -- nix-env -p /nix/var/nix/profiles/system --delete-generations $(GEN) | ||
46 | |||
47 | cleanup: delete-generations | ||
48 | nix-store --gc | ||
49 | ./scripts/nixops_wrap ssh eldiron -- nix-store --gc | ||
50 | |||
51 | .PHONY: setup ssh-eldiron info debug dry-run build upload deploy push pull pull-deployment list-generations delete-generations cleanup | ||
diff --git a/nixops/scripts/pull_deployment b/nixops/scripts/pull_deployment index 8ee9b75..d238434 100755 --- a/nixops/scripts/pull_deployment +++ b/nixops/scripts/pull_deployment | |||
@@ -8,16 +8,17 @@ if [ -z "$NIXOPS_CONFIG_PASS_SUBTREE_PATH" ]; then | |||
8 | fi | 8 | fi |
9 | 9 | ||
10 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | 10 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" |
11 | nixops="$(nix-build --no-out-link -A nixops "$(dirname $(dirname $DIR))")/bin/nixops" | ||
11 | export NIXOPS_STATE="$(dirname $DIR)/state/eldiron.nixops" | 12 | export NIXOPS_STATE="$(dirname $DIR)/state/eldiron.nixops" |
12 | 13 | ||
13 | if nixops info -d $DeploymentUuid 2>/dev/null >/dev/null; then | 14 | if $nixops info -d $DeploymentUuid 2>/dev/null >/dev/null; then |
14 | cat <<EOF | 15 | cat <<EOF |
15 | This will remove your current deployment file and recreate it! | 16 | This will remove your current deployment file and recreate it! |
16 | Continue? [y/N] | 17 | Continue? [y/N] |
17 | EOF | 18 | EOF |
18 | read y | 19 | read y |
19 | if [ "$y" = "y" -o "$y" = "Y" ]; then | 20 | if [ "$y" = "y" -o "$y" = "Y" ]; then |
20 | nixops delete --force -d $DeploymentUuid | 21 | $nixops delete --force -d $DeploymentUuid |
21 | else | 22 | else |
22 | echo "Aborting" | 23 | echo "Aborting" |
23 | exit 1 | 24 | exit 1 |
@@ -26,6 +27,6 @@ fi | |||
26 | 27 | ||
27 | deployment=$(pass show $NIXOPS_CONFIG_PASS_SUBTREE_PATH/Nixops/Deployment) | 28 | deployment=$(pass show $NIXOPS_CONFIG_PASS_SUBTREE_PATH/Nixops/Deployment) |
28 | 29 | ||
29 | echo "$deployment" | nixops import | 30 | echo "$deployment" | $nixops import |
30 | 31 | ||
31 | nixops modify -d "$DeploymentUuid" "$(dirname $DIR)/eldiron.nix" | 32 | $nixops modify -d "$DeploymentUuid" "$(dirname $DIR)/eldiron.nix" |
diff --git a/nixops/scripts/push_deployment b/nixops/scripts/push_deployment index e43b6be..73084e4 100755 --- a/nixops/scripts/push_deployment +++ b/nixops/scripts/push_deployment | |||
@@ -8,7 +8,8 @@ if [ -z "$NIXOPS_CONFIG_PASS_SUBTREE_PATH" ]; then | |||
8 | fi | 8 | fi |
9 | 9 | ||
10 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | 10 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" |
11 | nixops="$(nix-build --no-out-link -A nixops "$(dirname $(dirname $DIR))")/bin/nixops" | ||
11 | export NIXOPS_STATE="$(dirname $DIR)/state/eldiron.nixops" | 12 | export NIXOPS_STATE="$(dirname $DIR)/state/eldiron.nixops" |
12 | export NIXOPS_DEPLOYMENT="$DeploymentUuid" | 13 | export NIXOPS_DEPLOYMENT="$DeploymentUuid" |
13 | 14 | ||
14 | nixops export | pass insert -m $NIXOPS_CONFIG_PASS_SUBTREE_PATH/Nixops/Deployment | 15 | $nixops export | pass insert -m $NIXOPS_CONFIG_PASS_SUBTREE_PATH/Nixops/Deployment |
diff --git a/nixops/scripts/setup b/nixops/scripts/setup index 4a76d35..cfa8d64 100755 --- a/nixops/scripts/setup +++ b/nixops/scripts/setup | |||
@@ -134,31 +134,12 @@ if nix show-config --json | jq -e '.sandbox.value == "true"' >/dev/null; then | |||
134 | exit 1 | 134 | exit 1 |
135 | fi | 135 | fi |
136 | 136 | ||
137 | if ! which nixops 2>/dev/null >/dev/null; then | ||
138 | cat <<-EOF | ||
139 | nixops is needed: | ||
140 | > nix-env -i nixops | ||
141 | If it fails, please check that $HOME/.nix-profile/bin is in your PATH. | ||
142 | Continue? [y/N] | ||
143 | EOF | ||
144 | read y | ||
145 | if [ "$y" = "y" -o "$y" = "Y" ]; then | ||
146 | nix-env -i nixops | ||
147 | if ! which nixops 2>/dev/null >/dev/null; then | ||
148 | echo "Installation failed, please check that $HOME/.nix-profile/bin is in your path." | ||
149 | exit 1 | ||
150 | fi | ||
151 | else | ||
152 | echo "Aborting" | ||
153 | exit 1 | ||
154 | fi | ||
155 | fi | ||
156 | |||
157 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | 137 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" |
138 | nixops="$(nix-build --no-out-link -A nixops "$(dirname $(dirname $DIR))")/bin/nixops" | ||
158 | export NIXOPS_STATE="$(dirname $DIR)/state/eldiron.nixops" | 139 | export NIXOPS_STATE="$(dirname $DIR)/state/eldiron.nixops" |
159 | export NIXOPS_DEPLOYMENT="$DeploymentUuid" | 140 | export NIXOPS_DEPLOYMENT="$DeploymentUuid" |
160 | 141 | ||
161 | if ! nixops info 2>/dev/null >/dev/null; then | 142 | if ! $nixops info 2>/dev/null >/dev/null; then |
162 | cat <<-EOF | 143 | cat <<-EOF |
163 | Importing deployment file into nixops: | 144 | Importing deployment file into nixops: |
164 | Continue? [y/N] | 145 | Continue? [y/N] |
@@ -166,9 +147,9 @@ if ! nixops info 2>/dev/null >/dev/null; then | |||
166 | read y | 147 | read y |
167 | if [ "$y" = "y" -o "$y" = "Y" ]; then | 148 | if [ "$y" = "y" -o "$y" = "Y" ]; then |
168 | deployment=$(pass show $NIXOPS_CONFIG_PASS_SUBTREE_PATH/Nixops/Deployment) | 149 | deployment=$(pass show $NIXOPS_CONFIG_PASS_SUBTREE_PATH/Nixops/Deployment) |
169 | echo "$deployment" | nixops import | 150 | echo "$deployment" | $nixops import |
170 | 151 | ||
171 | nixops modify "$(dirname $DIR)/eldiron.nix" | 152 | $nixops modify "$(dirname $DIR)/eldiron.nix" |
172 | else | 153 | else |
173 | echo "Aborting" | 154 | echo "Aborting" |
174 | exit 1 | 155 | exit 1 |