Skip to content

Commit

Permalink
more simply using the scripts on fs
Browse files Browse the repository at this point in the history
  • Loading branch information
joelmccracken committed Nov 19, 2023
1 parent 35758db commit ff1a06f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 89 deletions.
36 changes: 3 additions & 33 deletions bootstrap-workstation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -209,26 +209,6 @@ function install_doom_emacs_no_nix() {
}
# install_doom_emacs_no_nix_function ends here

# [[file:workstation.org::install_system_nix_conf_function][install_system_nix_conf_function]]

function emit_nix_conf_content () {
cat - <<-EOF
# Generated at $(date)
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=
substituters = https://cache.nixos.org https://cache.iog.io
experimental-features = nix-command flakes
trusted-users = root $(whoami) runner
build-users-group = nixbld
# END OF /etc/nix/nix.conf
EOF
}

function install_system_nix_conf() {
emit_nix_conf_content | \
sudo bash -c 'mkdir -p /etc/nix; cat > /etc/nix/nix.conf'
}
# install_system_nix_conf_function ends here

# [[file:workstation.org::restart_nix_deamon_function][restart_nix_deamon_function]]
function restart_nix_daemon_linux() {
sudo systemctl restart nix-daemon.service;
Expand All @@ -247,17 +227,6 @@ function restart_nix_daemon () {
}
# 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 @@ -319,11 +288,12 @@ else
fi

info ensuring nix is installed
ensure_nix_installed
~/workstation/lib/shell/setup/ensure_nix_installed.sh

info finished ensuring nix is installed

info setting up nix.conf
install_system_nix_conf
~/workstation/lib/shell/setup/install_system_nix_conf.sh

info restarting nix daemon
restart_nix_daemon
Expand Down
23 changes: 9 additions & 14 deletions lib/shell/setup/ensure_nix_installed.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
#!/usr/bin/env bash
# Install Nix


# External Script:

# [[file:../../../workstation.org::*Install Nix][Install Nix:2]]
# [[file:../../../workstation.org::*Install Nix][Install Nix:1]]
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"
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
# Install Nix:2 ends here
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
# Install Nix:1 ends here
26 changes: 17 additions & 9 deletions lib/shell/setup/install_system_nix_conf.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
#!/usr/bin/env bash
# install nix configuration file
# I wish I could do this with a nix-like thing, but sadly, there are several
# complications.
# - for MacOS, this is nix-darwin.
# - for Ubuntu, there is nothing that can do it.
# - There _is_ a way to do something similar with home manager, but it sets the
# _user_ nix settings, _not_ the system settings. This is not overly surprising,
# but it does mean that it can't be the sole solution for setting
# configurations, if you need to set up caches/substituters.
# At the very least, I would need some *other* way besides home manager to
# sepecify that my user is a trusted user. But, then, there becomes a question
# of bootstrapping (nix settings needed before home manager ever runs), so I
# think its overall easier to just hack a thing with bash.

# External Script:

# [[file:../../../workstation.org::*install nix configuration file][install nix configuration file:2]]
# [[file:../../../workstation.org::*install nix configuration file][install nix configuration file:1]]
function emit_nix_conf_content () {
cat - <<-EOF
# Generated at $(date)
Expand All @@ -15,9 +26,6 @@ build-users-group = nixbld
EOF
}

function install_system_nix_conf() {
emit_nix_conf_content | \
sudo bash -c 'mkdir -p /etc/nix; cat > /etc/nix/nix.conf'
}
install_system_nix_conf
# install nix configuration file:2 ends here
emit_nix_conf_content | \
sudo bash -c 'mkdir -p /etc/nix; cat > /etc/nix/nix.conf'
# install nix configuration file:1 ends here
47 changes: 14 additions & 33 deletions workstation.org
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,8 @@ fi

«install_doom_emacs_no_nix_function»

«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 @@ -333,11 +329,12 @@ fi
#+begin_src shell :noweb yes

info ensuring nix is installed
ensure_nix_installed
~/workstation/lib/shell/setup/ensure_nix_installed.sh

info finished ensuring nix is installed

info setting up nix.conf
install_system_nix_conf
~/workstation/lib/shell/setup/install_system_nix_conf.sh

info restarting nix daemon
restart_nix_daemon
Expand Down Expand Up @@ -578,9 +575,7 @@ complications.
sepecify that my user is a trusted user. But, then, there becomes a question
of bootstrapping (nix settings needed before home manager ever runs), so I
think its overall easier to just hack a thing with bash.
#+name: install_system_nix_conf_function
#+begin_src shell :noweb yes

#+begin_src sh :tangle ./lib/shell/setup/install_system_nix_conf.sh :shebang "#!/usr/bin/env bash" :noweb yes
function emit_nix_conf_content () {
cat - <<-EOF
# Generated at $(date)
Expand All @@ -593,15 +588,9 @@ build-users-group = nixbld
EOF
}

function install_system_nix_conf() {
emit_nix_conf_content | \
sudo bash -c 'mkdir -p /etc/nix; cat > /etc/nix/nix.conf'
}
#+end_src
External Script:
#+begin_src sh :tangle ./lib/shell/setup/install_system_nix_conf.sh :shebang "#!/usr/bin/env bash" :noweb yes
«install_system_nix_conf_function»
install_system_nix_conf
emit_nix_conf_content | \
sudo bash -c 'mkdir -p /etc/nix; cat > /etc/nix/nix.conf'

#+end_src
*** restart nix daemons
Sometimes we need to restart the nix daemons, e.g. after editing the nix config
Expand Down Expand Up @@ -632,25 +621,17 @@ source ~/workstation/lib/shell/funcs.sh
restart_nix_daemon
#+end_src
*** Install Nix
#+name: ensure_nix_installed_function
#+begin_src shell :noweb yes
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
}
#+end_src

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
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

#+end_src
*** Install doom emacs without nix
#+name: install_doom_emacs_no_nix_function
Expand Down

0 comments on commit ff1a06f

Please sign in to comment.