aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2019-04-25 19:41:41 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2019-04-25 19:41:41 +0200
commitc79bb68270abd6e5a59e36bf09d64b2eb0d23fb8 (patch)
treecd86d2c91ebf20c045a55ed541a8cbccf8034d4a
parent8db8e666707a0e51af9353c76c5863e1a5482ed5 (diff)
downloadNix-c79bb68270abd6e5a59e36bf09d64b2eb0d23fb8.tar.gz
Nix-c79bb68270abd6e5a59e36bf09d64b2eb0d23fb8.tar.zst
Nix-c79bb68270abd6e5a59e36bf09d64b2eb0d23fb8.zip
Add makefile and remove nixops dependency
-rw-r--r--nixops/Makefile51
-rwxr-xr-xnixops/scripts/pull_deployment9
-rwxr-xr-xnixops/scripts/push_deployment3
-rwxr-xr-xnixops/scripts/setup27
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 @@
1setup:
2 ./scripts/setup
3
4ssh-eldiron:
5 ./scripts/nixops_wrap ssh eldiron
6
7info:
8 ./scripts/nixops_wrap list
9 ./scripts/nixops_wrap info
10
11debug:
12 ./scripts/nixops_wrap deploy --build-only --show-trace
13
14dry-run:
15 ./scripts/nixops_wrap deploy --dry-run
16
17build:
18 ./scripts/nixops_wrap deploy --build-only
19
20upload:
21 ./scripts/nixops_wrap deploy --copy-only
22
23deploy:
24 ./scripts/nixops_wrap deploy
25
26push:
27 ./scripts/push_deployment
28 ./scripts/push_environment
29
30pull:
31 ./scripts/pull_environment
32
33pull-deployment:
34 ./scripts/pull_deployment
35
36profile = $(shell ./scripts/nixops_wrap info | grep "^Nix profile: " | sed -e "s/^Nix profile: //")
37GEN ?= "+3"
38
39list-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
43delete-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
47cleanup: 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
8fi 8fi
9 9
10DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 10DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
11nixops="$(nix-build --no-out-link -A nixops "$(dirname $(dirname $DIR))")/bin/nixops"
11export NIXOPS_STATE="$(dirname $DIR)/state/eldiron.nixops" 12export NIXOPS_STATE="$(dirname $DIR)/state/eldiron.nixops"
12 13
13if nixops info -d $DeploymentUuid 2>/dev/null >/dev/null; then 14if $nixops info -d $DeploymentUuid 2>/dev/null >/dev/null; then
14 cat <<EOF 15 cat <<EOF
15This will remove your current deployment file and recreate it! 16This will remove your current deployment file and recreate it!
16Continue? [y/N] 17Continue? [y/N]
17EOF 18EOF
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
27deployment=$(pass show $NIXOPS_CONFIG_PASS_SUBTREE_PATH/Nixops/Deployment) 28deployment=$(pass show $NIXOPS_CONFIG_PASS_SUBTREE_PATH/Nixops/Deployment)
28 29
29echo "$deployment" | nixops import 30echo "$deployment" | $nixops import
30 31
31nixops 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
8fi 8fi
9 9
10DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 10DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
11nixops="$(nix-build --no-out-link -A nixops "$(dirname $(dirname $DIR))")/bin/nixops"
11export NIXOPS_STATE="$(dirname $DIR)/state/eldiron.nixops" 12export NIXOPS_STATE="$(dirname $DIR)/state/eldiron.nixops"
12export NIXOPS_DEPLOYMENT="$DeploymentUuid" 13export NIXOPS_DEPLOYMENT="$DeploymentUuid"
13 14
14nixops 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
135fi 135fi
136 136
137if ! 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
155fi
156
157DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 137DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
138nixops="$(nix-build --no-out-link -A nixops "$(dirname $(dirname $DIR))")/bin/nixops"
158export NIXOPS_STATE="$(dirname $DIR)/state/eldiron.nixops" 139export NIXOPS_STATE="$(dirname $DIR)/state/eldiron.nixops"
159export NIXOPS_DEPLOYMENT="$DeploymentUuid" 140export NIXOPS_DEPLOYMENT="$DeploymentUuid"
160 141
161if ! nixops info 2>/dev/null >/dev/null; then 142if ! $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