Compare commits

...

5 Commits

Author SHA1 Message Date
Daniel Barlow 70da3a582d some generally (I hope) useful config for the Pinephone 2022-07-03 14:11:51 +01:00
Daniel Barlow 6d4dfbe029 nixos module to start kiwmi at boot
this is here for my convenience, I make no claims of practicality
or beauty (it uses nix-shell and hardcodes pathnames)
2022-07-03 14:11:41 +01:00
Daniel Barlow a8f7448245 only resize output when using wayland backend
surprisingly enough, real hardware complains
2022-07-03 14:11:24 +01:00
Daniel Barlow b04c91c897 use output width/height instead of hardcoding 2022-07-03 14:09:24 +01:00
Daniel Barlow ff4d5e1414 add some matrix functions 2022-07-03 14:03:35 +01:00
7 changed files with 240 additions and 14 deletions

55
matrix.fnl Normal file
View File

@ -0,0 +1,55 @@
;; homogeneous matrix operations for 2d graphics
(local identity
[
1 0 0
0 1 0
0 0 1
])
(fn multiply-matrix [a b]
[
(+ (* (. a 1) (. b 1)) (* (. a 2) (. b 4)) (* (. a 3) (. b 7)))
(+ (* (. a 1) (. b 2)) (* (. a 2) (. b 5)) (* (. a 3) (. b 8)))
(+ (* (. a 1) (. b 3)) (* (. a 2) (. b 6)) (* (. a 3) (. b 9)))
(+ (* (. a 4) (. b 1)) (* (. a 5) (. b 4)) (* (. a 6) (. b 7)))
(+ (* (. a 4) (. b 2)) (* (. a 5) (. b 5)) (* (. a 6) (. b 8)))
(+ (* (. a 4) (. b 3)) (* (. a 5) (. b 6)) (* (. a 6) (. b 9)))
(+ (* (. a 7) (. b 1)) (* (. a 8) (. b 4)) (* (. a 9) (. b 7)))
(+ (* (. a 7) (. b 2)) (* (. a 8) (. b 5)) (* (. a 9) (. b 8)))
(+ (* (. a 7) (. b 3)) (* (. a 8) (. b 6)) (* (. a 9) (. b 9)))
])
(fn scale [matrix x y]
(let [scale [
x 0 0
0 y 0
0 0 1]]
(multiply-matrix matrix scale)))
(fn translate [matrix x y]
(let [translation [
1 0 x
0 1 y
0 0 1]]
(multiply-matrix matrix translation)))
(fn rotate [matrix rad]
(let [sin (math.sin rad)
cos (math.cos rad)
rotation [
cos (- sin) 0
sin cos 0
0 0 1
]]
(multiply-matrix matrix rotation)))
{
: identity
: scale
: translate
: rotate
}

58
module.nix Normal file
View File

@ -0,0 +1,58 @@
{ config, lib, pkgs, ... }:
{
systemd.services."eufon" = {
wants = [
"systemd-machined.service"
"accounts-daemon.service"
"systemd-udev-settle.service"
"dbus.socket"
];
aliases = [ "display-manager.service" ];
after = [
"rc-local.service"
"systemd-machined.service"
"systemd-user-sessions.service"
"getty@tty2.service"
"plymouth-quit.service"
"plymouth-start.service"
"systemd-logind.service"
"systemd-udev-settle.service"
];
conflicts = [
"getty@tty2.service"
"plymouth-quit.service"
];
wantedBy = [ "multi-user.target" ];
serviceConfig =
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
systemd-cat echo "dbus-run-session $?"
'';
in {
WorkingDirectory = "/home/dan/src/eufon";
TTYPath = "/dev/tty2";
TTYReset = "yes";
TTYVHangup = "yes";
TTYVTDisallocate = "yes";
PAMName = "login";
StandardInput = "tty";
StandardError = "journal";
StandardOutput = "journal";
User = "dan";
ExecStart = run-eufon;
Restart = "always";
};
environment = {
NIX_PATH = "nixpkgs=${<nixpkgs>}";
};
};
environment.systemPackages = with pkgs; [
git
];
networking.networkmanager.enable = true;
services.logind.extraConfig = ''
HandlePowerKey=ignore
'';
}

59
pinephone.nix Normal file
View File

