From 36f8a44906c9015c300618801a7364281f2f8557 Mon Sep 17 00:00:00 2001 From: Daniel Ziltener Date: Tue, 19 Mar 2024 23:29:14 +0100 Subject: [PATCH] . --- zilti/packages/hyprland.scm | 365 ++++++++++++++++++++++++++++++++++++ 1 file changed, 365 insertions(+) diff --git a/zilti/packages/hyprland.scm b/zilti/packages/hyprland.scm index bccba75..ef2c9d0 100644 --- a/zilti/packages/hyprland.scm +++ b/zilti/packages/hyprland.scm @@ -1,4 +1,6 @@ (define-module (zilti packages hyprland) + #:use-module (srfi srfi-1) + #:use-module (ice-9 match) #:use-module (guix packages) #:use-module (guix download) #:use-module (guix gexp) @@ -13,14 +15,18 @@ #:use-module (gnu packages autotools) #:use-module (gnu packages base) #:use-module (gnu packages bash) + #:use-module (gnu packages bison) #:use-module (gnu packages build-tools) #:use-module (gnu packages check) #:use-module (gnu packages cmake) #:use-module (gnu packages compression) #:use-module (gnu packages docbook) + #:use-module (gnu packages elf) + #:use-module (gnu packages flex) #:use-module (gnu packages fontutils) #:use-module (gnu packages freedesktop) #:use-module (gnu packages gcc) + #:use-module (gnu packages gettext) #:use-module (gnu packages ghostscript) #:use-module (gnu packages gl) #:use-module (gnu packages glib) @@ -29,21 +35,380 @@ #:use-module (gnu packages hardware) #:use-module (gnu packages image) #:use-module (gnu packages linux) + #:use-module (gnu packages llvm) #:use-module (gnu packages ninja) #:use-module (gnu packages pciutils) #:use-module (gnu packages pcre) #:use-module (gnu packages pdf) #:use-module (gnu packages python) + #:use-module (gnu packages python-xyz) #:use-module (gnu packages pkg-config) #:use-module (gnu packages version-control) #:use-module (gnu packages xdisorg) #:use-module (gnu packages rust) #:use-module (gnu packages web) + #:use-module (gnu packages xml) #:use-module (gnu packages video) #:use-module (gnu packages vulkan) #:use-module (gnu packages wm) #:use-module (gnu packages xorg)) +(define-public libdrm ;; SENT to Guix + (package + (name "libdrm") + (version "2.4.120") + (source (origin + (method url-fetch) + (uri (string-append + "https://dri.freedesktop.org/libdrm/libdrm-" + version ".tar.xz")) + (sha256 + (base32 + "0yijzgg6rdsa68bz03sw0lcfa2nclv9m3as1cja50wkcyxim7x9v")))) + (build-system meson-build-system) + (arguments + (list #:configure-flags + (match (%current-system) + ((or "armhf-linux" "aarch64-linux") + #~(list "-Dexynos=enabled" + "-Domap=enabled" + "-Detnaviv=enabled" + "-Dtegra=enabled" + "-Dfreedreno-kgsl=true")) + (_ ''())) + #:phases + #~(modify-phases %standard-phases + ;; A typo in a previous upstream commit disabled building + ;; libdrm_intel by default on supported platforms. This was + ;; fixed by the following change in upstream commit + ;; 8a933c778a0eb36526bf3fc8a289e25add9ff8b0. + ;; TODO: Remove on next update of libdrm. + (add-after 'unpack 'build-intel-by-default + (lambda _ + (substitute* "meson.build" + (("system\\(\\)\\.startswith") + "cpu_family().startswith")))) + (replace 'check + (lambda* (#:key tests? #:allow-other-keys) + (when tests? + (invoke "meson" "test" "--timeout-multiplier" "5"))))))) + (propagated-inputs + (list libpciaccess)) + (native-inputs + (list pkg-config)) + (home-page "https://dri.freedesktop.org/wiki/") + (synopsis "Direct rendering userspace library") + (description "The Direct Rendering Infrastructure, also known as the DRI, +is a framework for allowing direct access to graphics hardware under the +X Window System in a safe and efficient manner. It includes changes to the +X server, to several client libraries, and to the kernel (DRM, Direct +Rendering Manager). The most important use for the DRI is to create fast +OpenGL implementations providing hardware acceleration for Mesa. +Several 3D accelerated drivers have been written to the DRI specification, +including drivers for chipsets produced by 3DFX, AMD (formerly ATI), Intel +and Matrox.") + (license license:x11))) + +;;; Mesa needs LibVA headers to build its Gallium-based VA API implementation; +;;; LibVA itself depends on Mesa. We use the following to solve the circular +;;; dependency. +(define libva-without-mesa + ;; Delay to work around circular import problem. + (delay + (package + (inherit libva) + (name "libva-without-mesa") + (inputs (fold alist-delete (package-inputs libva) + '("mesa" "wayland"))) + (arguments + (strip-keyword-arguments + '(#:make-flags) + (substitute-keyword-arguments (package-arguments libva) + ((#:configure-flags flags) + '(list "--disable-glx")))))))) + +(define-public mesa ;; SENT to Guix + (package + (name "mesa") + (version "24.0.3") + (source + (origin + (method url-fetch) + (uri (list (string-append "https://archive.mesa3d.org/" + "mesa-" version ".tar.xz") + (string-append "ftp://ftp.freedesktop.org/pub/mesa/" + "mesa-" version ".tar.xz"))) + (sha256 + (base32 + "1gpx3glifdvyw2fxigiannrxkdfhag6b6h0nxab3azbvlfickbkp")))) + (build-system meson-build-system) + (propagated-inputs + ;; The following are in the Requires.private field of gl.pc. + (list libdrm + libvdpau + libx11 + libxdamage + libxfixes + libxshmfence + libxxf86vm + xorgproto)) + (inputs + (list elfutils ;libelf required for r600 when using llvm + expat + (force libva-without-mesa) + libxml2 + libxrandr + libxvmc + llvm-for-mesa + wayland + wayland-protocols + `(,zstd "lib"))) + (native-inputs + (cons* bison + flex + gettext-minimal + glslang + pkg-config + python-libxml2 ;for OpenGL ES 1.1 and 2.0 support + python-mako + python-wrapper + (@ (gnu packages base) which) + (if (%current-target-system) + (list cmake-minimal-cross + pkg-config-for-build + wayland + wayland-protocols) + '()))) + (outputs '("out" "bin")) + (arguments + (list + #:configure-flags + #~(list + #$@(cond + ((target-aarch64?) + ;; TODO: Fix svga driver for non-Intel architectures. + '("-Dgallium-drivers=etnaviv,freedreno,kmsro,lima,nouveau,\ +panfrost,r300,r600,swrast,tegra,v3d,vc4,virgl,zink")) + ((target-arm32?) + ;; Freedreno FTBFS when built on a 64-bit machine. + '("-Dgallium-drivers=etnaviv,kmsro,lima,nouveau,panfrost,\ +r300,r600,swrast,tegra,v3d,vc4,virgl,zink")) + ((or (target-ppc64le?) (target-ppc32?) (target-riscv64?)) + '("-Dgallium-drivers=nouveau,r300,r600,radeonsi,swrast,virgl,zink")) + (else + '("-Dgallium-drivers=crocus,iris,nouveau,r300,r600,radeonsi,\ +svga,swrast,virgl,zink"))) + ;; Enable various optional features. TODO: opencl requires libclc, + ;; omx requires libomxil-bellagio + "-Dplatforms=x11,wayland" + "-Dglx=dri" ;Thread Local Storage, improves performance + ;; "-Dopencl=true" + ;; "-Domx=true" + "-Dosmesa=true" + "-Dgallium-xa=enabled" + + ;; features required by wayland + "-Dgles2=enabled" + "-Dgbm=enabled" + "-Dshared-glapi=enabled" + + ;; Explicitly enable Vulkan on some architectures. + #$@(cond + ((or (target-x86-32?) (target-x86-64?)) + '("-Dvulkan-drivers=intel,intel_hasvk,amd,swrast")) + ((or (target-ppc64le?) (target-ppc32?)) + '("-Dvulkan-drivers=amd,swrast")) + ((target-aarch64?) + '("-Dvulkan-drivers=freedreno,amd,broadcom,swrast")) + ((target-riscv64?) + '("-Dvulkan-drivers=amd,swrast")) + (else + '("-Dvulkan-drivers=auto"))) + + ;; Enable the Vulkan overlay layer on all architectures. + "-Dvulkan-layers=device-select,overlay" + + ;; Enable the codecs that were built by default as part of the + ;; 21.3.x releases to avoid functionality regressions. + "-Dvideo-codecs=vc1dec,h264dec,h264enc,h265dec,h265enc" + + ;; Enable ZSTD compression for shader cache. + "-Dzstd=enabled" + + ;; Also enable the tests. + "-Dbuild-tests=true" + + "-Dllvm=enabled") ; default is x86/x86_64 only + + ;; XXX: 'debugoptimized' causes LTO link failures on some drivers. The + ;; documentation recommends using 'release' for performance anyway. + #:build-type "release" + + #:modules '((ice-9 match) + (srfi srfi-1) + (guix build utils) + (guix build meson-build-system)) + #:phases + #~(modify-phases %standard-phases + #$@(if (%current-target-system) + #~((add-after 'unpack 'fix-cross-compiling + (lambda* (#:key native-inputs #:allow-other-keys) + ;; When cross compiling, we use cmake to find llvm, not + ;; llvm-config, because llvm-config cannot be executed + ;; see https://github.com/llvm/llvm-project/issues/58984 + (substitute* "meson.build" + (("method : host_machine\\.system.*") + "method : 'cmake',\n")) + (setenv "CMAKE" + (search-input-file + native-inputs "/bin/cmake"))))) + #~()) + (add-after 'unpack 'disable-failing-test + (lambda _ + ;; Disable the intel vulkan (anv_state_pool) tests, as they may + ;; fail in a nondeterministic fashion (see: + ;; https://gitlab.freedesktop.org/mesa/mesa/-/issues/5446). + (substitute* "src/intel/vulkan/meson.build" + (("if with_tests") + "if false")) + #$@(match (%current-system) + ("riscv64-linux" + ;; According to the test logs the llvm JIT is not designed + ;; for this architecture and the llvmpipe tests all segfault. + ;; The same is true for mesa:gallium / osmesa-render. + `((substitute* '("src/gallium/drivers/llvmpipe/meson.build" + "src/gallium/targets/osmesa/meson.build") + (("if with_tests") "if false")))) + ("powerpc64le-linux" + ;; Disable some of the llvmpipe tests. + `((substitute* "src/gallium/drivers/llvmpipe/lp_test_arit.c" + (("0\\.5, ") "")))) + ("powerpc-linux" + ;; There are some tests which fail specifically on powerpc. + `((substitute* '(;; LLVM ERROR: Relocation type not implemented yet! + "src/gallium/drivers/llvmpipe/meson.build" + ;; This is probably a big-endian test failure. + "src/gallium/targets/osmesa/meson.build") + (("if with_tests") "if not with_tests")) + ;; This test times out and receives SIGTERM. + (substitute* "src/amd/common/meson.build" + (("and not with_platform_windows") "and with_platform_windows")) + (substitute* "src/compiler/nir/meson.build" + ((".*loop_unroll_tests.*") "")))) + ("i686-linux" + ;; This test is known to fail on i686 (see: + ;; https://gitlab.freedesktop.org/mesa/mesa/-/issues/4091). + `((substitute* "src/util/meson.build" + ((".*'tests/u_debug_stack_test.cpp',.*") "")))) + ("aarch64-linux" + ;; The ir3_disasm test segfaults. + ;; The simplest way to skip it is to run a different test instead. + `((substitute* "src/freedreno/ir3/meson.build" + (("disasm\\.c'") "delay.c',\n link_args: ld_args_build_id")))) + ("armhf-linux" + ;; Disable some of the llvmpipe tests. + `((substitute* "src/gallium/drivers/llvmpipe/meson.build" + (("'lp_test_arit', ") "")))) + (_ + '((display "No tests to disable on this architecture.\n")))))) + (add-before 'configure 'fix-dlopen-libnames + (lambda _ + (let ((out #$output)) + ;; Remain agnostic to .so.X.Y.Z versions while doing + ;; the substitutions so we're future-safe. + (substitute* "src/glx/meson.build" + (("-DGL_LIB_NAME=\"lib@0@\\.so\\.@1@\"") + (string-append "-DGL_LIB_NAME=\"" out + "/lib/lib@0@.so.@1@\""))) + (substitute* "src/gbm/backends/dri/gbm_dri.c" + (("\"libglapi\\.so") + (string-append "\"" out "/lib/libglapi.so"))) + (substitute* "src/gbm/main/backend.c" + ;; No need to patch the gbm_gallium_drm.so reference; + ;; it's never installed since Mesa removed its + ;; egl_gallium support. + (("\"gbm_dri\\.so") + (string-append "\"" out "/lib/dri/gbm_dri.so")))))) + (add-after 'install 'split-outputs + (lambda _ + (let ((out #$output) + (bin #$output:bin)) + ;; Not all architectures have the Vulkan overlay control script. + (mkdir-p (string-append out "/bin")) + (call-with-output-file (string-append out "/bin/.empty") + (const #t)) + (copy-recursively (string-append out "/bin") + (string-append bin "/bin")) + (delete-file-recursively (string-append out "/bin"))))) + (add-after 'install 'symlinks-instead-of-hard-links + (lambda _ + ;; All the drivers and gallium targets create hard links upon + ;; installation (search for "hardlink each megadriver instance" + ;; in the makefiles). This is no good for us since we'd produce + ;; nars that contain several copies of these files. Thus, turn + ;; them into symlinks, which saves ~124 MiB. + (let* ((out #$output) + (lib (string-append out "/lib")) + (files (find-files lib + (lambda (file stat) + (and (string-contains file ".so") + (eq? 'regular + (stat:type stat)))))) + (inodes (map (compose stat:ino stat) files))) + (for-each (lambda (inode) + (match (filter-map (match-lambda + ((file ino) + (and (= ino inode) file))) + (zip files inodes)) + ((_) + #f) + ((reference others ..1) + (format #t "creating ~a symlinks to '~a'~%" + (length others) reference) + (for-each delete-file others) + (for-each (lambda (file) + (if (string=? (dirname file) + (dirname reference)) + (symlink (basename reference) + file) + (symlink reference file))) + others)))) + (delete-duplicates inodes))))) + (add-after 'install 'set-layer-path-in-manifests + (lambda _ + (let* ((out #$output) + (implicit-path (string-append + out + "/share/vulkan/implicit_layer.d/")) + (explicit-path (string-append + out + "/share/vulkan/explicit_layer.d/")) + (fix-layer-path + (lambda (layer-name) + (let* ((explicit (string-append explicit-path layer-name ".json")) + (implicit (string-append implicit-path layer-name ".json")) + (manifest (if (file-exists? explicit) + explicit + implicit))) + (substitute* manifest + (((string-append "\"lib" layer-name ".so\"")) + (string-append "\"" out "/lib/lib" layer-name ".so\""))))))) + (for-each fix-layer-path '("VkLayer_MESA_device_select" + "VkLayer_MESA_overlay")))))))) + (native-search-paths + (list (search-path-specification + ;; Ensure the Mesa VDPAU drivers can be found. + (variable "VDPAU_DRIVER_PATH") + (separator #f) + (files '("lib/vdpau"))))) + (home-page "https://mesa3d.org/") + (synopsis "OpenGL and Vulkan implementations") + (description "Mesa is a free implementation of the OpenGL and Vulkan +specifications - systems for rendering interactive 3D graphics. A variety of +device drivers allows Mesa to be used in many different environments ranging +from software emulation to complete hardware acceleration for modern GPUs.") + (license license:x11))) + (define-public glu ;; SENT to Guix (package (name "glu")