Skip to content

RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process

added nix flake

oxydizereae26e6021c3
diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml
new file mode 100644
index 0000000..128f1a6
--- /dev/null
+++ b/.github/workflows/nix.yml
@@ -0,0 +1,22 @@
+name: Nix
+
+on:
+ push:
+ pull_request:
+ workflow_dispatch:
+
+permissions:
+ contents: read
+
+jobs:
+ build:
+ runs-on: ubuntu-24.04
+ timeout-minutes: 45
+ steps:
+ - uses: actions/checkout@v7
+ with:
+ persist-credentials: false
+ - uses: nixbuild/nix-quick-install-action@v35
+ - run: nix flake check --print-build-logs
+ - run: nix build --print-build-logs
+ - run: ./result/bin/rediwm-msg --help
diff --git a/.gitignore b/.gitignore
index 0683111..c86d706 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,5 @@ zig-pkg/
__pycache__/
*.pyc
/release/
+/result
+/result-*
diff --git a/README.md b/README.md
index c160c37..c311e63 100644
--- a/README.md
+++ b/README.md
@@ -51,6 +51,10 @@ curl -fsSL https://rediwm.redios.org/install.sh | sh # add `-s -- --dm` for r
and derivatives such as Artix and CachyOS, Debian, Ubuntu and Fedora).
Installing never replaces your login manager
+NixOS users can install the flake and enable `programs.rediwm.enable` to add
+RediWM to their existing login manager. See [Nix installation](docs/nix.md)
+for configuration, building with Nix, and the initial support scope.
+
## Building and running
Requirements: Zig 0.17, wlroots 0.20, and the development files for Wayland,
diff --git a/docs/nix.md b/docs/nix.md
new file mode 100644
index 0000000..03c0a87
--- /dev/null
+++ b/docs/nix.md
@@ -0,0 +1,86 @@
+# Nix and NixOS
+
+The flake packages RediWM and its apps for `x86_64-linux`, using Zig 0.17 and
+the same patched wlroots 0.20.2 as the distro releases. `flake.lock` pins
+Nixpkgs; Zig's source dependencies are fetched separately with a fixed hash,
+so the compilation step needs no network access.
+
+## NixOS session
+
+Add RediWM as an input to your system flake:
+
+```nix
+inputs.rediwm.url = "github:oxydizer/rediwm";
+```
+
+Include the module in the `modules` list of your `nixosSystem`:
+
+```nix
+rediwm.nixosModules.default
+{
+ programs.rediwm.enable = true;
+}
+```
+
+Here `rediwm` is the flake input passed to your `outputs` function. Keep the
+display manager you already use. Rebuild your system, log out, and select
+**RediWM** at login. The module registers the session, enables the graphical
+desktop prerequisites, configures portals and polkit, and installs a PAM
+policy for the built-in lock screen. It does not select a default session.
+
+Keep RediWM's own Nixpkgs pin initially: older Nixpkgs versions may not have
+Zig 0.17 or the dependencies needed by wlroots 0.20. Override
+`programs.rediwm.package` if you need a custom package.
+
+The NixOS portal service uses its declarative configuration. Screen sharing
+defaults to RediWM's picker and 30 fps; override these through
+`xdg.portal.wlr.settings.screencast`. These xdpw settings also apply to other
+wlroots sessions using the same service.
+
+This first package supports RediWM under an existing display manager.
+`rediwm-dm`, the account-management helper and the installer restart tool are
+not installed. Manage users and login services through NixOS; RediWM's Users
+settings cannot perform privileged account edits in this package. Updating
+the package takes effect after logging out and back in.
+
+## Build or try a nested session
+
+Enable Nix's `nix-command` and `flakes` experimental features. From a checkout:
+
+```sh
+nix build
+./result/bin/rediwm-msg --help
+WLR_BACKENDS=wayland ./result/bin/rediwm
+```
+
+Run the last command inside an existing Wayland session. For a login session,
+use the NixOS module: installing just the package does not configure PAM or
+system services. Nix on other Linux distributions can build the package, but
+host graphics-driver and login integration are outside this module's scope.
+
+There is no RediWM binary cache configured yet. Nix uses cached dependencies
+where available and builds RediWM and its patched wlroots locally.
+
+## Maintenance and checks
+
+```sh
+nix flake check --print-build-logs
+nix build --print-build-logs
+```
+
+The checks build the package and evaluate the NixOS module's session, portal,
+polkit and PAM configuration. The GitHub Nix workflow runs them independently
+of `scripts/make-release.sh`; Nix packages do not need a distro tarball.
+Real display-manager login, unlock, Xwayland and browser screen sharing still
+need a NixOS session acceptance check.
+
+When changing `build.zig.zon` dependencies, set `outputHash` in
+`nix/zig-deps.nix` to `lib.fakeHash` (and add `lib` to its arguments), build
+`nix build .#rediwm.zigDeps`, then replace it with the reported actual hash.
+Keep `nix/wlroots.nix` aligned with `scripts/build-wlroots.sh` and the patches
+in `patches/wlroots/`. Update Nixpkgs deliberately with
+`nix flake update nixpkgs`, then rerun the checks.
+
+Nix-specific runtime path substitutions live in `nix/runtime-paths.nix` and
+fail if their source text changes. The PDF sandbox grants access only to
+specific font and Poppler data directories, not the whole Nix store.
diff --git a/flake.lock b/flake.lock
new file mode 100644
index 0000000..908bdd1
--- /dev/null
+++ b/flake.lock
@@ -0,0 +1,27 @@
+{
+ "nodes": {
+ "nixpkgs": {
+ "locked": {
+ "lastModified": 1793110635,
+ "narHash": "sha256-dhoW6VgFWlaodSY5jrBn+CF2FLmaUvDVgM7+C7T2+NM=",
+ "owner": "NixOS",
+ "repo": "nixpkgs",
+ "rev": "31ecbaca1bdefa45dffc409f0250bd8039ea0010",
+ "type": "github"
+ },
+ "original": {
+ "owner": "NixOS",
+ "ref": "nixos-unstable",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "root": {
+ "inputs": {
+ "nixpkgs": "nixpkgs"
+ }
+ }
+ },
+ "root": "root",
+ "version": 7
+}
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 0000000..9c05b5b
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,39 @@
+{
+ description = "RediWM Wayland desktop";
+
+ inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
+
+ outputs =
+ { self, nixpkgs }:
+ let
+ systems = [ "x86_64-linux" ];
+ forAllSystems = nixpkgs.lib.genAttrs systems;
+ in
+ {
+ packages = forAllSystems (
+ system:
+ let
+ pkgs = import nixpkgs { inherit system; };
+ rediwm = pkgs.callPackage ./nix/package.nix { };
+ in
+ {
+ inherit rediwm;
+ default = rediwm;
+ }
+ );
+
+ nixosModules.default = self.nixosModules.rediwm;
+ nixosModules.rediwm = { pkgs, lib, ... }: {
+ imports = [ ./nix/module.nix ];
+ programs.rediwm.package = lib.mkDefault self.packages.${pkgs.stdenv.hostPlatform.system}.rediwm;
+ };
+
+ checks = forAllSystems (system: {
+ package = self.packages.${system}.rediwm;
+ module = import ./nix/module-check.nix {
+ inherit nixpkgs system;
+ rediwmModule = self.nixosModules.rediwm;
+ };
+ });
+ };
+}
diff --git a/nix/module-check.nix b/nix/module-check.nix
new file mode 100644
index 0000000..a269822
--- /dev/null
+++ b/nix/module-check.nix
@@ -0,0 +1,29 @@
+{
+ nixpkgs,
+ system,
+ rediwmModule,
+}:
+let
+ evaluated = nixpkgs.lib.nixosSystem {
+ inherit system;
+ modules = [
+ rediwmModule
+ {
+ programs.rediwm.enable = true;
+ system.stateVersion = "26.05";
+ boot.isContainer = true;
+ }
+ ];
+ };
+ inherit (evaluated) config pkgs;
+in
+assert builtins.elem config.programs.rediwm.package config.services.displayManager.sessionPackages;
+assert config.security.polkit.enable;
+assert config.security.wrappers.pkexec.setuid;
+assert config.services.displayManager.defaultSession == null;
+assert config.xdg.portal.config.rediwm."org.freedesktop.impl.portal.ScreenCast" == "wlr";
+assert nixpkgs.lib.all (entry: entry.assertion) config.assertions;
+pkgs.runCommand "rediwm-module-check" { } ''
+ test -s ${config.environment.etc."pam.d/rediwm".source}
+ touch "$out"
+''
diff --git a/nix/module.nix b/nix/module.nix
new file mode 100644
index 0000000..d9e1c55
--- /dev/null
+++ b/nix/module.nix
@@ -0,0 +1,62 @@
+{
+ config,
+ lib,
+ pkgs,
+ options,
+ ...
+}:
+let
+ cfg = config.programs.rediwm;
+in
+{
+ options.programs.rediwm = {
+ enable = lib.mkEnableOption "the RediWM Wayland session";
+ package = lib.mkOption {
+ type = lib.types.package;
+ description = "RediWM package supplied by the flake.";
+ };
+ };
+
+ config = lib.mkIf cfg.enable {
+ environment.systemPackages = [ cfg.package ];
+ services.displayManager.sessionPackages = [ cfg.package ];
+ services.graphical-desktop.enable = true;
+ programs.xwayland.enable = lib.mkDefault true;
+ programs.dconf.enable = lib.mkDefault true;
+ security.polkit = {
+ enable = true;
+ }
+ // lib.optionalAttrs (options.security.polkit ? enablePkexecWrapper) {
+ # Older NixOS releases enable this wrapper along with polkit.
+ enablePkexecWrapper = true;
+ };
+ security.pam.services.rediwm = { };
+
+ xdg.portal = {
+ enable = true;
+ wlr.enable = true;
+ # NixOS starts xdpw with --config, so its per-user config is bypassed.
+ wlr.settings.screencast = {
+ max_fps = lib.mkDefault 30;
+ chooser_type = lib.mkDefault "dmenu";
+ chooser_cmd = lib.mkDefault "${cfg.package}/bin/rediwm-share-picker --xdpw-dmenu";
+ };
+ extraPortals = [
+ cfg.package
+ pkgs.xdg-desktop-portal-gtk
+ ];
+ config.rediwm = {
+ default = [ "gtk" ];
+ "org.freedesktop.impl.portal.ScreenCast" = [ "wlr" ];
+ "org.freedesktop.impl.portal.Settings" = [
+ "rediwm"
+ "gtk"
+ ];
+ "org.freedesktop.impl.portal.FileChooser" = [
+ "rediwm"
+ "gtk"
+ ];
+ };
+ };
+ };
+}
diff --git a/nix/package.nix b/nix/package.nix
new file mode 100644
index 0000000..5209577
--- /dev/null
+++ b/nix/package.nix
@@ -0,0 +1,225 @@
+{
+ lib,
+ stdenv,
+ callPackage,
+ zig_0_17,
+ pkg-config,
+ wayland-scanner,
+ makeWrapper,
+ wrapGAppsNoGuiHook,
+ autoPatchelfHook,
+ wayland,
+ wayland-protocols,
+ libxkbcommon,
+ pixman,
+ cairo,
+ freetype,
+ harfbuzz,
+ fontconfig,
+ librsvg,
+ gdk-pixbuf,
+ pango,
+ libinput,
+ pam,
+ libpulseaudio,
+ pulseaudio,
+ pipewire,
+ poppler,
+ libseccomp,
+ libarchive,
+ libjpeg,
+ libpng,
+ libwebp,
+ readline,
+ libtorrent-rasterbar,
+ boost,
+ openssl,
+ json-glib,
+ glib,
+ cups,
+ libxcb,
+ libdrm,
+ libGL,
+ xwayland,
+ xdg-utils,
+ shared-mime-info,
+ hicolor-icon-theme,
+ tzdata,
+ systemd,
+ glibc,
+ dejavu_fonts,
+ poppler_data,
+}:
+
+let
+ wlroots = callPackage ./wlroots.nix { };
+ zigDeps = callPackage ./zig-deps.nix { };
+in
+stdenv.mkDerivation {
+ pname = "rediwm";
+ version = builtins.head (
+ builtins.match ''.*\.version = "([^"]+)".*'' (builtins.readFile ../build.zig.zon)
+ );
+ src = lib.fileset.toSource {
+ root = ../.;
+ fileset = lib.fileset.unions [
+ ../build.zig
+ ../build.zig.zon
+ ../build
+ ../src
+ ../protocol
+ ../assets
+ ../data
+ ../po
+ ../tests
+ ../tools
+ ../LICENSE-MIT
+ ../LICENSE-APACHE
+ ];
+ };
+
+ strictDeps = true;
+ nativeBuildInputs = [
+ zig_0_17
+ pkg-config
+ wayland-scanner
+ makeWrapper
+ wrapGAppsNoGuiHook
+ autoPatchelfHook
+ ];
+ dontWrapGApps = true;
+ buildInputs = [
+ # zig-wayland queries wayland-scanner.pc through the target pkg-config.
+ wlroots
+ wayland
+ wayland-scanner
+ wayland-protocols
+ libxkbcommon
+ pixman
+ cairo
+ freetype
+ harfbuzz
+ fontconfig
+ librsvg
+ gdk-pixbuf
+ pango
+ libinput
+ pam
+ libpulseaudio
+ pipewire
+ poppler
+ libseccomp
+ libarchive
+ libjpeg
+ libpng
+ libwebp
+ readline
+ libtorrent-rasterbar
+ boost
+ openssl
+ json-glib
+ glib
+ cups
+ libxcb
+ libdrm
+ libGL
+ ]
+ ++ wlroots.buildInputs; # wlroots.pc's Requires.private is needed for C headers too.
+
+ # explicit_sync.c includes drm.h directly. It lives below include/libdrm,
+ # which wlroots' shared-library pkg-config flags do not expose.
+ env.NIX_CFLAGS_COMPILE = "-isystem ${lib.getDev libdrm}/include/libdrm";
+
+ postPatch = import ./runtime-paths.nix {
+ inherit
+ lib
+ tzdata
+ systemd
+ glibc
+ pulseaudio
+ dejavu_fonts
+ fontconfig
+ poppler_data
+ ;
+ };
+
+ configurePhase = ''
+ runHook preConfigure
+ export ZIG_GLOBAL_CACHE_DIR="$TMPDIR/zig-cache"
+ mkdir -p "$ZIG_GLOBAL_CACHE_DIR"
+ cp -R ${zigDeps}/p "$ZIG_GLOBAL_CACHE_DIR/p"
+ chmod -R u+w "$ZIG_GLOBAL_CACHE_DIR"
+ runHook postConfigure
+ '';
+ buildPhase = ''
+ runHook preBuild
+ zig build -Doptimize=ReleaseSafe -Dcpu=baseline -j"$NIX_BUILD_CORES" --prefix "$out"
+ runHook postBuild
+ '';
+ installPhase = ''
+ runHook preInstall
+ # Login/account administration is configured by NixOS, not our installer.
+ rm "$out/bin/rediwm-dm" "$out/bin/rediwm-accounts-helper" "$out/bin/rediwm-restart"
+ rm "$out/share/polkit-1/actions/org.rediwm.accounts.policy"
+ rm "$out/share/wayland-sessions/rediwm-release-safe.desktop"
+ substituteInPlace "$out/share/wayland-sessions/rediwm.desktop" \
+ --replace-fail 'Exec=rediwm-session' "Exec=$out/bin/rediwm-session"
+ install -Dm644 data/rediwm-theme.xml "$out/share/mime/packages/rediwm-theme.xml"
+ install -Dm644 LICENSE-MIT "$out/share/licenses/rediwm/LICENSE-MIT"
+ install -Dm644 LICENSE-APACHE "$out/share/licenses/rediwm/LICENSE-APACHE"
+ runHook postInstall
+ '';
+ postFixup = ''
+ # Keep executables in bin/: the supervisor and clients find siblings and
+ # ../share relative to /proc/self/exe, including when behind a wrapper.
+ for program in "$out"/bin/*; do
+ wrapProgram "$program" \
+ "''${gappsWrapperArgs[@]}" \
+ --prefix PATH : ${
+ lib.makeBinPath [
+ xwayland
+ xdg-utils
+ glib
+ ]
+ } \
+ --suffix XDG_DATA_DIRS : "$out/share:${
+ lib.makeSearchPath "share" [
+ shared-mime-info
+ hicolor-icon-theme
+ dejavu_fonts
+ ]
+ }" \
+ --set-default TZDIR ${tzdata}/share/zoneinfo
+ done
+ '';
+ doInstallCheck = true;
+ installCheckPhase = ''
+ runHook preInstallCheck
+ "$out/bin/rediwm-msg" --help > /dev/null
+ test -x "$out/bin/rediwm-session"
+ grep -Fx "Exec=$out/bin/rediwm-session" "$out/share/wayland-sessions/rediwm.desktop"
+ grep -Fx "TryExec=$out/bin/rediwm-session" "$out/share/wayland-sessions/rediwm.desktop"
+ test ! -e "$out/bin/rediwm-dm"
+ test ! -e "$out/share/polkit-1/actions/org.rediwm.accounts.policy"
+ test -x ${lib.getExe' pulseaudio "paplay"}
+ test -x ${lib.getExe' systemd "systemctl"}
+ test -x ${lib.getBin glibc}/bin/locale
+ test -r ${tzdata}/share/zoneinfo/zone.tab
+ runHook postInstallCheck
+ '';
+
+ passthru = {
+ providedSessions = [ "rediwm" ];
+ inherit wlroots zigDeps;
+ };
+ meta = {
+ description = "RediWM Wayland desktop";
+ homepage = "https://github.com/oxydizer/rediwm";
+ license = with lib.licenses; [
+ mit
+ asl20
+ ];
+ platforms = [ "x86_64-linux" ];
+ mainProgram = "rediwm";
+ };
+}
diff --git a/nix/runtime-paths.nix b/nix/runtime-paths.nix
new file mode 100644
index 0000000..4d78a28
--- /dev/null
+++ b/nix/runtime-paths.nix
@@ -0,0 +1,35 @@
+{
+ lib,
+ tzdata,
+ systemd,
+ glibc,
+ pulseaudio,
+ dejavu_fonts,
+ fontconfig,
+ poppler_data,
+}:
+
+# Keep distro-specific paths in the packaging layer. --replace-fail makes
+# upstream changes visible rather than silently shipping broken lookups.
+''
+ substituteInPlace src/polkit/native.c \
+ --replace-fail 'const char *paths[] = {' 'const char *paths[] = {"/run/wrappers/bin/polkit-agent-helper-1", '
+ substituteInPlace src/systemd_edit.zig \
+ --replace-fail '/usr/bin/pkexec' '/run/wrappers/bin/pkexec' \
+ --replace-fail 'else "/bin/pkexec"' 'else "/run/wrappers/bin/pkexec"' \
+ --replace-fail '/usr/bin/systemctl' '${lib.getExe' systemd "systemctl"}' \
+ --replace-fail 'else "/bin/systemctl"' 'else "${lib.getExe' systemd "systemctl"}"'
+ substituteInPlace src/config_runtime/region.zig src/control_center/sections/region.zig \
+ --replace-fail '/usr/share/zoneinfo' '${tzdata}/share/zoneinfo'
+ substituteInPlace src/control_center/sections/region.zig \
+ --replace-fail '/usr/bin/locale' '${lib.getBin glibc}/bin/locale'
+ substituteInPlace src/audio/sounds.zig \
+ --replace-fail '/usr/bin/paplay' '${lib.getExe' pulseaudio "paplay"}'
+ # Permit only these font/character-map data directories after Landlock,
+ # never the whole Nix store. The UI's selected fonts are opened beforehand.
+ substituteInPlace src/pdf/sandbox.c \
+ --replace-fail '/usr/share/fonts' '${dejavu_fonts}/share/fonts' \
+ --replace-fail '/usr/local/share/fonts' '${dejavu_fonts.minimal}' \
+ --replace-fail '/usr/share/fontconfig' '${fontconfig}/etc/fonts' \
+ --replace-fail '/usr/share/poppler' '${poppler_data}/share/poppler'
+''
diff --git a/nix/wlroots.nix b/nix/wlroots.nix
new file mode 100644
index 0000000..7a1f72a
--- /dev/null
+++ b/nix/wlroots.nix
@@ -0,0 +1,23 @@
+{ wlroots_0_20, fetchurl }:
+
+# Match scripts/build-wlroots.sh, including RediWM's local patches. Nix
+# supplies the dependencies; Meson must never download fallback subprojects.
+wlroots_0_20.overrideAttrs (old: {
+ version = "0.20.2";
+ src = fetchurl {
+ url = "https://gitlab.freedesktop.org/wlroots/wlroots/-/archive/0.20.2/wlroots-0.20.2.tar.gz";
+ sha256 = "972c7ac44b17828f4702bfae7cd8347346a3fb5b2c1076cfa2c3fcedac5ec343";
+ };
+ patches = (old.patches or [ ]) ++ [ ../patches/wlroots/0001-repair-window-titles.patch ];
+ outputs = [ "out" ];
+ mesonFlags = (old.mesonFlags or [ ]) ++ [
+ "-Dexamples=false"
+ "-Dbackends=drm,libinput,x11"
+ "-Drenderers=gles2"
+ "-Dsession=enabled"
+ "-Dcolor-management=enabled"
+ "-Dlibliftoff=disabled"
+ ];
+ # Nixpkgs normally copies example executables to a separate output.
+ postFixup = "";
+})
diff --git a/nix/zig-deps.nix b/nix/zig-deps.nix
new file mode 100644
index 0000000..fcbf03b
--- /dev/null
+++ b/nix/zig-deps.nix
@@ -0,0 +1,32 @@
+{
+ stdenvNoCC,
+ zig_0_17,
+ cacert,
+}:
+
+# Only this fixed-output fetch may access the network. The actual build
+# receives the verified package cache and runs completely offline.
+stdenvNoCC.mkDerivation {
+ pname = "rediwm-zig-deps";
+ version = "1";
+ src = ../build.zig.zon;
+ dontUnpack = true;
+ nativeBuildInputs = [
+ zig_0_17
+ cacert
+ ];
+ dontConfigure = true;
+ dontInstall = true;
+ dontFixup = true;
+ buildPhase = ''
+ export ZIG_GLOBAL_CACHE_DIR="$TMPDIR/zig-cache"
+ cp "$src" build.zig.zon
+ touch build.zig
+ zig build --fetch
+ mkdir -p "$out"
+ cp -R "$ZIG_GLOBAL_CACHE_DIR/p" "$out/p"
+ '';
+ outputHashMode = "recursive";
+ outputHashAlgo = "sha256";
+ outputHash = "sha256-Bm0/CoGiYtscJWFCDKVEiUmA59n9PATonIuEjOBr3GM=";
+}