diff --git a/README.md b/README.md index 45688141..d171d691 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ the only hard dependency for my exported pkgs/modules should be [nixpkgs][nixpkg building <./hosts/> will require [sops][sops]. you might specifically be interested in these files (elaborated further in #key-points-of-interest): -- [`sxmo-utils-latest`](./pkgs/additional/sxmo-utils/default.nix) +- [`sxmo-utils`](./pkgs/additional/sxmo-utils/default.nix) - [example SXMO deployment](./hosts/modules/gui/sxmo/default.nix) - [my implementation of impermanence](./modules/persist/default.nix) - my way of deploying dotfiles/configuring programs per-user: diff --git a/hosts/by-name/lappy/polyfill.nix b/hosts/by-name/lappy/polyfill.nix index bad5633c..2567e303 100644 --- a/hosts/by-name/lappy/polyfill.nix +++ b/hosts/by-name/lappy/polyfill.nix @@ -33,7 +33,7 @@ # and so it just wouldn't handle any button inputs (sxmo_hook_inputhandler.sh not on path) SXMO_DEVICE_NAME = "three_button_touchscreen"; }; - package = (pkgs.sxmo-utils-latest.override { preferSystemd = true; }).overrideAttrs (base: { + package = (pkgs.sxmo-utils.override { preferSystemd = true; }).overrideAttrs (base: { postPatch = (base.postPatch or "") + '' # after volume-button navigation mode, restore full keyboard functionality cp ${./xkb_mobile_normal_buttons} ./configs/xkb/xkb_mobile_normal_buttons diff --git a/hosts/modules/gui/sxmo/default.nix b/hosts/modules/gui/sxmo/default.nix index 2be82562..1db04460 100644 --- a/hosts/modules/gui/sxmo/default.nix +++ b/hosts/modules/gui/sxmo/default.nix @@ -130,7 +130,7 @@ in }; sane.gui.sxmo.package = mkOption { type = types.package; - default = pkgs.sxmo-utils-latest.override { preferSystemd = true; }; + default = pkgs.sxmo-utils.override { preferSystemd = true; }; description = '' sxmo base scripts and hooks collection. consider overriding the outputs under /share/sxmo/default_hooks diff --git a/pkgs/additional/sxmo-utils/common.nix b/pkgs/additional/sxmo-utils/common.nix deleted file mode 100644 index fdab09bf..00000000 --- a/pkgs/additional/sxmo-utils/common.nix +++ /dev/null @@ -1,198 +0,0 @@ -{ stdenv -, bash -, bc -, bemenu -, bonsai -, brightnessctl -, buildPackages -, busybox -, conky -, coreutils -, curl -, dbus -, dmenu -, fetchgit -, fetchpatch -, gitUpdater -, gnugrep -, gojq -, grim -, inotify-tools -, j4-dmenu-desktop -, jq -, lib -, libnotify -, libxml2 -, lisgd -, makeBinaryWrapper -, mako -, modemmanager -, nettools -, networkmanager -, playerctl -, procps -, pulseaudio -, rsync -, scdoc -, scrot -, sfeed -, slurp -, superd -, sway -, swayidle -, systemd -, wob -, wl-clipboard -, wtype -, wvkbd -, xdg-user-dirs -, xdotool -, xrdb - -, version -, rev ? version -, hash ? "" -, patches ? [] -, supportSway ? true -, supportDwm ? false -, preferSystemd ? false -}: - -let - # anything which any sxmo script or default hook in this package might invoke - runtimeDeps = [ - bc # also in busybox - bonsai - brightnessctl - conky - curl - dbus - gnugrep # also in busybox - gojq - inotify-tools - j4-dmenu-desktop - jq - libnotify - libxml2.bin # for xmllint; sxmo_weather.sh, sxmo_surf_linkset.sh - lisgd - mako - modemmanager # mmcli - nettools # netstat - networkmanager # nmcli - playerctl - procps # pgrep - pulseaudio # pactl - sfeed - wob - xdg-user-dirs # used by sxmo_hook_start.sh - xrdb # for sxmo_xinit AND sxmo_winit - ] ++ ( - if preferSystemd then [ systemd ] else [ superd ] - ) ++ lib.optionals supportSway [ - bemenu - grim - slurp # for sxmo_screenshot.sh - sway - swayidle - wl-clipboard # for wl-copy; sxmo_screenshot.sh - wtype # for sxmo_type - wvkbd # sxmo_winit.sh - ] ++ lib.optionals supportDwm [ - dmenu - scrot # sxmo_screenshot.sh - xdotool - ]; -in -stdenv.mkDerivation rec { - pname = "sxmo-utils"; - inherit version; - - src = fetchgit { - url = "https://git.sr.ht/~mil/sxmo-utils"; - inherit rev hash; - }; - - inherit patches; - - postPatch = '' - # allow sxmo to source its init file - sed -i "s@/etc/profile\.d/sxmo_init.sh@$out/etc/profile.d/sxmo_init.sh@" scripts/core/*.sh - # remove absolute paths - substituteInPlace scripts/core/sxmo_version.sh \ - --replace "/usr/bin/" "" - - # let superd find sxmo service binaries at runtime via PATH - # TODO: replace with fully-qualified paths - sed -i 's:ExecStart=/usr/bin/:ExecStart=/usr/bin/env :' \ - configs/services/*.service \ - configs/superd/services/*.service - - # install udev rules to where nix expects - substituteInPlace Makefile \ - --replace "/usr/lib/udev/rules.d" "/etc/udev/rules.d" - # avoid relative paths in udev rules - substituteInPlace configs/udev/90-sxmo.rules \ - --replace "/bin/chgrp" "${coreutils}/bin/chgrp" \ - --replace "/bin/chmod" "${coreutils}/bin/chmod" - '' + lib.optionalString preferSystemd '' - shopt -s globstar - sed -i 's/superctl status "$1" | grep -q started/systemctl --user is-active --quiet "$1"/g' **/*.sh - sed -i 's/superctl/systemctl --user/g' **/*.sh - ''; - - nativeBuildInputs = [ - makeBinaryWrapper - scdoc - ]; - - buildInputs = [ bash ]; # needed here so stdenv's `patchShebangsAuto` hook sets the right interpreter - - makeFlags = [ - "PREFIX=${placeholder "out"}" - "SYSCONFDIR=${placeholder "out"}/etc" - "DESTDIR=" - "OPENRC=0" - # TODO: use SERVICEDIR and EXTERNAL_SERVICES=0 to integrate superd/systemd better - ]; - preInstall = '' - # busybox is used by setup_config_version.sh, but placing it in nativeBuildInputs breaks the nix builder - PATH="$PATH:${buildPackages.busybox}/bin" - ''; - - # we don't wrap sxmo_common.sh or sxmo_init.sh - # which is unfortunate, for non-sxmo-utils files that might source those. - # if that's a problem, could inject a PATH=... line into them with sed. - postInstall = '' - for f in \ - $out/bin/*.sh \ - $out/share/sxmo/default_hooks/desktop/sxmo_hook_*.sh \ - $out/share/sxmo/default_hooks/one_button_e_reader/sxmo_hook_*.sh \ - $out/share/sxmo/default_hooks/three_button_touchscreen/sxmo_hook_*.sh \ - $out/share/sxmo/default_hooks/sxmo_hook_*.sh \ - ; do - case $(basename $f) in - (sxmo_common.sh|sxmo_deviceprofile_*.sh|sxmo_hook_icons.sh|sxmo_init.sh) - # these are sourced by other scripts: don't wrap them else the `exec` in the nix wrapper breaks the outer script - ;; - (*) - wrapProgram "$f" \ - --suffix PATH : "${lib.makeBinPath runtimeDeps}" - ;; - esac - done - ''; - - passthru = { - inherit runtimeDeps; - providedSessions = (lib.optional supportSway "swmo") ++ (lib.optional supportDwm "sxmo"); - updateScript = gitUpdater { }; - }; - - meta = { - homepage = "https://git.sr.ht/~mil/sxmo-utils"; - description = "Contains the scripts and small C programs that glues the sxmo enviroment together"; - license = lib.licenses.mit; - maintainers = with lib.maintainers; [ colinsane ]; - platforms = lib.platforms.linux; - }; -} diff --git a/pkgs/additional/sxmo-utils/default.nix b/pkgs/additional/sxmo-utils/default.nix index 3a673311..c02439d6 100644 --- a/pkgs/additional/sxmo-utils/default.nix +++ b/pkgs/additional/sxmo-utils/default.nix @@ -1,7 +1,113 @@ -{ callPackage +{ stdenv +, bash +, bc +, bemenu +, bonsai +, brightnessctl +, buildPackages +, busybox +, conky +, coreutils +, curl +, dbus +, dmenu +, fetchgit , fetchpatch +, gitUpdater +, gnugrep +, gojq +, grim +, inotify-tools +, j4-dmenu-desktop +, jq +, lib +, libnotify +, libxml2 +, lisgd +, makeBinaryWrapper +, mako +, modemmanager +, nettools +, networkmanager +, playerctl +, procps +, pulseaudio +, rsync +, scdoc +, scrot +, sfeed +, slurp +, superd +, sway +, swayidle +, systemd +, wob +, wl-clipboard +, wtype +, wvkbd +, xdg-user-dirs +, xdotool +, xrdb +, supportSway ? true +, supportDwm ? false +, preferSystemd ? false }: + let + # anything which any sxmo script or default hook in this package might invoke + runtimeDeps = [ + bc # also in busybox + bonsai + brightnessctl + conky + curl + dbus + gnugrep # also in busybox + gojq + inotify-tools + j4-dmenu-desktop + jq + libnotify + libxml2.bin # for xmllint; sxmo_weather.sh, sxmo_surf_linkset.sh + lisgd + mako + modemmanager # mmcli + nettools # netstat + networkmanager # nmcli + playerctl + procps # pgrep + pulseaudio # pactl + sfeed + wob + xdg-user-dirs # used by sxmo_hook_start.sh + xrdb # for sxmo_xinit AND sxmo_winit + ] ++ ( + if preferSystemd then [ systemd ] else [ superd ] + ) ++ lib.optionals supportSway [ + bemenu + grim + slurp # for sxmo_screenshot.sh + sway + swayidle + wl-clipboard # for wl-copy; sxmo_screenshot.sh + wtype # for sxmo_type + wvkbd # sxmo_winit.sh + ] ++ lib.optionals supportDwm [ + dmenu + scrot # sxmo_screenshot.sh + xdotool + ]; +in +stdenv.mkDerivation rec { + pname = "sxmo-utils"; + version = "unstable-2023-10-10"; + + src = fetchgit { + url = "https://git.sr.ht/~mil/sxmo-utils"; + rev = "c33408abb560dac52de52d878840945c12a75a32"; + hash = "sha256-VYUYN5S6qmsNpxMq7xFfgsGcbjIjqvuj36AG+NeMHTM="; + }; + patches = [ (fetchpatch { name = "sxmo_migrate: add option to disable configversion checks"; @@ -44,11 +150,86 @@ let # hash = "sha256-dc71eztkXaZyy+hm5teCw9lI9hKS68pPoP53KiBm5Fg="; # }) ]; -in { - latest = callPackage ./common.nix { - version = "unstable-2023-10-10"; - rev = "c33408abb560dac52de52d878840945c12a75a32"; - hash = "sha256-VYUYN5S6qmsNpxMq7xFfgsGcbjIjqvuj36AG+NeMHTM="; - inherit patches; + + postPatch = '' + # allow sxmo to source its init file + sed -i "s@/etc/profile\.d/sxmo_init.sh@$out/etc/profile.d/sxmo_init.sh@" scripts/core/*.sh + # remove absolute paths + substituteInPlace scripts/core/sxmo_version.sh \ + --replace "/usr/bin/" "" + + # let superd find sxmo service binaries at runtime via PATH + # TODO: replace with fully-qualified paths + sed -i 's:ExecStart=/usr/bin/:ExecStart=/usr/bin/env :' \ + configs/services/*.service \ + configs/superd/services/*.service + + # install udev rules to where nix expects + substituteInPlace Makefile \ + --replace "/usr/lib/udev/rules.d" "/etc/udev/rules.d" + # avoid relative paths in udev rules + substituteInPlace configs/udev/90-sxmo.rules \ + --replace "/bin/chgrp" "${coreutils}/bin/chgrp" \ + --replace "/bin/chmod" "${coreutils}/bin/chmod" + '' + lib.optionalString preferSystemd '' + shopt -s globstar + sed -i 's/superctl status "$1" | grep -q started/systemctl --user is-active --quiet "$1"/g' **/*.sh + sed -i 's/superctl/systemctl --user/g' **/*.sh + ''; + + nativeBuildInputs = [ + makeBinaryWrapper + scdoc + ]; + + buildInputs = [ bash ]; # needed here so stdenv's `patchShebangsAuto` hook sets the right interpreter + + makeFlags = [ + "PREFIX=${placeholder "out"}" + "SYSCONFDIR=${placeholder "out"}/etc" + "DESTDIR=" + "OPENRC=0" + # TODO: use SERVICEDIR and EXTERNAL_SERVICES=0 to integrate superd/systemd better + ]; + preInstall = '' + # busybox is used by setup_config_version.sh, but placing it in nativeBuildInputs breaks the nix builder + PATH="$PATH:${buildPackages.busybox}/bin" + ''; + + # we don't wrap sxmo_common.sh or sxmo_init.sh + # which is unfortunate, for non-sxmo-utils files that might source those. + # if that's a problem, could inject a PATH=... line into them with sed. + postInstall = '' + for f in \ + $out/bin/*.sh \ + $out/share/sxmo/default_hooks/desktop/sxmo_hook_*.sh \ + $out/share/sxmo/default_hooks/one_button_e_reader/sxmo_hook_*.sh \ + $out/share/sxmo/default_hooks/three_button_touchscreen/sxmo_hook_*.sh \ + $out/share/sxmo/default_hooks/sxmo_hook_*.sh \ + ; do + case $(basename $f) in + (sxmo_common.sh|sxmo_deviceprofile_*.sh|sxmo_hook_icons.sh|sxmo_init.sh) + # these are sourced by other scripts: don't wrap them else the `exec` in the nix wrapper breaks the outer script + ;; + (*) + wrapProgram "$f" \ + --suffix PATH : "${lib.makeBinPath runtimeDeps}" + ;; + esac + done + ''; + + passthru = { + inherit runtimeDeps; + providedSessions = (lib.optional supportSway "swmo") ++ (lib.optional supportDwm "sxmo"); + updateScript = gitUpdater { }; + }; + + meta = { + homepage = "https://git.sr.ht/~mil/sxmo-utils"; + description = "Contains the scripts and small C programs that glues the sxmo enviroment together"; + license = lib.licenses.mit; + maintainers = with lib.maintainers; [ colinsane ]; + platforms = lib.platforms.linux; }; } diff --git a/pkgs/default.nix b/pkgs/default.nix index 5ca12985..0b04e1b7 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -60,8 +60,7 @@ let signal-desktop-from-src = callPackage ./additional/signal-desktop-from-src { }; static-nix-shell = callPackage ./additional/static-nix-shell { }; sublime-music-mobile = callPackage ./additional/sublime-music-mobile { }; - sxmo-utils' = lib.recurseIntoAttrs (callPackage ./additional/sxmo-utils { }); - sxmo-utils-latest = sxmo-utils'.latest; + sxmo-utils = callPackage ./additional/sxmo-utils { }; tow-boot-pinephone = callPackage ./additional/tow-boot-pinephone { }; tree-sitter-nix-shell = callPackage ./additional/tree-sitter-nix-shell { }; trivial-builders = lib.recurseIntoAttrs (callPackage ./additional/trivial-builders { });