1
1
mirror of https://github.com/NixOS/mobile-nixos.git synced 2024-12-13 12:35:48 +03:00

Merge pull request #86 from samueldr-wip/feature/boot-gui/simulator-fixes

Boot GUI: Simulator fixes
This commit is contained in:
Samuel Dionne-Riel 2020-03-02 14:04:10 -05:00 committed by GitHub
commit e121b722a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 156 additions and 53 deletions

View File

@ -10,6 +10,9 @@ REFRESH_RATE = 120
NIXOS_LIGHT_HUE = 205
NIXOS_DARK_HUE = 220
# File with boot selection
SELECTIONS = "/run/boot/selection.json"
# Define the arguments
Args.define({
resolution: nil,
@ -22,8 +25,8 @@ if Args.get(:resolution)
$stderr.puts "--resolution <width>x<height>"
exit 2
end
LVGL::Hacks.monitor_width = ARGV.first.to_i
LVGL::Hacks.monitor_height = ARGV.last.to_i
LVGL::Hacks.monitor_width = pair.first.to_i
LVGL::Hacks.monitor_height = pair.last.to_i
else
LVGL::Hacks.monitor_width = 720
LVGL::Hacks.monitor_height = 1280
@ -79,7 +82,12 @@ class Clock < Widget
end
def update_clock()
set_text(Time.now.strftime("%T"))
now = Time.now
set_text([
:hour,
:min,
:sec,
].map{|fn| now.send(fn).to_s.rjust(2, "0") }.join(":"))
end
end
@ -233,9 +241,7 @@ ui = UI.new
def run(*cmd)
$stderr.puts " $ " + cmd.join(" ")
# TODO: better introspection to allow the app to know it is running in a
# simulated environment, and dry-run in simulator.
system(*cmd)
system(*cmd) unless LVGL::Hacks.simulator?
end
# TODO: wait ~0.3s for the animation before doing the button actions.
@ -281,15 +287,17 @@ end
# Generations tab
JSON.parse(File.read("/run/boot/selection.json")).each do |selection|
ui.button(selection["name"], page: :generations).tap do |btn|
btn.event_handler = ->(event) do
case event
when LVGL::EVENT::CLICKED
File.write("/run/boot/choice", selection["id"])
exit 0
end
end
if File.exist?(SELECTIONS)
JSON.parse(File.read(SELECTIONS)).each do |selection|
ui.button(selection["name"], page: :generations).tap do |btn|
btn.event_handler = ->(event) do
case event
when LVGL::EVENT::CLICKED
File.write("/run/boot/choice", selection["id"])
exit 0
end
end
end
end
end

46
boot/gui/simulator.nix Normal file
View File

@ -0,0 +1,46 @@
{ stdenv
, lib
, callPackage
, mrbgems
}:
let
loader = callPackage ../script-loader {
mrbgems = mrbgems // {
mruby-lvgui = callPackage ../../overlay/mruby-builder/mrbgems/mruby-lvgui {
withSimulator = true;
};
};
};
in
stdenv.mkDerivation {
pname = "boot-gui-simulator";
version = "0.0.1";
src = lib.cleanSource ./.;
nativeBuildInputs = [
loader.mruby
];
buildPhase = ''
(PS4=" $ "; set -x
mrbc -o gui.mrb \
lib/*.rb main.rb
)
'';
installPhase = ''
(PS4=" $ "; set -x
mkdir -p $out/libexec/
cp -v gui.mrb $out/libexec/gui.mrb
mkdir -p $out/bin
cat > $out/bin/simulator <<EOF
#!/bin/sh
${loader}/bin/loader $out/libexec/gui.mrb "\$@"
EOF
chmod +x $out/bin/simulator
)
'';
}

View File

@ -1,6 +1,8 @@
{ fetchurl
, mruby
{ stdenv
, fetchurl
, mrbgems
, mruby
, script-loader
# Additional tasks
, tasks ? []
@ -14,20 +16,24 @@ let
sha256 = "197g7qvrrijmajixa2h9c4jw26l36y8ig6qjb5d43qg4qykhqfcx";
};
in
mruby.builder {
stdenv.mkDerivation {
pname = "mobile-nixos-init";
version = "0.1.0";
src = ./.;
nativeBuildInputs = [
mruby
];
postPatch = ''
cp ${shellwords} lib/0001_shellwords.rb
'';
# Sorting ensures a stable lexicographic import order.
# Otherwise the compiler could accidentally be flaky.
buildPhase = ''
get_tasks() {
# Sorting ensures a stable lexicographic import order.
# Otherwise the compiler could accidentally be flaky.
for s in $tasks; do
find $s -type f -iname '*.rb'
done | sort
@ -38,36 +44,14 @@ mruby.builder {
$(find lib -type f | sort) \
$(get_tasks) \
init.rb
mkdir -p $out/libexec
cp init.mrb $out/libexec/init.mrb
'';
# We're building a script loader here.
makeBin loader \
main.rb
installPhase = ''
mkdir -p $out
install -D -t $out/libexec/ init.mrb
'';
tasks = [
"./tasks"
] ++ tasks;
gems = with mrbgems; [
{ core = "mruby-exit"; }
{ core = "mruby-io"; }
{ core = "mruby-sleep"; }
{ core = "mruby-time"; }
mruby-dir
mruby-dir-glob
mruby-env
mruby-file-stat
mruby-json
mruby-logger
mruby-lvgui
mruby-open3
mruby-regexp-pcre
mruby-singleton
mruby-time-strftime
# This needs to be the last gem
mruby-require
];
}

View File

@ -0,0 +1,39 @@
{ fetchurl
, mruby
, mrbgems
}:
mruby.builder {
pname = "mobile-nixos-script-loader";
version = "0.2.0";
src = ./.;
# `main.rb` is where the magic happens.
buildPhase = ''
makeBin loader main.rb
'';
# This script loader handles all "applets" and scripts that will run during
# stage-1.
gems = with mrbgems; [
{ core = "mruby-exit"; }
{ core = "mruby-io"; }
{ core = "mruby-sleep"; }
{ core = "mruby-time"; }
mruby-dir
mruby-dir-glob
mruby-env
mruby-file-stat
mruby-json
mruby-logger
mruby-lvgui
mruby-open3
mruby-regexp-pcre
mruby-singleton
mruby-time-strftime
# This needs to be the last gem
mruby-require
];
}

View File

@ -41,8 +41,8 @@ When the device is not a _"Boot as recovery"_, or still uses a recovery
partition, you will need to flash a recovery image to the recovery partition.
....
nix-build --argstr device $DEVICE -A build.android-recovery
fastboot flash recovery result
$ nix-build --argstr device $DEVICE -A build.android-recovery
$ fastboot flash recovery result
....
=== All other devices
@ -60,3 +60,11 @@ keys are held, it will instead show the recovery menu.
* Right control
* Escape
== Testing the boot GUI
The simulator can be launched using the following commands:
....
$ nix-build --argstr device qemu-x86_64 -A pkgs.boot-gui-simulator
$ result/bin/simulator --resolution 1080x1920
....

View File

@ -41,7 +41,7 @@ let
inherit (config.mobile.boot.stage-1) earlyInitScripts;
# The script loader
loader = "${mobile-nixos-init}/bin/loader";
loader = "${mobile-nixos-script-loader}/bin/loader";
# The init "script"
initScript = "${mobile-nixos-init}/libexec/init.mrb";
@ -59,7 +59,9 @@ let
stage-1 = config.mobile.boot.stage-1;
mobile-nixos-script-loader = pkgs.pkgsStatic.callPackage ../boot/script-loader {};
mobile-nixos-init = pkgs.pkgsStatic.callPackage ../boot/init {
script-loader = mobile-nixos-script-loader;
inherit (config.mobile.boot.stage-1) tasks;
};

View File

@ -17,8 +17,8 @@ mrbgems.mkGem {
src = fetchFromGitHub {
repo = "mruby-lvgui";
owner = "mobile-nixos";
rev = "d281e8b59f7e70709b7cbb993a84148eaa415302";
sha256 = "1ial5lhwl5izn65i5ycpkz3vkmzfmf72w7rx8xb337qnarh4k60z";
rev = "1c251ec97da1e4d3e99f0b9674b387c990211906";
sha256 = "03bhksn2rzixxl8dk7viw2avw5cv4zpfpkcijrxjy4cc76f1wkja";
};
gemBuildInputs = [

View File

@ -3,7 +3,6 @@
, fetchFromGitHub
, pkg-config
, libevdev
, nix-gitignore
, SDL2
, withSimulator ? false
}:
@ -18,7 +17,6 @@ in
pname = "mobile-nixos-early-boot-gui";
version = "2020-02-05";
#src = nix-gitignore.gitignoreSource [] ./.;
src = fetchFromGitHub {
fetchSubmodules = true;
repo = "lvgui";
@ -27,6 +25,13 @@ in
sha256 = "1vdahc0lymzprnlckdxcba9p78gqymvsy3bhmyqzjx68r8xcd985";
};
# Document `LVGL_ENV_SIMULATOR` in the built headers.
# This allows the mrbgem to know about it.
# (In reality this should be part of a ./configure step or something similar.)
postPatch = ''
sed -i"" '/^#define LV_CONF_H/a #define LVGL_ENV_SIMULATOR ${if withSimulator then "1" else "0"}' lv_conf.h
'';
nativeBuildInputs = [
pkg-config
];

View File

@ -96,5 +96,9 @@ in
runHook postBuild
'';
passthru = {
inherit mruby;
};
installPhase = ":";
})

View File

@ -60,6 +60,13 @@ in
hardshutdown = callPackage ./hardshutdown {};
bootlogd = callPackage ./bootlogd {};
#
# Mobile NixOS only stuff
# -----------------------
#
boot-gui-simulator = callPackage ../boot/gui/simulator.nix {};
#
# Hacks
# -----