]> git.immae.eu Git - perso/Immae/Config/AUR.git/blob - nix.install
update to 1.11.16
[perso/Immae/Config/AUR.git] / nix.install
1
2 pre_install () {
3 # Check that the group and users don't already exist
4 if [[ -n $(cut -d: -f1 /etc/group | grep -w nixbld) ]]; then
5 echo "The nixbld group already exists. This install cannot proceed."
6 exit 1
7 fi
8
9 for i in {1..10}; do
10 if [[ -n $(cut -d: -f1 /etc/passwd | grep -w nixbld$i) ]]; then
11 echo "The nixbld$i user already exists. This install cannot proceed."
12 exit 1
13 fi
14 done
15 }
16
17 create_users () {
18 # Create a nixbld group.
19 groupadd -r nixbld
20
21 # Create 10 nixbld{i} users
22 for i in {1..10}; do
23 useradd -g nixbld -G nixbld -r -N -M -d /var/empty -s /sbin/nologin nixbld$i
24 done
25 }
26
27 delete_users() {
28 # Remove the users
29 for i in {1..10}; do
30 userdel nixbld$i
31 done
32
33 # Remove the group
34 groupdel nixbld
35 }
36
37 create_store() {
38 # Create nix folders and set permissions
39 mkdir -p /nix/store
40 chown root.nixbld /nix/store
41 chmod 1775 /nix/store
42 mkdir -p -m 1777 /nix/var/nix/gcroots/per-user
43 mkdir -p -m 1777 /nix/var/nix/profiles/per-user
44 }
45
46 restore_store() {
47 # Restore folder permissions
48 chmod 755 /nix/store
49 chown root.root /nix/store
50 }
51
52 daemon_info() {
53 if [ ! -d /nix/var/nix/profiles/per-user/root ]; then
54 echo "To start the nix daemon, execute one of the following:"
55 echo
56 echo " systemctl enable nix-daemon.socket # Sets the daemon to start on next boot"
57 echo " systemctl enable --now nix-daemon.socket # Starts now and on next boot too"
58 echo
59 echo "Also, if this is a new install, you need to start a new login shell or otherwise"
60 echo
61 echo " source /etc/profile.d/nix.sh"
62 echo " source /etc/profile.d/nix-daemon.sh"
63 echo
64 echo "Once your environment is set-up, you will need to add some channels. You can see how"
65 echo "to do that here:"
66 echo " https://nixos.org/nix/manual/#sec-channels"
67 fi
68 }
69
70 post_install() {
71 create_users
72 create_store
73 daemon_info
74 }
75
76 pre_upgrade() {
77 systemctl stop nix-daemon.socket
78 systemctl stop nix-daemon
79 }
80
81 post_upgrade() {
82 delete_users
83 create_users
84 create_store
85 daemon_info
86 }
87
88 pre_remove() {
89 restore_store
90 delete_users
91 }