]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - nixops/scripts/setup
Freeze channel version when deploying.
[perso/Immae/Config/Nix.git] / nixops / scripts / setup
CommitLineData
9f5da6d7
IB
1#!/bin/bash
2
3RemoteRepo="gitolite@git.immae.eu:perso/Immae/Prive/Password_store/Mes_Sites/Paul"
34c58714
IB
4NixChannelUrl='https://releases.nixos.org/nixos/18.09/nixos-18.09.1834.9d608a6f592'
5NixChannelName='immaeNixpkgs'
9f5da6d7
IB
6
7if [ -z "$NIXOPS_CONFIG_PASS_SUBTREE_REMOTE" \
8 -o -z "$NIXOPS_CONFIG_PASS_SUBTREE_PATH" ]; then
9 cat <<-EOF
10Two environment variables are needed to setup the password store:
11NIXOPS_CONFIG_PASS_SUBTREE_PATH : path where the subtree will be imported
12NIXOPS_CONFIG_PASS_SUBTREE_REMOTE : remote name to give to the repository
13EOF
14 exit 1
15fi
16
17if ! pass $NIXOPS_CONFIG_PASS_SUBTREE_PATH > /dev/null 2>/dev/null; then
18 cat <<-EOF
19/!\ This will modify your password store to add and import a subtree
20with the specific passwords files. Choose a path that doesn’t exist
21yet in your password store.
22> pass git remote add $NIXOPS_CONFIG_PASS_SUBTREE_REMOTE $RemoteRepo
23> pass git subtree add --prefix=$NIXOPS_CONFIG_PASS_SUBTREE_PATH $NIXOPS_CONFIG_PASS_SUBTREE_REMOTE master
24Later, you can use pull_environment and push_environment scripts to
25update the passwords when needed
26Continue? [y/N]
27EOF
28 read y
29 if [ "$y" = "y" -o "$y" = "Y" ]; then
30 pass git remote add $NIXOPS_CONFIG_PASS_SUBTREE_REMOTE $RemoteRepo
31 pass git subtree add --prefix=$NIXOPS_CONFIG_PASS_SUBTREE_PATH $NIXOPS_CONFIG_PASS_SUBTREE_REMOTE master
32 else
33 echo "Aborting"
34 exit 1
35 fi
36fi
37
38if [ ! -f /etc/ssh/ssh_rsa_key_nixops ]; then
39 cat <<EOF
40The key to access private git repositories (websites hosted by the
41server) needs to be accessible to nix builders. It will be put in
42/etc/ssh/ssh_rsa_key_nixops (sudo right is needed for that)
43> pass show $NIXOPS_CONFIG_PASS_SUBTREE_PATH/NixSshKey | sudo tee /etc/ssh/ssh_rsa_key_nixops > /dev/null
44> pass show $NIXOPS_CONFIG_PASS_SUBTREE_PATH/NixSshKey.pub | sudo tee /etc/ssh/ssh_rsa_key_nixops.pub > /dev/null
45> sudo chmod u=r,go-rwx /etc/ssh/ssh_rsa_key_nixops
46> sudo chown nixbld1:nixbld /etc/ssh/ssh_rsa_key_nixops /etc/ssh/ssh_rsa_key_nixops.pub
47Continue? [y/N]
48EOF
49 read y
50 if [ "$y" = "y" -o "$y" = "Y" ]; then
51 if ! id -u nixbld1 2>/dev/null >/dev/null; then
52 echo "User nixbld1 seems inexistant, did you install nix?"
53 exit 1
54 fi
55 mask=$(umask)
56 umask 0777
57 # Don’t forward it directly to tee, it would break ncurse pinentry
58 key=$(pass show $NIXOPS_CONFIG_PASS_SUBTREE_PATH/NixSshKey)
59 echo "$key" | sudo tee /etc/ssh/ssh_rsa_key_nixops > /dev/null
60 sudo chmod u=r,go=- /etc/ssh/ssh_rsa_key_nixops
61 pubkey=$(pass show $NIXOPS_CONFIG_PASS_SUBTREE_PATH/NixSshKey.pub)
62 echo "$pubkey" | sudo tee /etc/ssh/ssh_rsa_key_nixops.pub > /dev/null
63 sudo chmod a=r /etc/ssh/ssh_rsa_key_nixops.pub
64 sudo chown nixbld1:nixbld /etc/ssh/ssh_rsa_key_nixops /etc/ssh/ssh_rsa_key_nixops.pub
65 umask $mask
66 else
67 echo "Aborting"
68 exit 1
69 fi
70fi
71
34c58714 72if ! nix-channel --list | grep -q "$NixChannelName $NixChannelUrl"; then
9f5da6d7 73cat <<EOF
34c58714
IB
74A new nix channel will be installed (or upgraded) to freeze the packages
75version:
76$NixChannelName $NixChannelUrl
77> nix-channel --add $NixChannelUrl $NixChannelName
78> nix-channel --update
79If this step fail, you may have to disable sandboxing in
80/etc/nix/nix.conf and rerun
81> nix-channel --update
82manually.
83Continue? [y/N]
9f5da6d7 84EOF
34c58714
IB
85 read y
86 if [ "$y" = "y" -o "$y" = "Y" ]; then
87 nix-channel --add $NixChannelUrl $NixChannelName
88 nix-channel --update
89 fi
9f5da6d7 90fi
34c58714
IB
91
92cat <<EOF
93All set up.
94Please make sure you’re using scripts/nixops_wrap when deploying
95EOF