]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - nixops/scripts/setup
Simplify management of secrets in nixops
[perso/Immae/Config/Nix.git] / nixops / scripts / setup
CommitLineData
9f5da6d7
IB
1#!/bin/bash
2
d07d139a 3set -euo pipefail
05ec8138 4
4506dbe5 5MAKEFILE_DIR="$( cd "$( dirname $( dirname "${BASH_SOURCE[0]}" ))" >/dev/null 2>&1 && pwd )"
568d4240
IB
6
7if ! which nix 2>/dev/null >/dev/null; then
8 cat <<-EOF
9 nix is needed, please install it:
10 > curl https://nixos.org/nix/install | sh
11 (or any other way handled by your distribution)
12 EOF
13 exit 1
14fi
9f5da6d7 15
df6dc085
IB
16if [ "${NIX_STORE:-/nix/store}" != "/nix/store" ]; then
17 cat <<-EOF
18 Nix store outside of /nix/store is not supported
19 EOF
20 exit 1
21fi
22
1052bfda 23gpg_keys=$(pass ls Nixops/GPGKeys | sed -e "1d" | cut -d" " -f2)
d07d139a 24for key in $gpg_keys; do
1052bfda 25 content=$(pass show Nixops/GPGKeys/$key)
d07d139a
IB
26 fpr=$(echo "$content" | gpg --import-options show-only --import --with-colons | grep -e "^pub" | cut -d':' -f5)
27 gpg --list-key "$fpr" >/dev/null 2>/dev/null && imported=yes || imported=no
28 # /usr/share/doc/gnupg/DETAILS field 2
29 (echo "$content" | gpg --import-options show-only --import --with-colons |
30 grep -E '^pub:' |
31 cut -d':' -f2 |
32 grep -q '[fu]') && signed=yes || signed=no
33 if [ "$signed" = no -o "$imported" = no ] ; then
34 echo "The key for $key needs to be imported and signed (a local signature is enough)"
35 echo "$content" | gpg --import-options show-only --import
36 echo "Continue? [y/N]"
37 read y
38 if [ "$y" = "y" -o "$y" = "Y" ]; then
39 echo "$content" | gpg --import
40 gpg --expert --edit-key "$fpr" lsign quit
41 else
42 echo "Aborting"
43 exit 1
44 fi
45 fi
46done
47
08822d6f
IB
48if nix show-config --json | jq -e '.sandbox.value == "true"' >/dev/null; then
49 cat <<-EOF
e83ec961 50 There used to be some impure derivations (grep __noChroot), you may need
08822d6f
IB
51 sandbox = "relaxed"
52 in /etc/nix/nix.conf
53 you may also want to add
54 keep-outputs = true
55 keep-derivations = true
56 to prevent garbage collector from deleting build dependencies (they take a lot of time to build)
e83ec961
IB
57 and
58 allow-import-from-derivation = false
59 as an attempt to avoid having build-time derivations (doesn’t work for all packages)
60 press key to continue
08822d6f 61 EOF
e83ec961 62 read y
08822d6f
IB
63fi
64
4506dbe5 65if ! make -C $MAKEFILE_DIR deployment_is_set 2>/dev/null >/dev/null; then
568d4240
IB
66 cat <<-EOF
67 Importing deployment file into nixops:
68 Continue? [y/N]
69 EOF
70 read y
71 if [ "$y" = "y" -o "$y" = "Y" ]; then
4506dbe5 72 make -C $MAKEFILE_DIR pull_deployment
568d4240
IB
73 else
74 echo "Aborting"
75 exit 1
34c58714 76 fi
9f5da6d7 77fi
34c58714 78
568d4240
IB
79cat <<-EOF
80 All set up.
4506dbe5 81 Please make sure you’re using make commands when deploying
568d4240 82 EOF