From 4c4bd9e99706d45dcf220f1df2d65e31f63a0e06 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sun, 14 Aug 2022 10:46:55 +0000 Subject: [PATCH] make an installable derivation untested as yet --- .gitignore | 3 +++ README.md | 61 +++++++++++++++++++++++++--------------------------- bin/eufon.sh | 2 ++ default.nix | 15 ++++++++++++- module.nix | 14 +++++++++--- 5 files changed, 59 insertions(+), 36 deletions(-) create mode 100644 .gitignore create mode 100755 bin/eufon.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6b96928 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*~ +result* +*.img diff --git a/README.md b/README.md index 4656ea0..91876c0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ **Broken, not ready for use** -> *euphony*: _noun_ Harmonious aqrrangement of sounds in composition; a smooth and agreeable combination of articulate elements in any piece of writing. +> *euphony*: _noun_ Harmonious arrangement of sounds in composition; a smooth and agreeable combination of articulate elements in any piece of writing. A mostly Fennel-based graphical environment tailored for Linux-based mobile devices. The principles we aspire to are @@ -19,35 +19,12 @@ mobile devices. The principles we aspire to are As of 2022 these principles are more aspirational than actual. _This repo is basically in an advanced state of brokenness_ -## Building for a device - -To build an image, unpack [Mobile NixOS](https://github.com/NixOS/mobile-nixos/) in a sibling directory -of this repo (so that `../mobile-nixos` addresses it) and then do -something like this (substituing an appropriate device name for -`motorola-potter`) - - $ nix-build ../mobile-nixos/ -I mobile-nixos-configuration=./configuration.nix --argstr device motorola-potter -A build.default - -You are warmly encouraged to refer to the [Mobile Nixos -docs](https://mobile.nixos.org/devices/) for how to use this image. - -Once you have your device up and running and you can ssh into it -somehow (this may take further research, again I invite you to look at -the Mobile Nixos site) then you should be able to use -`nix-copy-closure` to update it without reinstalling. - - $ phone=myphone.lan - $ nix-build ../mobile-nixos/ -I mobile-nixos-configuration=./configuration.nix --argstr device motorola-potter -A config.system.build.toplevel - $ nix-copy-closure --to root@${phone} --include-outputs \ - ./result && ssh root@${phone} \ - `readlink result`/bin/switch-to-configuration switch - - ## Running the shell/apps locally -You may prefer to develop on a desktop device of some kind, especially -if you're changing C code and have that edit/compile run cycle to go -round. You can start the shell locally with +Eufon is intendfed for phones, but you may prefer to develop on a +desktop device of some kind, especially if you're changing C code and +have that edit/compile run cycle to go round. You can start the shell +locally with $ nix-shell --run "kiwmi -c init.lua" @@ -58,11 +35,31 @@ for the Lua interpreter itself, but it doesn't do the same for kiwmi. ## Connecting to the repl -If you are using the example rc.fnl, it opens a Unix socket that you -can connect to and interact with a Fennel REPL. I use -[socat](http://www.dest-unreach.org/socat/) for this purpose: +If you are using the example rc.fnl, it opens a Unix socket to which +you can connect to interact with a Fennel REPL. The `eufonctl` +script is a wrapper around [socat](http://www.dest-unreach.org/socat/) + + $ eufonctl $WAYLAND_DISPLAY + + +## Building for a device + +Eufon can be installed as a [Mobile NixOS](https://github.com/NixOS/mobile-nixos/) module, by adding +`module.nix` to the `imports` in `your configuration.nix`. For example, on my development phone I +have + +```nix + imports = [ + (import { + device = "motorola-potter"; + }) + /home/dan/src/phoen/eufon/module.nix + ]; +``` + +Instructions for using Mobile NixOS are currently outside the scope of +this README. - $ socat - unix-connect:${XDG_RUNTIME_DIR}/kiwmi-repl.wayland-1.socket # TODO diff --git a/bin/eufon.sh b/bin/eufon.sh new file mode 100755 index 0000000..01da16f --- /dev/null +++ b/bin/eufon.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +kiwmi -V -V -c init.lua diff --git a/default.nix b/default.nix index 38e092b..d76c728 100644 --- a/default.nix +++ b/default.nix @@ -11,6 +11,9 @@ , gtk-layer-shell , lua5_3 , socat +, cpio + +, makeWrapper } : let lua = lua5_3; @@ -63,11 +66,21 @@ stdenv.mkDerivation { gtk3 webkitgtk ]; + nativeBuildInputs = [ cpio makeWrapper ]; installPhase = '' + export LUA_PATH="`lua -e 'print(package.path)'`" + export LUA_CPATH="`lua -e 'print(package.cpath)'`" mkdir -p $out/bin - substitute bin/eufon.sh $out/bin/eufon \ + find . -name kiwmi -prune -o -type l -prune -o -print0 | cpio -0 -v --pass-through $out + substitute bin/eufonctl.sh $out/bin/eufonctl \ --replace SOCAT=socat SOCAT=${socat}/bin/socat + makeWrapper ${kiwmi}/bin/kiwmi $out/bin/eufon \ + --set LUA_PATH ".;$out/?.fnl;$LUA_PATH" \ + --set LUA_CPATH ".;$out/?.so;$LUA_CPATH" \ + --prefix PATH : ${kiwmi}/bin \ + --add-flags "-c $out/init.lua" + chmod +x $out/bin/eufon ''; diff --git a/module.nix b/module.nix index ed729e1..866f111 100644 --- a/module.nix +++ b/module.nix @@ -1,4 +1,5 @@ { config, lib, pkgs, ... }: +let eufon = pkgs.callPckage ./default.nix; in { systemd.services."eufon" = { wants = [ @@ -19,6 +20,7 @@ "systemd-udev-settle.service" ]; conflicts = [ + "getty@tty1.service" # not sure if needed "getty@tty2.service" "plymouth-quit.service" ]; @@ -27,11 +29,11 @@ let run-eufon = pkgs.writeScript "run-eufon" '' #!${pkgs.bash}/bin/bash source ${config.system.build.setEnvironment} - ${pkgs.dbus}/bin/dbus-run-session /home/dan/src/eufon/run.sh + ${pkgs.dbus}/bin/dbus-run-session ${eufon}/bin/eufon systemd-cat echo "dbus-run-session $?" ''; in { - WorkingDirectory = "/home/dan/src/eufon"; + WorkingDirectory = "${eufon}"; TTYPath = "/dev/tty2"; TTYReset = "yes"; TTYVHangup = "yes"; @@ -52,7 +54,13 @@ environment.systemPackages = with pkgs; [ git ]; - networking.networkmanager.enable = true; + + boot.postBootCommands = lib.mkOrder (-1) '' + brightness=4000 + echo "Setting brightness to $brightness" + echo $brightness > /sys/class/backlight/wled/brightness + ''; + services.logind.extraConfig = '' HandlePowerKey=ignore '';