home

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 18d597038bca372c9bc6210f5bcfdc711cde4dba
parent 6275ea67db03ae2cd6a1d3033fbb8eed7d152d56
Author: Vincent Demeester <vincent@sbr.pm>
Date:   Sun, 12 May 2019 20:20:41 +0200

bootstrap.sh now installs nix & home-manager

- fedora: install nix (if not present), then home-manager
- nixos: install home-manager

Under fedora (non-nixos), disable manpath from home-manager, otherwise
using any nix binary will end up failing really hard (and killing the
machine too…)

Signed-off-by: Vincent Demeester <vincent@sbr.pm>

Diffstat:
Mbootstrap.sh | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+), 0 deletions(-)

diff --git a/bootstrap.sh b/bootstrap.sh @@ -8,12 +8,72 @@ set -e +# Install nix +setup_nix() { + echo "> Install nix" + curl https://nixos.org/nix/install | sh +} + +# Install home-manager (without running it) +setup_home-manager() { + echo "> Install home-manager" + mkdir -m 0755 -p /nix/var/nix/{profiles,gcroots}/per-user/$USER + nix-channel --add https://github.com/rycee/home-manager/archive/master.tar.gz home-manager + nix-channel --update +} + +run_home-manager() { + nix-shell '<home-manager>' -A install +} + +# Fedora is "managed" by nix directly +# - bootstrap nix + home-manager setup_nixos() { echo "NixOS detected" + setup_home-manager + run_home-manager } +# Fedora is "managed" mainly using ansible +# - install ansible +# - play the "correct" playbook +# - boostrap nix + home-manager setup_fedora() { echo "Fedora detected" + if hash nix 2>/dev/null; then + echo "> nix already present" + else + setup_nix + echo "if [ -e $HOME/.nix-profile/etc/profile.d/nix.sh ]; then . $HOME/.nix-profile/etc/profile.d/nix.sh; fi # added by Nix installer" >> $HOME/.bashrc + . $HOME/.bashrc + fi + if hash home-manager 2>/dev/null; then + echo "> home-manager already present" + else + setup_home-manager + echo "export NIX_PATH=$HOME/.nix-defexpr/channels\${NIX_PATH:+:}\$NIX_PATH" >> $HOME/.bashrc + fi + if [[ ! -f $HOME/.config/nixpkgs/home.nix ]]; then + echo "> create a temporary home-manager configuration" + mkdir -p $HOME/.config/nixpkgs/ + cat > $HOME/.config/nixpkgs/home.nix <<EOF +{ + programs.home-manager.enable = true; + programs.man.enable = false; + home.extraOutputsToInstall = [ "man" ]; +} + +EOF + fi + echo "> setup nix caches" + mkdir -p $HOME/.config/nix/ + cat > $HOME/.config/nix/nix.conf <<EOF +substituters = http://nix.cache.home https://cache.nixos.org https://shortbrain.cachix.org +trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= shortbrain.cachix.org-1:dqXcXzM0yXs3eo9ChmMfmob93eemwNyhTx7wCR4IjeQ= +EOF + run_home-manager + echo ". \"$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh\"" >> $HOME/.bashrc + . $HOME/.bashrc } setup_osx() {