aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitmodules3
-rw-r--r--Makefile4
-rw-r--r--nixops/Makefile37
-rwxr-xr-xnixops/scripts/setup39
-rwxr-xr-xnixops/scripts/with_env9
m---------nixops/secrets0
6 files changed, 17 insertions, 75 deletions
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..c2d9b18
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
1[submodule "nixops/secrets"]
2 path = nixops/secrets
3 url = gitolite@git.immae.eu:perso/Immae/Config/Nix/Nixops/Secrets
diff --git a/Makefile b/Makefile
index d5b8e5a..6ba059c 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,8 @@
1subrecipes = setup nix-info 1subrecipes = setup nix-info edit_env
2subrecipes += nixops ssh-eldiron ssh-backup-2 ssh-monitoring-1 2subrecipes += nixops ssh-eldiron ssh-backup-2 ssh-monitoring-1
3subrecipes += info debug dry-run build upload deploy deploy-reboot reboot 3subrecipes += info debug dry-run build upload deploy deploy-reboot reboot
4subrecipes += list-generations delete-generations cleanup 4subrecipes += list-generations delete-generations cleanup
5subrecipes += pull pull_environment pull_deployment deployment_is_set push push_deployment push_environment 5subrecipes += pull_deployment deployment_is_set push_deployment
6${subrecipes}: 6${subrecipes}:
7 @$(MAKE) --no-print-directory -C nixops/ $@ 7 @$(MAKE) --no-print-directory -C nixops/ $@
8.PHONY: ${subrecipes} 8.PHONY: ${subrecipes}
diff --git a/nixops/Makefile b/nixops/Makefile
index c521682..a7b24cd 100644
--- a/nixops/Makefile
+++ b/nixops/Makefile
@@ -1,8 +1,5 @@
1export 1export
2ifndef NIXOPS_CONFIG_PASS_SUBTREE_PATH 2PASSWORD_STORE_DIR = $(shell pwd)/secrets
3 $(error Please set NIXOPS_CONFIG_PASS_SUBTREE_PATH to the password-store subtree path)
4endif
5
6NIXOPS_STATE ?= ./state/eldiron.nixops 3NIXOPS_STATE ?= ./state/eldiron.nixops
7NIXOPS_DEPLOYMENT = cef694f3-081d-11e9-b31f-0242ec186adf 4NIXOPS_DEPLOYMENT = cef694f3-081d-11e9-b31f-0242ec186adf
8nixpkgs ?= $(shell cat ../nix/sources.json | jq -r '."nixpkgs-nixops".url') 5nixpkgs ?= $(shell cat ../nix/sources.json | jq -r '."nixpkgs-nixops".url')
@@ -34,6 +31,9 @@ ifdef TARGET
34endif 31endif
35SSH_ARGS ?= 32SSH_ARGS ?=
36 33
34edit_env:
35 pass edit Nixops/files/environment.nix || true
36
37nixops: 37nixops:
38 $(NIXOPS_PRIV) $(NIXOPS_ARGS) 38 $(NIXOPS_PRIV) $(NIXOPS_ARGS)
39 39
@@ -101,17 +101,6 @@ cleanup: delete-generations
101.PHONY: cleanup 101.PHONY: cleanup
102 102
103###### Pull environment and deployment from remote 103###### Pull environment and deployment from remote
104# Don't include pull_deployment by default as this should happen only rarely
105pull: pull_environment;
106.PHONY: pull
107
108pull_environment:
109ifndef NIXOPS_CONFIG_PASS_SUBTREE_REMOTE
110 $(error "Please set NIXOPS_CONFIG_PASS_SUBTREE_REMOTE to the password-store subtree remote name")
111endif
112 pass git subtree pull --prefix=$(NIXOPS_CONFIG_PASS_SUBTREE_PATH) $(NIXOPS_CONFIG_PASS_SUBTREE_REMOTE) master
113.PHONY: pull_environment
114
115pull_deployment: 104pull_deployment:
116 @if $(NIXOPS) info -d $(NIXOPS_DEPLOYMENT) 2>/dev/null >/dev/null ; then \ 105 @if $(NIXOPS) info -d $(NIXOPS_DEPLOYMENT) 2>/dev/null >/dev/null ; then \
117 echo "This will remove your current deployment file and recreate it!. Continue? [y/N]" && \ 106 echo "This will remove your current deployment file and recreate it!. Continue? [y/N]" && \
@@ -119,7 +108,7 @@ pull_deployment:
119 [ "$$y" = "y" -o "$$y" = "Y" ] && \ 108 [ "$$y" = "y" -o "$$y" = "Y" ] && \
120 $(NIXOPS) delete --force -d $(NIXOPS_DEPLOYMENT); \ 109 $(NIXOPS) delete --force -d $(NIXOPS_DEPLOYMENT); \
121 fi 110 fi
122 pass show $(NIXOPS_CONFIG_PASS_SUBTREE_PATH)/Nixops/Deployment | $(NIXOPS) import 111 pass show Nixops/Deployment | $(NIXOPS) import
123 $(NIXOPS) modify -d $(NIXOPS_DEPLOYMENT) "$$(pwd)/default.nix" 112 $(NIXOPS) modify -d $(NIXOPS_DEPLOYMENT) "$$(pwd)/default.nix"
124.PHONY: pull_deployment 113.PHONY: pull_deployment
125 114
@@ -127,17 +116,7 @@ deployment_is_set:
127 $(NIXOPS) info -d $(NIXOPS_DEPLOYMENT) 2>/dev/null >/dev/null 116 $(NIXOPS) info -d $(NIXOPS_DEPLOYMENT) 2>/dev/null >/dev/null
128.PHONY: deployment_is_set 117.PHONY: deployment_is_set
129 118
130###### Push environment and deployment information to password store 119###### Push deployment information to password store
131push: push_deployment push_environment;
132.PHONY: push
133
134push_deployment: 120push_deployment:
135 $(NIXOPS) export | pass insert -m $(NIXOPS_CONFIG_PASS_SUBTREE_PATH)/Nixops/Deployment 121 $(NIXOPS) export | pass insert -m Nixops/Deployment
136.PHONY: push_deployment 122.PHONY: push
137
138push_environment:
139ifndef NIXOPS_CONFIG_PASS_SUBTREE_REMOTE
140 $(error "Please set NIXOPS_CONFIG_PASS_SUBTREE_REMOTE to the password-store subtree remote name")
141endif
142 pass git subtree push --prefix=$(NIXOPS_CONFIG_PASS_SUBTREE_PATH) $(NIXOPS_CONFIG_PASS_SUBTREE_REMOTE) master
143.PHONY: push_environment
diff --git a/nixops/scripts/setup b/nixops/scripts/setup
index 3b364ac..22f43ce 100755
--- a/nixops/scripts/setup
+++ b/nixops/scripts/setup
@@ -2,7 +2,6 @@
2 2
3set -euo pipefail 3set -euo pipefail
4 4
5RemoteRepo="gitolite@git.immae.eu:perso/Immae/Prive/Password_store/Sites"
6MAKEFILE_DIR="$( cd "$( dirname $( dirname "${BASH_SOURCE[0]}" ))" >/dev/null 2>&1 && pwd )" 5MAKEFILE_DIR="$( cd "$( dirname $( dirname "${BASH_SOURCE[0]}" ))" >/dev/null 2>&1 && pwd )"
7 6
8if ! which nix 2>/dev/null >/dev/null; then 7if ! which nix 2>/dev/null >/dev/null; then
@@ -21,43 +20,9 @@ if [ "${NIX_STORE:-/nix/store}" != "/nix/store" ]; then
21 exit 1 20 exit 1
22fi 21fi
23 22
24if [ -z "$NIXOPS_CONFIG_PASS_SUBTREE_REMOTE" \ 23gpg_keys=$(pass ls Nixops/GPGKeys | sed -e "1d" | cut -d" " -f2)
25 -o -z "$NIXOPS_CONFIG_PASS_SUBTREE_PATH" ]; then
26 cat <<-EOF
27 Two environment variables are needed to setup the password store:
28 NIXOPS_CONFIG_PASS_SUBTREE_PATH : path where the subtree will be imported
29 NIXOPS_CONFIG_PASS_SUBTREE_REMOTE : remote name to give to the repository
30 EOF
31 exit 1
32fi
33
34if ! pass $NIXOPS_CONFIG_PASS_SUBTREE_PATH > /dev/null 2>/dev/null; then
35 cat <<-EOF
36 /!\ This will modify your password store to add and import a subtree
37 with the specific passwords files. Choose a path that doesn’t exist
38 yet in your password store.
39 > pass git remote add $NIXOPS_CONFIG_PASS_SUBTREE_REMOTE $RemoteRepo
40 > pass git subtree add --prefix=$NIXOPS_CONFIG_PASS_SUBTREE_PATH $NIXOPS_CONFIG_PASS_SUBTREE_REMOTE master
41 Later, you can use pull_environment and push_environment scripts to
42 update the passwords when needed
43 Continue? [y/N]
44 EOF
45 read y
46 if [ "$y" = "y" -o "$y" = "Y" ]; then
47 pass git remote add $NIXOPS_CONFIG_PASS_SUBTREE_REMOTE $RemoteRepo
48 pass git subtree add --prefix=$NIXOPS_CONFIG_PASS_SUBTREE_PATH $NIXOPS_CONFIG_PASS_SUBTREE_REMOTE master
49 else
50 echo "Aborting"
51 exit 1
52 fi
53fi
54
55# Repull it before adding keys, just in case
56make -C $MAKEFILE_DIR pull_environment
57
58gpg_keys=$(pass ls $NIXOPS_CONFIG_PASS_SUBTREE_PATH/Nixops/GPGKeys | sed -e "1d" | cut -d" " -f2)
59for key in $gpg_keys; do 24for key in $gpg_keys; do
60 content=$(pass show $NIXOPS_CONFIG_PASS_SUBTREE_PATH/Nixops/GPGKeys/$key) 25 content=$(pass show Nixops/GPGKeys/$key)
61 fpr=$(echo "$content" | gpg --import-options show-only --import --with-colons | grep -e "^pub" | cut -d':' -f5) 26 fpr=$(echo "$content" | gpg --import-options show-only --import --with-colons | grep -e "^pub" | cut -d':' -f5)
62 gpg --list-key "$fpr" >/dev/null 2>/dev/null && imported=yes || imported=no 27 gpg --list-key "$fpr" >/dev/null 2>/dev/null && imported=yes || imported=no
63 # /usr/share/doc/gnupg/DETAILS field 2 28 # /usr/share/doc/gnupg/DETAILS field 2
diff --git a/nixops/scripts/with_env b/nixops/scripts/with_env
index dd0fecb..26e74b5 100755
--- a/nixops/scripts/with_env
+++ b/nixops/scripts/with_env
@@ -5,11 +5,6 @@ if [ -z "$NIXOPS" ]; then
5 exit 1; 5 exit 1;
6fi 6fi
7 7
8if [ -z "$NIXOPS_CONFIG_PASS_SUBTREE_PATH" ]; then
9 echo "Please set NIXOPS_CONFIG_PASS_SUBTREE_PATH to the password-store subtree path"
10 exit 1;
11fi
12
13TEMP=$(mktemp -d /tmp/XXXXXX-nixops-files) 8TEMP=$(mktemp -d /tmp/XXXXXX-nixops-files)
14chmod go-rwx $TEMP 9chmod go-rwx $TEMP
15 10
@@ -21,10 +16,10 @@ finish() {
21trap finish EXIT 16trap finish EXIT
22 17
23# pass cannot "just" list files in a directory without showing a tree :( 18# pass cannot "just" list files in a directory without showing a tree :(
24files=$(pass ls $NIXOPS_CONFIG_PASS_SUBTREE_PATH/Nixops/files | sed -e '1d' -e 's/^.* //') 19files=$(pass ls Nixops/files | sed -e '1d' -e 's/^.* //')
25 20
26for file in $files; do 21for file in $files; do
27 pass show "$NIXOPS_CONFIG_PASS_SUBTREE_PATH/Nixops/files/$file" > $TEMP/$file 22 pass show "Nixops/files/$file" > $TEMP/$file
28done 23done
29$NIXOPS set-args --argstr privateFiles "$TEMP" 24$NIXOPS set-args --argstr privateFiles "$TEMP"
30 25
diff --git a/nixops/secrets b/nixops/secrets
new file mode 160000
Subproject d34d5490226809ff9863ce4e66bd59a68ead861