sshd setup for termux

This commit is contained in:
2026-08-07 01:38:46 +03:00
parent af90756661
commit bc9b2dc792
3 changed files with 55 additions and 9 deletions
+5
View File
@@ -31,6 +31,11 @@ let
# (default is bashInteractive) # (default is bashInteractive)
user.shell = "${pkgs.zsh}/bin/zsh"; 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: # Minimal termux settings (nix-on-droid options only:
# environment.*, nix.*, time.*, user.*, system.*, android-integration.*) # environment.*, nix.*, time.*, user.*, system.*, android-integration.*)
+15 -7
View File
@@ -51,11 +51,18 @@
TUCKR_HOME = "$HOME/Storage/dotfiles"; TUCKR_HOME = "$HOME/Storage/dotfiles";
EDITOR = "fresh"; EDITOR = "fresh";
}; };
file.".nanorc".text = '' file = {
set nowrap ".nanorc".text = ''
set tabstospaces set nowrap
set tabsize 2 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 = { programs = {
# ---- Shell: zsh ---- # ---- Shell: zsh ----
@@ -68,7 +75,7 @@
enable = true; enable = true;
theme = "robbyrussell"; theme = "robbyrussell";
}; };
loginExtra = "clear && fastfetch"; loginExtra = "clear && fastfetch && cd ~/.config/nix-on-droid";
initContent = '' initContent = ''
beet-p() { beet-p() {
local base="${config.home.homeDirectory}/.config/beets/My" local base="${config.home.homeDirectory}/.config/beets/My"
@@ -99,7 +106,8 @@
z-proxy = "export ALL_PROXY=socks5://localhost:10808"; z-proxy = "export ALL_PROXY=socks5://localhost:10808";
zh-proxy = "export HTTPS_PROXY=http://localhost:10808 && export HTTP_PROXY=http://localhost:10808"; zh-proxy = "export HTTPS_PROXY=http://localhost:10808 && export HTTP_PROXY=http://localhost:10808";
nix-dir = "cd ~/.config/nix-on-droid"; nix-dir = "cd ~/.config/nix-on-droid";
q-ssh = "sshd-start";
# beets # beets
beet-ima = "beet im ./ -A"; beet-ima = "beet im ./ -A";
+35 -2
View File
@@ -1,9 +1,42 @@
{ {
config,
lib, lib,
pkgs, 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 "$@"
'')
];
} }