From 56fa8435c79fb99be3350c8eff017f52c3204634 Mon Sep 17 00:00:00 2001 From: Vegard Bieker Matthey Date: Tue, 31 Mar 2026 01:05:21 +0200 Subject: [PATCH] maybe module --- .gitignore | 1 + config.def.h | 2 +- flake.nix | 28 ++++++++++------- module.nix | 38 +++++++++++++++++++++++ package.nix | 88 +++++++++++++++++++++++++++++++++++++++++++--------- 5 files changed, 131 insertions(+), 26 deletions(-) create mode 100644 module.nix diff --git a/.gitignore b/.gitignore index 1d3642b..da41243 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ dwl .ccls-cache config.h result +result-man diff --git a/config.def.h b/config.def.h index 8a6eda0..318442d 100644 --- a/config.def.h +++ b/config.def.h @@ -103,7 +103,7 @@ LIBINPUT_CONFIG_TAP_MAP_LMR -- 1/2/3 finger tap maps to left/middle/right static const enum libinput_config_tap_button_map button_map = LIBINPUT_CONFIG_TAP_MAP_LRM; /* If you want to use the windows key for MODKEY, use WLR_MODIFIER_LOGO */ -#define MODKEY WLR_MODIFIER_ALT +#define MODKEY WLR_MODIFIER_LOGO #define TAGKEYS(KEY,SKEY,TAG) \ { MODKEY, KEY, view, {.ui = 1 << TAG} }, \ diff --git a/flake.nix b/flake.nix index b94bfe7..9e9e0b8 100644 --- a/flake.nix +++ b/flake.nix @@ -12,20 +12,21 @@ }: let system = "x86_64-linux"; + patches = []; pkgs = nixpkgs.legacyPackages.${system}; nativeBuildInputs = with pkgs; [ - tinycc - gnumake + installShellFiles pkg-config - wayland-protocols + wayland-scanner ]; buildInputs = with pkgs; [ - wayland-scanner - wlroots libinput - wayland + libxcb libxkbcommon pixman + wayland + wayland-protocols + wlroots_0_19 ]; inherit (pkgs) lib; in @@ -55,14 +56,19 @@ }; in { - default = pkgs.callPackage ./package.nix { inherit src buildInputs nativeBuildInputs; }; + default = pkgs.callPackage ./package.nix { inherit src buildInputs nativeBuildInputs patches; }; }; overlays = { - default = self.overlays.dwl; - dwl = final: prev: { - inherit (self.packages.${prev.stdenv.hostPlatform.system}) default; - }; + default = self.overlays.dwl; + dwl = final: prev: { + inherit (self.packages.${prev.stdenv.hostPlatform.system}) default; + }; + }; + + nixosModules = { + default = self.nixosModules.dwl; + dwl = ./module.nix; }; }; } diff --git a/module.nix b/module.nix new file mode 100644 index 0000000..6dcd4b1 --- /dev/null +++ b/module.nix @@ -0,0 +1,38 @@ +{ + config, + lib, + pkgs, + ... +}: + +let + cfg = config.programs.dwl; +in +{ + options.programs.dwl = { + enable = lib.mkEnableOption "dwl, a simple and hackable wayland compositor"; + package = lib.mkPackageOption pkgs "dwl" { }; + + patches = lib.mkOption { + type = lib.types.array; + default = [ ]; + description = "patches for dwl"; + }; + + enableXwayland = lib.mkOption { + type = lib.types.bool; + default = false; + description = "compile with or without xwayland support"; + }; + }; + + config = lib.mkIf cfg.enable { + environment.systemPackages = [ + pkgs.callPackage + ./package.nix + { + inherit (cfg) patches enableXwayland; + } + ]; + }; +} diff --git a/package.nix b/package.nix index 2b493ed..f16bffa 100644 --- a/package.nix +++ b/package.nix @@ -4,24 +4,84 @@ stdenv, buildInputs, nativeBuildInputs, + wayland, + testers, + nixosTests, + writeText, + enableXWayland ? false, + withCustomConfigH ? (configH != null), + configH ? "config.h", + patches, }: -stdenv.mkDerivation { +stdenv.mkDerivation (finalAttrs: { pname = "dwl"; - version = "0.1.0"; - inherit src buildInputs nativeBuildInputs; + version = "0.8-dev"; + inherit + src + buildInputs + nativeBuildInputs + patches + ; - makeFlags = [ + outputs = [ + "out" + "man" ]; - meta = { - description = "dwm for Wayland"; - homepage = "https://codeberg.org/dwl/dwl"; - platforms = lib.platforms.linux; - mainProgram = "dwl"; + postPatch = + let + configFile = + if lib.isDerivation configH || builtins.isPath configH then + configH + else + writeText "config.h" configH; + in + lib.optionalString withCustomConfigH "cp ${configFile} config.h"; + + makeFlags = [ + "PKG_CONFIG=${stdenv.cc.targetPrefix}pkg-config" + "WAYLAND_SCANNER=wayland-scanner" + "PREFIX=$(out)" + "MANDIR=$(man)/share/man" + ] + ++ lib.optionals enableXWayland [ + ''XWAYLAND="-DXWAYLAND"'' + ''XLIBS="xcb xcb-icccm"'' + ]; + + strictDeps = true; + + # required for whitespaces in makeFlags + __structuredAttrs = true; + + passthru = { + tests = { + version = testers.testVersion { + package = finalAttrs.finalPackage; + # `dwl -v` emits its version string to stderr and returns 1 + command = "dwl -v 2>&1; return 0"; + }; + basic = nixosTests.dwl; + }; }; - installPhase = '' - mkdir -p $out/ - cp dwl $out/ - ''; -} + meta = { + homepage = "https://codeberg.org/dwl/dwl"; + changelog = "https://codeberg.org/dwl/dwl/src/branch/${finalAttrs.version}/CHANGELOG.md"; + description = "Dynamic window manager for Wayland"; + longDescription = '' + dwl is a compact, hackable compositor for Wayland based on wlroots. It is + intended to fill the same space in the Wayland world that dwm does in X11, + primarily in terms of philosophy, and secondarily in terms of + functionality. Like dwm, dwl is: + + - Easy to understand, hack on, and extend with patches + - One C source file (or a very small number) configurable via config.h + - Tied to as few external dependencies as possible + ''; + license = lib.licenses.gpl3Only; + maintainers = [ ]; + inherit (wayland.meta) platforms; + mainProgram = "dwl"; + }; +})