Last active
May 14, 2016 16:38
-
-
Save zefhemel/7300869 to your computer and use it in GitHub Desktop.
Install Nix on 64-bit Ubuntu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
# Install the binary tarball... | |
cd / | |
wget -O - http://hydra.nixos.org/job/nix/trunk/binaryTarball.x86_64-linux/latest/download | tar xvj | |
/usr/bin/nix-finish-install | |
rm /usr/bin/nix-finish-install | |
# Setup multiuser | |
# Allow all users to create profiles | |
mkdir -p /nix/var/nix/profiles/per-user | |
chmod 1777 /nix/var/nix/profiles/per-user | |
# Add build users | |
# 9 is the exit code when the group already exists | |
groupadd -r nixbld || [ "$?" -eq 9 ] | |
for n in 1 2 3 4 5 6 7 8 9 10; do | |
useradd -c "Nix build user $n" -d /var/empty -g nixbld -G nixbld \ | |
-M -N -r -s `which nologin` nixbld$n || [ "$?" -eq 9 ] | |
done | |
chown root:nixbld /nix/store | |
chmod 1775 /nix/store | |
mkdir -p /etc/nix | |
grep -w build-users-group /etc/nix/nix.conf 2>/dev/null || echo "build-users-group = nixbld" >> /etc/nix/nix.conf | |
grep -w binary-caches /etc/nix/nix.conf 2>/dev/null || echo "binary-caches = http://cache.nixos.org" >> /etc/nix/nix.conf | |
grep -w trusted-binary-caches /etc/nix/nix.conf 2>/dev/null || echo "trusted-binary-caches = http://hydra.nixos.org http://builder.logicblox.com http://cache.nixos.org" >> /etc/nix/nix.conf | |
# Use a multiuser-compatible profile script | |
unlink /etc/profile.d/nix.sh | |
cat > /etc/profile.d/nix.sh <<EOF | |
if test -n "\$HOME"; then | |
NIX_LINK="\$HOME/.nix-profile" | |
if [ -w /nix/var/nix/db ]; then | |
OWNS_STORE=1 | |
fi | |
# Set the default profile. | |
if ! [ -L "\$NIX_LINK" ]; then | |
echo "creating \$NIX_LINK" >&2 | |
if [ -n "\$OWNS_STORE" ]; then | |
_NIX_PROFILE_LINK=/nix/var/nix/nix/profiles/default | |
else | |
mkdir -p "/nix/var/nix/profiles/per-user/\$LOGNAME" | |
_NIX_PROFILE_LINK="/nix/var/nix/profiles/per-user/\$LOGNAME/profile" | |
fi | |
ln -s "\$_NIX_PROFILE_LINK" "\$NIX_LINK" | |
fi | |
# Subscribe the root user to the Nixpkgs channel by default. | |
if [ -n "\$OWNS_STORE" ] && [ ! -e "\$HOME/.nix-channels" ]; then | |
echo "http://nixos.org/channels/nixpkgs-unstable nixpkgs" > "\$HOME/.nix-channels" | |
fi | |
# Set up nix-defexpr | |
NIX_DEFEXPR="\$HOME/.nix-defexpr" | |
if ! [ -e "\$NIX_DEFEXPR" ]; then | |
echo "creating \$NIX_DEFEXPR" >&2 | |
mkdir -p "\$NIX_DEFEXPR" | |
_NIX_CHANNEL_LINK=/nix/var/nix/profiles/per-user/root/channels/nixpkgs | |
ln -s "\$_NIX_CHANNEL_LINK" "\$NIX_DEFEXPR" | |
fi | |
if [ -z "\$OWNS_STORE" ]; then | |
export NIX_REMOTE=daemon | |
export PATH="/nix/var/nix/profiles/default/bin:\$PATH" | |
fi | |
export PATH="\$NIX_LINK/bin:\$PATH" | |
# Set up NIX_PATH | |
export NIX_PATH="\${NIX_PATH:+\$NIX_PATH:}/nix/var/nix/profiles/per-user/\$LOGNAME/channels" | |
unset OWNS_STORE | |
fi | |
EOF | |
cat >> /etc/environment <<EOF | |
PATH="\$PATH:/nix/var/nix/profiles/default/bin" | |
EOF | |
# Install upstart job | |
cat > /etc/init/nix-daemon.conf <<EOF | |
description "Nix Daemon" | |
start on filesystem | |
stop on shutdown | |
respawn | |
env NIX_CONF_DIR="/etc/nix" | |
exec $(readlink -f /nix/var/nix/profiles/default/bin/nix-daemon) --daemon | |
EOF | |
# Start nix daemon | |
initctl start nix-daemon | |
# Update the nix channel | |
/nix/var/nix/profiles/default/bin/nix-channel --update |
It is pretty broken however that it kills the standard PATH variable settings. I do not endorse this script.
The use of quotes is also rather giving away that you don't know how to write a decent shell script.
@zefhemel Why do you publish this crap?
Before you use a file (/etc/environment), make sure that you understand how it works, please.
https://help.ubuntu.com/community/EnvironmentVariables#A.2Fetc.2Fenvironment
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If someone writes a script designed for 64 bit Ubuntu, it sort of implies that there is no guarantee that it works on anything other than that. So, it likely does work, just not in your completely unsupported environment.