diff options
| author | K900 <me@0upti.me> | 2023-08-09 09:46:51 +0300 |
|---|---|---|
| committer | K900 <me@0upti.me> | 2023-08-15 22:27:46 +0300 |
| commit | 63c6c8fa7114e3f6149a34d5df5ace6b9135e47a (patch) | |
| tree | 5ce782eab89ff9d4f2dcd79752e22cc4e18dfe47 /modules | |
| parent | f7a95a37306c46b42e9ce751977c44c752fd5eca (diff) | |
feat: add a recovery shell
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/wsl-distro.nix | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/modules/wsl-distro.nix b/modules/wsl-distro.nix index ac763d7..0c5a15f 100644 --- a/modules/wsl-distro.nix +++ b/modules/wsl-distro.nix @@ -8,6 +8,22 @@ let exec ${pkgs.bashInteractive}/bin/sh "$@" ''; + nixos-enter' = config.system.build.nixos-enter.overrideAttrs (_: { + runtimeShell = "/bin/bash"; + }); + + recovery = pkgs.writeScriptBin "nixos-wsl-recovery" '' + #! /bin/sh + if [ -f /etc/NIXOS ]; then + echo "nixos-wsl-recovery should only be run from the WSL system distribution." + echo "Example:" + echo " wsl --system --distribution NixOS --user root -- /nix/var/nix/profiles/system/bin/nixos-wsl-recovery" + exit 1 + fi + mount -o remount,rw /mnt/wslg/distro + exec /mnt/wslg/distro/${nixos-enter'}/bin/nixos-enter --root /mnt/wslg/distro "$@" + ''; + cfg = config.wsl; in { @@ -125,6 +141,9 @@ in ln -sf /init /bin/wslpath ln -sf ${cfg.binShPkg}/bin/sh /bin/sh ln -sf ${pkgs.util-linux}/bin/mount /bin/mount + + # needs to be a copy, not a symlink, to be executable from outside + cp -f ${recovery}/bin/nixos-wsl-recovery /bin/nixos-wsl-recovery ''); update-entrypoint.text = '' mkdir -p /nix/nixos-wsl |
