]>
git.immae.eu Git - perso/Immae/Config/Nix.git/blob - nixops/scripts/setup
793b7c3f1553b763dad322b6fa0fa2a71e51c888
5 RemoteRepo
="gitolite@git.immae.eu:perso/Immae/Prive/Password_store/Sites"
6 DeploymentUuid
="cef694f3-081d-11e9-b31f-0242ec186adf"
8 if ! which nix
2>/dev
/null
>/dev
/null
; then
10 nix is needed, please install it:
11 > curl https://nixos.org/nix/install | sh
12 (or any other way handled by your distribution)
17 if [ "${NIX_STORE:-/nix/store}" != "/nix/store" ]; then
19 Nix store outside of /nix/store is not supported
24 if [ -z "$NIXOPS_CONFIG_PASS_SUBTREE_REMOTE" \
25 -o -z "$NIXOPS_CONFIG_PASS_SUBTREE_PATH" ]; then
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
34 if ! pass
$NIXOPS_CONFIG_PASS_SUBTREE_PATH > /dev
/null
2>/dev
/null
; then
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
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
55 # Repull it before using it, just in case
56 pass git subtree pull
--prefix=$NIXOPS_CONFIG_PASS_SUBTREE_PATH $NIXOPS_CONFIG_PASS_SUBTREE_REMOTE master
58 gpg_keys
=$(pass ls $NIXOPS_CONFIG_PASS_SUBTREE_PATH/Nixops/GPGKeys | sed -e "1d" | cut -d" " -f2)
59 for key
in $gpg_keys; do
60 content
=$(pass show $NIXOPS_CONFIG_PASS_SUBTREE_PATH/Nixops/GPGKeys/$key)
61 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
63 # /usr/share/doc/gnupg/DETAILS field 2
64 (echo "$content" | gpg
--import-options show
-only --import --with-colons |
67 grep -q '[fu]') && signed
=yes || signed
=no
68 if [ "$signed" = no
-o "$imported" = no
] ; then
69 echo "The key for $key needs to be imported and signed (a local signature is enough)"
70 echo "$content" | gpg
--import-options show
-only --import
71 echo "Continue? [y/N]"
73 if [ "$y" = "y" -o "$y" = "Y" ]; then
74 echo "$content" | gpg
--import
75 gpg
--expert --edit-key "$fpr" lsign quit
83 if nix show
-config --json | jq
-e '.sandbox.value == "true"' >/dev
/null
; then
85 There used to be some impure derivations (grep __noChroot), you may need
88 you may also want to add
90 keep-derivations = true
91 to prevent garbage collector from deleting build dependencies (they take a lot of time to build)
93 allow-import-from-derivation = false
94 as an attempt to avoid having build-time derivations (doesn’t work for all packages)
100 DIR
="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev
/null
2>&1 && pwd )"
101 export NIXOPS_STATE="$(dirname $DIR)/state
/eldiron.nixops
"
102 export NIXOPS_DEPLOYMENT="$DeploymentUuid"
103 source $(dirname $(dirname $DIR))/scripts/nix_env
105 if ! nixops_custom info 2>/dev/null >/dev/null; then
107 Importing deployment file into nixops:
111 if [ "$y" = "y
" -o "$y" = "Y
" ]; then
112 deployment=$(pass show $NIXOPS_CONFIG_PASS_SUBTREE_PATH/Nixops/Deployment)
113 echo "$deployment" | nixops_custom import
120 nixops_custom modify "$(dirname $DIR)/default.nix
"
124 Please make sure you’re using scripts/nixops_wrap when deploying