-
Notifications
You must be signed in to change notification settings - Fork 0
/
initialize-user-1.sh
50 lines (40 loc) · 1.16 KB
/
initialize-user-1.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env bash
set -euo pipefail
echo "Starting initialize-user-1.sh with arguments '$1'"
multi_user=$1
if [ $multi_user = "y" ]; then
daemon_arg="--daemon"
else
daemon_arg="--no-daemon"
fi
echo "Installing Nix"
sh <(curl -L https://nixos.org/nix/install) $daemon_arg
if [ $multi_user != "y" ]; then
echo ". /home/$USER/.nix-profile/etc/profile.d/nix.sh" >> ~/.profile
fi
echo "Creating nix config file"
configContent="experimental-features = nix-command flakes"
if [ $multi_user = "y" ]; then
conf_folder="/etc/nix"
conf_file="$conf_folder/nix.conf"
cp $conf_file .
chown $USER nix.conf
cat >> "nix.conf" << EOF
$configContent
EOF
sudo mv -f "nix.conf" $conf_file
sudo chown root:root $conf_file
sudo chmod u=rw,g=rw,o=r $conf_file
else
conf_folder="~/.config/nix"
mkdir -p "$conf_folder"
cat > "$conf_folder/nix.conf" << EOF
$configContent
EOF
fi
echo "Configuring WSL to launx nix-daemon on boot"
if [ $multi_user = "y" ]; then
echo "[boot]" | sudo tee -a /etc/wsl.conf
echo "command = /nix/var/nix/profiles/default/bin/nix-daemon" | sudo tee -a /etc/wsl.conf
echo "" | sudo tee -a /etc/wsl.conf
fi