feat(droid): add nix-on-droid support and vega host

This commit is contained in:
tux
2026-08-11 18:59:16 +05:30
parent 0f842359b3
commit 93dcaeb05e
8 changed files with 406 additions and 0 deletions

32
modules/droid/core/hm.nix Normal file
View File

@@ -0,0 +1,32 @@
{ inputs, config, ... }:
{
flake.modules.droid.core =
{
hostName,
userName,
userEmail,
...
}:
{
home-manager = {
backupFileExtension = "bak";
useGlobalPkgs = true;
useUserPackages = true;
extraSpecialArgs = {
inherit
inputs
hostName
userName
userEmail
;
};
config = {
imports = [
config.flake.modules.homeManager.shell
config.flake.modules.homeManager.${hostName}
];
};
};
};
}

View File

@@ -0,0 +1,7 @@
{
flake.modules.droid.core = {
nix.extraOptions = ''
experimental-features = nix-command flakes
'';
};
}

View File

@@ -0,0 +1,109 @@
{
flake.modules.droid.networking =
{
config,
lib,
pkgs,
...
}:
let
# utility functions
concatLines = list: builtins.concatStringsSep "\n" list;
prefixLines = mapper: list: concatLines (map mapper list);
# could be put in the config
configPath = "ssh/sshd_config";
keysFolder = "/etc/ssh";
authorizedKeysFolder = "/etc/ssh/authorized_keys.d";
supportedKeysTypes = [
"rsa"
"ed25519"
];
sshd-start-bin = "sshd-start";
# real config
cfg = config.tnix.networking.openssh;
pathOfKeyOf = type: "${keysFolder}/ssh_host_${type}_key";
generateKeyOf = type: ''
${lib.getExe' pkgs.openssh "ssh-keygen"} \
-t "${type}" \
-f "${pathOfKeyOf type}" \
-N ""
'';
generateKeyWhenNeededOf = type: ''
if [ ! -f ${pathOfKeyOf type} ]; then
mkdir --parents ${keysFolder}
${generateKeyOf type}
fi
'';
sshd-start = pkgs.writeScriptBin sshd-start-bin ''
#!${pkgs.runtimeShell}
${prefixLines generateKeyWhenNeededOf supportedKeysTypes}
mkdir --parents "${authorizedKeysFolder}"
echo "${lib.concatStringsSep "\n" cfg.authorizedKeys}" > ${authorizedKeysFolder}/${config.user.userName}
echo "Starting sshd in non-daemonized way on port ${lib.concatMapStrings toString cfg.ports}"
${lib.getExe' pkgs.openssh "sshd"} \
-f "/etc/${configPath}" \
-D # don't detach into a daemon process
'';
in
{
options.tnix.networking.openssh = {
enable = lib.mkEnableOption ''
Whether to enable the OpenSSH secure shell daemon, which
allows secure remote logins.
'';
ports = lib.mkOption {
type = lib.types.listOf lib.types.port;
default = [ 22 ];
description = ''
Specifies on which ports the SSH daemon listens.
'';
};
authorizedKeys = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
description = ''
Specify a list of public keys to be added to the authorized_keys file.
'';
};
};
config = lib.mkIf cfg.enable {
environment.etc = {
"${configPath}".text = ''
${prefixLines (port: "Port ${toString port}") cfg.ports}
AuthorizedKeysFile ${authorizedKeysFolder}/%u
LogLevel VERBOSE
'';
};
environment.packages = [
sshd-start
pkgs.openssh
];
build.activationAfter.sshd = ''
SERVER_PID=$(${lib.getExe' pkgs.procps "ps"} -a | ${lib.getExe' pkgs.toybox "grep"} sshd || true)
if [ -z "$SERVER_PID" ]; then
$DRY_RUN_CMD ${lib.getExe sshd-start}
fi
'';
};
};
}

View File

@@ -0,0 +1,48 @@
{
flake.modules.droid.vega =
{
pkgs,
userEmail,
...
}:
{
# @TODO: Broken currently
# android-integration.am.enable = true;
# android-integration.termux-open-url.enable = true;
# android-integration.xdg-open.enable = true;
# android-integration.termux-setup-storage.enable = true;
# android-integration.termux-reload-settings.enable = true;
terminal.font =
let
firacode = pkgs.nerd-fonts.fira-code;
fontPath = "share/fonts/truetype/NerdFonts/FiraCode/FiraCodeNerdFont-Regular.ttf";
in
"${firacode}/${fontPath}";
time.timeZone = "Asia/Kolkata";
tnix.networking.openssh = {
enable = true;
ports = [ 8033 ];
authorizedKeys = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIL+OzPUe2ECPC929DqpkM39tl/vdNAXfsRnmrGfR+X3D ${userEmail}"
];
};
user = {
uid = 10481;
gid = 10481;
shell = "${pkgs.zsh}/bin/zsh";
};
environment.etcBackupExtension = ".backup";
environment.motd = "";
environment.packages = with pkgs; [
openssh
rsync
];
system.stateVersion = "24.05";
};
}

View File

@@ -0,0 +1,41 @@
{
inputs,
outputs,
config,
...
}:
let
hostName = "vega";
userName = "nix-on-droid";
userEmail = "t@tux.rs";
system = "aarch64-linux";
unstable = true;
nixpkgs = if unstable then inputs.nixpkgs else inputs.nixpkgs-stable;
in
{
flake.nixOnDroidConfigurations."${hostName}" = inputs.nix-on-droid.lib.nixOnDroidConfiguration {
pkgs = import nixpkgs {
system = system;
config = {
allowUnfree = true;
joypixels.acceptLicense = true;
};
overlays = builtins.attrValues inputs.self.overlays;
};
extraSpecialArgs = {
inherit
inputs
outputs
hostName
userName
userEmail
;
};
modules = [
config.flake.modules.droid.core
config.flake.modules.droid.networking
config.flake.modules.droid.${hostName}
];
};
}

View File

@@ -0,0 +1,9 @@
{ lib, ... }:
{
flake.modules.homeManager.vega = {
# @TODO: Broken currently - By default it's enabled by neovim module
programs.vim.enable = lib.mkForce false;
home.stateVersion = "26.05";
};
}