@ -0,0 +1,59 @@
{ config, lib, pkgs, ... }:
# configuration.nix contains settings applicable to _my_ pinephone
# pinephone.nix contains settings applicable to eufon on pinephones.
# module.nix contains settings applicable to eufon generally
{
config = {
powerManagement = {
enable = true;
cpuFreqGovernor = "ondemand";
};
mobile.boot.stage-1.firmware = [
config.mobile.device.firmware
];
hardware.sensor.iio.enable = true;
hardware.firmware = [ config.mobile.device.firmware ];
services.fwupd = {
enable = true;
};
environment.systemPackages =
let refresh-bootfs = (import ./refresh-bootfs.nix { inherit config pkgs lib; });
in with pkgs; [
dtc
file
refresh-bootfs
];
environment.etc."fwupd/remotes.d/testing.conf" = {
mode = "0644";
text = ''
[fwupd Remote]
Enabled=true
Title=Linux Vendor Firmware Service (testing)
MetadataURI=https://cdn.fwupd.org/downloads/firmware-testing.xml.gz
ReportURI=https://fwupd.org/lvfs/firmware/report
OrderBefore=lvfs,fwupd
AutomaticReports=false
ApprovalRequired=false
'';
};
nixpkgs = {
config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
"pine64-pinephone-firmware"
];
};
# boot.loader.generic-extlinux-compatible.enable = lib.mkForce true;
hardware.opengl = {
enable = true;
driSupport = true;
};
};
}

31
rc.fnl
View File

@ -1,6 +1,7 @@
(local { : view } (require :fennel))
(local texture (require :texture))
(local matrix (require :matrix))
(local socket-repl (require :socket-repl))
(let [repl-socket-name
@ -12,37 +13,39 @@
)]
(socket-repl.start repl-socket-name))
(fn resize-wayland-backend [output]
(when (string.find (output:name) "^WL-")
(output:set_mode 360 720 0)))
(kiwmi:on
"output"
(fn [output]
(output:set_mode 360 720 0)
(let [r (output:renderer)
(resize-wayland-backend output)
(let [[width height] (output:size)
r (output:renderer)
kill (texture.from-file r "close-window.png")
launch (texture.from-file r "launcher.png")
spinner (texture.from-file r "carousel.png")]
(output:on "render"
(fn [{: output : renderer}]
(let [bar-height 40
matrix [1 0 0
0 1 0
0 0 1]]
(let [bar-height (/ height 15)]
(renderer:draw_rect :#00000077
0 (- 720 bar-height)
690 360 bar-height)
0 (- height bar-height)
width bar-height)
(renderer:draw_texture
kill
matrix
30 (- 720 bar-height)
matrix.identity
30 (- height bar-height)
0.7)
(renderer:draw_texture
launch matrix
(- 180 (/ bar-height 2)) (- 720 bar-height)
launch
matrix.identity
(- (/ width 2) (/ bar-height 2)) (- height bar-height)
0.7)
(renderer:draw_texture
spinner
matrix
(- 360 30 bar-height) (- 720 bar-height)
matrix.identity
(- width 30 bar-height) (- height bar-height)
0.7)))))))
(fn kill-window []

43
refresh-bootfs.nix Normal file
View File

@ -0,0 +1,43 @@
{ config, pkgs, lib, ... }:
# nixos/mobile-nixos don't currently (June 2022) update the kernel and
# initrd used by the bootloader when nixos-rebuild is run. This is a
# workaround until they do. Mount your boot filesystem somewhere
# and run "refresh-bootfs /path/to/mounted/bootfs" after switching
# configuration
let
inherit (config.mobile.outputs) recovery stage-0;
inherit (pkgs) writeScriptBin buildPackages imageBuilder runCommandNoCC;
kernel = stage-0.mobile.boot.stage-1.kernel.package;
kernel_file = "${kernel}/${if kernel ? file then kernel.file else pkgs.stdenv.hostPlatform.linux-kernel.target}";
# bootscr = runCommandNoCC "boot.scr" {
# nativeBuildInputs = [
# buildPackages.ubootTools
# ];
# } ''
# mkimage -C none -A arm64 -T script -d {bootcmd} $out
# '';
in writeScriptBin "refresh-bootfs" ''
#!${pkgs.runtimeShell}
test -n "$1" || exit 1
test -d "$1" || exit 1
cd $1
test -f ./boot.scr || exit 1
mkdir -vp mobile-nixos/{boot,recovery}
(
cd mobile-nixos/boot
cp -v ${stage-0.mobile.outputs.initrd} stage-1
cp -v ${kernel_file} kernel
cp -vr ${kernel}/dtbs dtbs
)
(
cd mobile-nixos/recovery
cp -v ${recovery.mobile.outputs.initrd} stage-1
cp -v ${kernel_file} kernel
cp -vr ${kernel}/dtbs dtbs
)
# cp -v {bootscr} ./boot.scr
''

2
run.sh Normal file
View File

@ -0,0 +1,2 @@
#!/usr/bin/env bash
nix-shell --run "start_eufon"

View File

@ -5,5 +5,11 @@ in (p.overrideAttrs (o:{
shellHook = ''
export LUA_PATH=`lua -e 'print(package.path)'`
export LUA_CPATH=`lua -e 'print(package.cpath)'`
# this is a shell function mostly so that I can comment it out
# to experiment with starting sway or tinywl or something else
# to see how they behave if kiwmi is being weird
start_eufon(){
kiwmi -c init.lua;
}
'';
})).override { debug = true; }