CCE

CCE in Nix On Droid

Contents

I'd like to get parts of my CCE running on t184256/nix-on-droid so that I can have my Emacs Tools like SRS and org-roam running on it.

nix-on-droid.nix

This uses Arroyo Home Manager to generate a list of Arroyo modules to include in to the Nix On Droid home-manager environment and then does some basic housekeeping stuff to expose Arroyo Emacs and rixpkgs to that environment.

nix:tangle ~/nix/nix-on-droid.nix:noweb yes
{ pkgs, lib, ... }:

{
  environment.packages = with pkgs; [ vim openssh gnugrep findutils diffutils ];
  system.stateVersion = "22.11";

  nix.nixPath = [
    "nixpkgs=/data/data/com.termux.nix/files/home/.nix-defexpr/channels/nixpkgs/"
    "arroyo=/storage/emulated/0/arroyo-nix"
    "/data/data/com.termux.nix/files/home/.nix-defexpr/channels"
  ];
  nix.substituters = [
    "https://cache.nixos.org/"
    "https://nix-community.cachix.org"
  ];
  nix.trustedPublicKeys = [
    "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
    "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
  ];

  nixpkgs.overlays = [
    (let inputs = (builtins.getFlake (toString ~/nix/.)).inputs;
     in inputs.emacs-overlay.overlays.default)
    (import <arroyo/overlay.nix>)
  ];

  home-manager.useGlobalPkgs = true;
  android-integration = {
    termux-open.enable = true;
    termux-open-url.enable = true;
    termux-reload-settings.enable = true;
  };
  terminal = {
    # colors = {
    #   background = "#ffffff";
    #   foreground = "#000000";
    #   cursor = "#888888";
    #   color0 = "#000000";
    #   color1 = "#111111";
    #   color2 = "#222222";
    #   color3 = "#333333";
    #   color4 = "#444444";
    #   color5 = "#555555";
    #   color6 = "#666666";
    #   color7 = "#777777";
    #   color8 = "#888888";
    #   color9 = "#999999";
    #   color10 = "#aaaaaa";
    #   color11 = "#bbbbbb";
    #   color12 = "#cccccc";
    #   color13 = "#dddddd";
    #   color14 = "#eeeeee";
    #   color15 = "#ffffff";
    # };
    font = "${pkgs.terminus_font_ttf}/share/fonts/truetype/TerminusTTF.ttf";
  };

  time.timeZone = "America/Los_Angeles";

  home-manager.config =
    { pkgs, ... }:
    {
      home.stateVersion = "22.05";
      imports = [
        <<home_manager_imports()>>
      ];

      services.emacs.package = pkgs.myEmacs.override { init = <arroyo/files/init.el.droid.el>; };

      programs.ssh.matchBlocks = {
        virtuous-cassette = {
          hostname = "100.116.176.133";
          user = "rrix";
          identitiesOnly = true;
          identityFile = "~/.ssh/id_rsa";
        };

        last-bank = {
          hostname = "100.123.74.28";
          user = "builder";
          identitiesOnly = true;
          identityFile = "~/.ssh/id_rsa";
        };
      };
      # home.file.".termux/termux.properties".source = ./files/termux.properties;
      home.file."bin/termux-url-opener".source = ./files/termux-url-opener;
      home.file."bin/termux-url-opener".executable = true;
    };

}
lua#+name: home_manager_imports:eval arroyo:results raw
local modules = arroyo.home_modules("droid")
return table.concat(modules, "\n")
hm/emacs.nix
hm/arcology-localapi.nix
hm/emacs-helpers.nix
hm/morph.nix
hm/profile.nix
hm/contacts.nix
hm/kicad.nix
hm/deadgrep.nix
hm/shell-helpers.nix
hm/gnupg.nix
hm/emacs-pager.nix
hm/direnv.nix
hm/prompt.nix
hm/org-roam.nix
hm/org-fc.nix
hm/spell-check.nix
hm/git.nix
hm/nix-update.nix
hm/ssh_client.nix
hm/python.nix
hm/plasma-manager.nix

Termux Configuration

Termux app properties should be set on the Cosmo and other devices with a hardware keyboard:

