Skip to content

Commit

Permalink
Add store prefix to (first time) install NixOS
Browse files Browse the repository at this point in the history
  • Loading branch information
blaggacao committed Aug 12, 2021
1 parent 0668fac commit 90e1ef8
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 59 deletions.
46 changes: 44 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,54 @@
# work around https://github.com/NixOS/nixpkgs/issues/73404
cd /tmp
$PROFILE/bin/switch-to-configuration switch
STORE_ROOT="''${STORE_ROOT%'/'}"
_SYSTEM="$STORE_ROOT/nix/var/nix/profiles/system"
_PROFILE="$STORE_ROOT/$PROFILE"
_SWITCH_COMMAND="$PROFILE/bin/switch-to-configuration switch" # always relative to root
_NIXOS_ENTER_COMMAND="nixos-enter --root $STORE_ROOT"
_already_on_nixos() { return [[ ! -f "$STORE_ROOT/etc/NIXOS" ]]; }
_set_system_profile() {
if [[ "$STORE_ROOT" == "" ]]
then
nix-env -p "$_SYSTEM" --set "$_PROFILE"
else
nix-env --store "$STORE_ROOT" -p "$_SYSTEM" --set "$_PROFILE"
done
}
_ensure_fs_contract() { mkdir -m 0755 -p "$STORE_ROOT"/etc; touch "$STORE_ROOT"/etc/NIXOS; }
_insall_bootloader_and_switch() {
ln -sfn /proc/mounts "$STORE_ROOT"/etc/mtab # Grub needs an mtab.
if [[ "$STORE_ROOT" == "" ]]
then
NIXOS_INSTALL_BOOTLOADER=1 $_SWITCH_COMMAND
else
NIXOS_INSTALL_BOOTLOADER=1 $_NIXOS_ENTER_COMMAND -- $_SWITCH_COMMAND
done
}
_switch_configuration() {
if [[ "$STORE_ROOT" == "" ]]
then
$_SWITCH_COMMAND
else
$_NIXOS_ENTER_COMMAND -- $_SWITCH_COMMAND
done
}
if _already_on_nixos
then
_switch_configuration
else
_set_system_profile
_ensure_fs_contract
_insall_bootloader_and_switch
done
# https://github.com/serokell/deploy-rs/issues/31
${with base.config.boot.loader;
final.lib.optionalString systemd-boot.enable
"sed -i '/^default /d' ${efi.efiSysMountPoint}/loader/loader.conf"}
"sed -i '/^default /d' $STORE_ROOT/${efi.efiSysMountPoint}/loader/loader.conf"}
'';

home-manager = base: custom base.activationPackage "$PROFILE/activate";
Expand Down
Loading

0 comments on commit 90e1ef8

Please sign in to comment.