Skip to content

Commit

Permalink
extract ensure nix installed
Browse files Browse the repository at this point in the history
  • Loading branch information
joelmccracken committed Nov 4, 2023
1 parent ee6a638 commit 2c20eed
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
18 changes: 12 additions & 6 deletions bootstrap-workstation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,17 @@ function restart_nix_daemon () {
if is_linux; then restart_nix_daemon_linux; fi
}
# restart_nix_deamon_function ends here

# [[file:workstation.org::ensure_nix_installed_function][ensure_nix_installed_function]]
function ensure_nix_installed () {
if which nix > /dev/null; then
info "nix exists in path, not installing"
else
info "nix not in path, installing"
sh <(curl -L https://releases.nixos.org/nix/$WORKSTATION_NIX_PM_VERSION/install) --daemon;
fi
}
# ensure_nix_installed_function ends here
info starting workstation bootstrap
is_mac && {
info ensuring xcode is installed
Expand Down Expand Up @@ -282,12 +293,8 @@ else
exit 5
fi
info ensuring nix is installed
{ which nix > /dev/null; } || {
info installing nix
sh <(curl -L https://releases.nixos.org/nix/$WORKSTATION_NIX_PM_VERSION/install) --daemon;
}
ensure_nix_installed
info finished ensuring nix is installed

export NIX_REMOTE=daemon

info setting up nix.conf
Expand Down Expand Up @@ -335,7 +342,6 @@ export HOME_MANAGER_BACKUP_EXT=old

nix run home-manager/$WORKSTATION_HOME_MANAGER_VERSION -- init ~/workstation


# [[file:workstation.org::home_manager_flake_switch_function][home_manager_flake_switch_function]]
function home_manager_flake_switch() {
nix build --no-link ~/workstation/#homeConfigurations.${WORKSTATION_NAME}.$(whoami).activationPackage --show-trace
Expand Down
3 changes: 3 additions & 0 deletions lib/shell/setup/workstation_setup_versions.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Versions
# The versions of various things that are installed as part of the bootstrapping
# process. Sometimes I need to update these, having them contained in one spot is
# helpful.
# #+name: workstation_setup_versions

# [[file:../../../workstation.org::workstation_setup_versions][workstation_setup_versions]]
Expand Down
23 changes: 14 additions & 9 deletions workstation.org
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ EMACS_CONFIG_DIR=~/.config/emacs
«install_system_nix_conf_function»

«restart_nix_deamon_function»

«ensure_nix_installed_function»
#+end_src
*** Log that bootstrap is starting
#+begin_src shell
Expand Down Expand Up @@ -329,15 +331,15 @@ else
exit 5
fi
#+end_src
*** rest of the script

*** set up nix
#+begin_src shell :noweb yes
info ensuring nix is installed
{ which nix > /dev/null; } || {
info installing nix
sh <(curl -L https://releases.nixos.org/nix/$WORKSTATION_NIX_PM_VERSION/install) --daemon;
}
ensure_nix_installed
info finished ensuring nix is installed

#+end_src
*** rest of the script
#+begin_src shell :noweb yes
export NIX_REMOTE=daemon

info setting up nix.conf
Expand Down Expand Up @@ -499,6 +501,9 @@ function clone_repo_and_checkout_at() {
}
#+end_src
*** Versions
The versions of various things that are installed as part of the bootstrapping
process. Sometimes I need to update these, having them contained in one spot is
helpful.
#+name: workstation_setup_versions
#+begin_src sh :tangle ./lib/shell/setup/workstation_setup_versions.sh :noweb yes
export WORKSTATION_NIX_PM_VERSION=nix-2.11.1
Expand Down Expand Up @@ -625,9 +630,6 @@ restart_nix_daemon
*** Install Nix
#+name: ensure_nix_installed_function
#+begin_src shell :noweb yes
source ~/workstation/lib/shell/setup/workstation_setup_versions.sh
source ~/workstation/lib/shell/funcs.sh

function ensure_nix_installed () {
if which nix > /dev/null; then
info "nix exists in path, not installing"
Expand All @@ -640,6 +642,9 @@ function ensure_nix_installed () {

External Script:
#+begin_src sh :tangle ./lib/shell/setup/ensure_nix_installed.sh :shebang "#!/usr/bin/env bash" :noweb yes
source ~/workstation/lib/shell/setup/workstation_setup_versions.sh
source ~/workstation/lib/shell/funcs.sh

«ensure_nix_installed_function»
ensure_nix_installed
#+end_src
Expand Down

0 comments on commit 2c20eed

Please sign in to comment.