conf:tangle ~/nix/files/termux.properties:comments none
# extra-keys-style = none doesn't work...
extra-keys = [ \
  [ \
  {key: 'TAB', popup: {macro: "CTRL x b", display: "alttab"}}, \
  {key: '/', popup: {macro: "SPACE r f", display: "find node"}}, \
  {key: '\\\\', popup: {macro: "ALT .", display: "insert link"}}, \
  {key: '[', popup: {macro: "SPACE r d p", display: "prev note"}}, \
  {key: ']', popup: {macro: "SPACE r d n", display: "next note"}}, \
  {key: '$', popup: {macro: "SPACE r d d", display: "journal"}}, \
  {key: '~', popup: {macro: "CTRL x CTRL b", display: "ibuffer"}}, \
  {key: 'UP', popup: {macro: "CTRL c c j j", display: "new note"}}, \
  {key: '`', popup: {macro: "CTRL c CTRL k", display: "cancel"}} \
  ], \
  [ \
  {key: 'ESC', popup: {macro: "CTRL g", display: "Quit"}}, \
  {key: 'CTRL', popup: {macro: "CTRL c", display: "C-c"}}, \
  {key: 'ALT', popup: {macro: "ALT x", display: "M-x"}}, \
  {key: '{', popup: {macro: "CTRL x r b", display: "bookmarks"}}, \
  {key: '}', popup: {macro: "CTRL x r m", display: "bookmark"}}, \
  {key: '%', popup: {macro: "CTRL x k", display: "kill buff"}}, \
  {key: 'LEFT', popup: {macro: "CTRL x 1", display: "maximize"}}, \
  {key: 'DOWN', popup: {macro: "CTRL c CTRL c", display: "commit"}}, \
  {key: 'RIGHT', popup: {macro: "CTRL x o", display: "other win"}} \
]]
back-key = escape
ctrl-space-workaround = true

Share URLs with Nix via android share sheet to save them to org-roam with this:

shell:tangle ~/nix/files/termux-url-opener:shebang #!/usr/bin/env
urlencode() {
    local string="$1"
    local length="${#string}"
    local encoded=""
    local pos c o

    for ((pos=0; pos<length; pos++)); do
        c="${string:$pos:1}"
        case "$c" in
            [a-zA-Z0-9.~_-]) 
                encoded+="$c" 
                ;;
            ,*) 
                printf -v o '%%%02X' "'$c"
                encoded+="$o"
                ;;
        esac
    done
    
    echo "$encoded"
}
encoded_url=$(urlencode "$1")

echo "Page title? "
read title
emacsclient -tc "org-protocol://roam-ref?template=r&ref=$encoded_url&title=$title"

INPROGRESS Emacs Init for minimal Org-Roam on Nix on Droid

lua:eval arroyo:results raw
local snippets = arroyo.emacs_snippets()
return table.concat(snippets, "\n")

Using machines running My NixOS configuration to as builders for nix-on-droid

Based on the Nix On Droid wiki examples:

Virtuous Cassette is set up with a builder user and aarch64 binfmt emulation:

nix:tangle ~/nix/nixos/nixos-builder.nix
{ ... }:

{
  boot.binfmt.emulatedSystems = [ "aarch64-linux" ];
  users.users.builder = {
    createHome = true;
    isNormalUser = true;
    initialPassword = "changeme!";
  };

  nix.settings.trusted-users = [ "builder" ];
}

Bootstrapping the build setup

On the droid side, it's configured to use this as the builder and SSH to the host over Tailscale:

nix.conf:

conf
builders-use-substitutes = true
builders = ssh://builder@virtuous-cassette;ssh://builder@window-smoke

.ssh/config

conf
Host virtuous-cassette
    HostName 100.96.6.32
    User builder
    IdentitiesOnly yes
    IdentityFile ~/.ssh/id_rsa

Host window-smoke
    HostName 100.79.48.59
    User builder
    IdentitiesOnly yes
    IdentityFile ~/.ssh/id_rsa
  • set up ssh: nix-shell -p openssh git then ssh-keygen then ssh-copy-id builder; git is used in nix-on-droid build

  • set up directories: ln -s /storage/emulated/0/org ~/org then ln -s /storage/emulated/0/arroyo-nix ~/arroyo-nix

  • install home-manager channel (only used for bootstrap, subsequent builds will use Nix Version Pins)

  • then finally =nix-on-droid build -f ~/arroyo-nix/nix-on-droid.nix -I arroyo=$HOME/arroyo-nix=