Skip to content

Instantly share code, notes, and snippets.

@jtimberman
Forked from dysinger/nix.sh
Last active December 16, 2015 07:39
Show Gist options
  • Save jtimberman/5400084 to your computer and use it in GitHub Desktop.
Save jtimberman/5400084 to your computer and use it in GitHub Desktop.
remote_file "/tmp/nix-1.5.1-x86_64-linux.tar.bz2" do
source "http://hydra.nixos.org/build/4253979/download/1/nix-1.5.1-x86_64-linux.tar.bz2"
notifies :run, "execute[untar nix]", :immediately
end
execute "untar nix" do
cwd "tmp"
command "tar -jxf /tmp/nix-1.5.1-x86_64-linux.tar.bz2 -C /"
action :nothing
notifies :run, "execute[nix-finish-install]"
end
execute "nix-finish-install" do
action :nothing
end
link "/etc/profiled./nix.sh" do
to "/nix/var/nix/profiles/default/etc/profile.d/nix.sh"
end
directory "#{node['current_user']}/.nix-defexpr"
file "/etc/profile.d/nix-defexpr.sh" do
content "[ ! -d $HOME/.nix-defexpr ] && mkdir $HOME/.nix-defexpr\n"
end
group "nixbld" do
system true
end
(1..10).each do |i|
user "nixbld#{i}" do
gid "nixbld"
shell "/bin/false"
home "/var/empty"
comment "Nix Build User #{i}"
end
end
file "/nix/store" do
group "nixbld"
mode 01775
end
directory "/nix/var/nix/profiles" do
recursive true
mode 01777
end
directory "/nix/var/nix/profiles/per-user" do
recursive true
mode 01777
end
directory "/etc/nix" do
group "nixbld"
end
file "/etc/nix/nix.conf" do
content "build-users-group = nixbld\n"
end
file "/etc/profile.d/nix-worker.sh" do
content "export NIX_REMOTE=daemon\n"
end
file "/etc/init/nix-worker.conf" do
content <<-EOH
start on runlevel [2345]
stop on runlevel [016]
respawn
exec /nix/var/nix/profiles/default/bin/nix-worker --daemon
EOH
end
service "nix-worker" do
action :start
end
execute "nix-channel --update"
#!/bin/sh
# INSTALL
wget -O- http://hydra.nixos.org/build/4253979/download/1/nix-1.5.1-x86_64-linux.tar.bz2 \
| tar xj -C /
sudo -i nix-finish-install
# DEFAULT PROFILE
ln -sf /nix/var/nix/profiles/default/etc/profile.d/nix.sh \
/etc/profile.d/nix.sh
# NIX-DEFEXPR DIR
echo '[ ! -d $HOME/.nix-defexpr ] && mkdir $HOME/.nix-defexpr' \
| tee /etc/profile.d/nix-defexpr.sh
# DAEMON USERS
grep '/bin/false' /etc/shells||(echo '/bin/false'|tee -a /etc/shells)
groupadd -r nixbld
for i in `seq 1 10`; do
useradd -r \
-g nogroup \
-G nixbld \
-d /var/empty \
-s /bin/false \
-c "Nix Build User $i" \
nixbld$i;
done
# DAEMON PERMS
chgrp nixbld /nix/store
chmod 1775 /nix/store
mkdir -p /nix/var/nix/profiles/per-user
chmod 1777 /nix/var/nix/profiles/per-user /nix/var/nix/profiles
# DAEMON CONFIG
mkdir /etc/nix
echo 'build-users-group = nixbld' | tee /etc/nix/nix.conf
echo 'export NIX_REMOTE=daemon' | tee /etc/profile.d/nix-worker.sh
cat >/etc/init/nix-worker.conf <<\EOF
start on runlevel [2345]
stop on runlevel [016]
respawn
exec /nix/var/nix/profiles/default/bin/nix-worker --daemon
EOF
# NIX UPDATE
service nix-worker start
sudo -i nix-channel --update
sudo -i nix-env -u nix-1.5.1
sudo -i nix-collect-garbage -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment