Commit 18d597038bca

Vincent Demeester <vincent@sbr.pm>
2019-05-12 20:20:41
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>
1 parent 6275ea6
Changed files (1)
bootstrap.sh
@@ -8,12 +8,72 @@
 
 set -e
 
-setup_nixos() {
-    echo "NixOS detected"
+# 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() {