diff --git a/configurations/mobile.nix b/configurations/mobile.nix index 1b1a3ff..749ed27 100644 --- a/configurations/mobile.nix +++ b/configurations/mobile.nix @@ -31,6 +31,11 @@ let # (default is bashInteractive) user.shell = "${pkgs.zsh}/bin/zsh"; + # SSH user (matches `User oqyude` in the client's ~/.ssh/config). + # Default is "nix-on-droid"; home stays at the read-only + # /data/data/com.termux.nix/files/home either way. + user.userName = "oqyude"; + # Minimal termux settings (nix-on-droid options only: # environment.*, nix.*, time.*, user.*, system.*, android-integration.*) diff --git a/home/termux.nix b/home/termux.nix index 0e636b1..1941f94 100644 --- a/home/termux.nix +++ b/home/termux.nix @@ -51,11 +51,18 @@ TUCKR_HOME = "$HOME/Storage/dotfiles"; EDITOR = "fresh"; }; - file.".nanorc".text = '' - set nowrap - set tabstospaces - set tabsize 2 - ''; + file = { + ".nanorc".text = '' + set nowrap + set tabstospaces + set tabsize 2 + ''; + # Authorized keys for sshd (see modules/termux/default.nix). + # Declarative for now — the Store/.ssh symlink scheme is postponed. + ".ssh/authorized_keys".text = '' + ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKduJia+unaQQdN6X5syaHvnpIutO+yZwvfiCP4qKQ/P + ''; + }; }; programs = { # ---- Shell: zsh ---- @@ -68,7 +75,7 @@ enable = true; theme = "robbyrussell"; }; - loginExtra = "clear && fastfetch"; + loginExtra = "clear && fastfetch && cd ~/.config/nix-on-droid"; initContent = '' beet-p() { local base="${config.home.homeDirectory}/.config/beets/My" @@ -99,7 +106,8 @@ z-proxy = "export ALL_PROXY=socks5://localhost:10808"; zh-proxy = "export HTTPS_PROXY=http://localhost:10808 && export HTTP_PROXY=http://localhost:10808"; nix-dir = "cd ~/.config/nix-on-droid"; - + q-ssh = "sshd-start"; + # beets beet-ima = "beet im ./ -A"; diff --git a/modules/termux/default.nix b/modules/termux/default.nix index 79b8d1e..faed463 100644 --- a/modules/termux/default.nix +++ b/modules/termux/default.nix @@ -1,9 +1,42 @@ { + config, lib, pkgs, ... }: +let + sshdDir = "${config.user.home}/sshd"; + sshdTmpDir = "${config.user.home}/sshd-tmp"; + port = 8022; +in { - # imports = [ - # ]; + # Minimal sshd server for LAN access (e.g. `ssh epral` from other hosts). + # nix-on-droid has no systemd: sshd is started manually via `sshd-start` + # (or from Termux:Boot / a session). The host key is generated once on the + # first activation and kept in ~/sshd (NOT /etc — it is rebuilt on every + # activation). + environment.etc."ssh/sshd_config".text = '' + HostKey ${sshdDir}/ssh_host_ed25519_key + Port ${toString port} + PasswordAuthentication no + AllowUsers ${config.user.userName} + ''; + + # Generate the host key on first activation (idempotent). + build.activation.sshd = '' + if [[ ! -d "${sshdDir}" ]]; then + $DRY_RUN_CMD rm -rf "${sshdTmpDir}" + $DRY_RUN_CMD mkdir -p "${sshdTmpDir}" + $VERBOSE_ECHO "Generating sshd host key..." + $DRY_RUN_CMD ${pkgs.openssh}/bin/ssh-keygen -t ed25519 -f "${sshdTmpDir}/ssh_host_ed25519_key" -N "" + $DRY_RUN_CMD mv "${sshdTmpDir}" "${sshdDir}" + fi + ''; + + environment.packages = [ + (pkgs.writeScriptBin "sshd-start" '' + #!${pkgs.runtimeShell} + exec ${pkgs.openssh}/bin/sshd -f /etc/ssh/sshd_config -D "$@" + '') + ]; }