Yazeed1s / zwm

X11 tiling window manager (work in progress)
BSD 2-Clause "Simplified" License
55 stars 1 forks source link

NixOS build using default.nix #8

Closed ClassickTech closed 1 day ago

ClassickTech commented 1 week ago

There are a few things not mentioned and changes needed to be made to build this on NixOS. So I am making this quick how to just in case any other Nix user has issues.

First create a default.nix file with the dependencies needed (i made mine in ~/.config/zwm/ directory):

{ pkgs ? import <nixpkgs> {} }:

pkgs.stdenv.mkDerivation {
  pname = "zwm";
  version = "0.1.0";

  src = pkgs.fetchFromGitHub {
    owner = "Yazeed1s";
    repo = "zwm";
    rev = "master";
    sha256 = "sha256-MACExlmIGluTsoZJDgvcUL4yyF2Z7RAKXgMWkoM6R9U=";
  };

  buildInputs = with pkgs; [
    xorg.libX11
    xorg.libxcb
    xorg.xcbutil
    xorg.xcbutilkeysyms
    xorg.xcbutilwm
    xorg.xcbutilcursor
    xorg.xorgproto
  ];

  nativeBuildInputs = with pkgs; [
    pkg-config
    gnumake
  ];

  makeFlags = [ "PREFIX=$(out)" ];

  patchPhase = ''
    substituteInPlace Makefile --replace "/usr/local" "$(PREFIX)"
    substituteInPlace Makefile --replace "/bin" "/bin"
  '';

  buildPhase = ''
    make CFLAGS="$CFLAGS -Wno-stringop-truncation"
  '';

  installPhase = ''
    mkdir -p $out/bin
    install -Dm755 zwm $out/bin/zwm
  '';

  meta = with pkgs.lib; {
    description = "zwm - a tiling window manager";
    homepage = "https://github.com/Yazeed1s/zwm";
    license = licenses.mit;
    platforms = platforms.linux;
  };
}

Build that: cd to that directory and "nix-build".

Now make this zwm.nix in /etc/nixos/:

{ config, lib, pkgs, ... }:

let
  zwm = pkgs.callPackage $HOME/.config/zwm/default.nix {};
in
{
  options = {
    services.zwm = {
      enable = lib.mkEnableOption "zwm window manager";
    };
  };

  config = lib.mkIf config.services.zwm.enable {
    environment.systemPackages = [ zwm ];

    services.xserver = {
      windowManager.session = lib.singleton {
        name = "zwm";
        start = ''
          ${zwm}/bin/zwm &
          waitPID=$!
        '';
      };
    };
  };
}

`
Then import the zwm.nix into your configuration.nix:
`{ config, pkgs, ... }:

{
  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
      ./zwm.nix
      `#`
  ];

Then sudo nixos-rebuild switch.

Now go to ~/.config/zwm and create .xinitrc file:

#!/usr/bin/env bash

userresources=$HOME/.Xresources
usermodmap=$HOME/.Xmodmap
sysresources=/run/current-system/sw/bin/xinit/.Xresources
sysmodmap=/run/current-system/sw/bin/xinit/.Xmodmap

# merge in defaults and keymaps
if [ -f $sysresources ]; then
    xrdb -merge $sysresources
fi

if [ -f $sysmodmap ]; then
    xmodmap $sysmodmap
fi

if [ -f "$userresources" ]; then
    xrdb -merge "$userresources"
fi

if [ -f "$usermodmap" ]; then
    xmodmap "$usermodmap"
fi

# start some nice programs
if [ -d /run/current-system/sw/bin/xinit/xinitrc.d ]; then
    for f in /run/current-system/sw/bin/xinit/xinitrc.d/?*.sh; do
        [ -x "$f" ] && . "$f"
    done
    unset f
fi

setxkbmap us &
nitrogen --restore &
xsetroot -cursor_name left_ptr &

exec ~/.config/zwm/result/bin/zwm

Now create a run.sh in the same directory:


#!/usr/bin/env bash

# The following command will run in a sandboxed zephyr Window. Run xrandr to get your optimal screen resolution and put it below:
startx ./.xinitrc -- /run/current-system/sw/bin/Xephyr -screen 1920x1080 -reset -core`

# The follwoing command will run as a full desktop window tiler. Uncomment the next line and comment the previous line... then run this script in tty:
#startx ./.xinitrc

Run the run.sh to start or bind it to a key.

A few notes as to why this is such a hard build and hopefully this will help you out:

I am a NixOS noob so this was a fun excersize to figure out and learn more how things work. I still have to figure out how to get it to show up as an option on LightGM login screen.

Yazeed1s commented 1 week ago

@ClassickTech Why is NixOS this complicated. I never used it but it seems like you guys do a lot of extra work to build packages. Regardless, I appreciate the effort put into this, if all this work without any issues, then I would suggest you 1- create a .md for it under zwm/docs 2- reference it in readme for NixOS users and 3- open a PR for it. Thanks again!

Yazeed1s commented 1 week ago

I'll leave this open anyway for NixOS users

ClassickTech commented 1 week ago

Yea it's pretty complicated but the pros outweigh the cons and the payoff is a thing of beauty ;).

Thanks for this. Working great so far.

I also fixed the formatting in my original comment. It was a mess. lol

ClassickTech commented 1 week ago

I think I found a bug. I finally got it to NOT run in a sandboxed Zephyr window by going to tty and running "startx ./.xinitrc ". The problem is, it treats all 3 of my monitors like one big window. Terminal opens up across all 3 monitors. So does firefox and so forth and so on. Arandr recognizes 3 monitors, but it doesn't help. Have you tried this using multiple monitors?

Yazeed1s commented 1 week ago

@ClassickTech As of now, multi-monitor support isn't implemented in ZWM. I have it on my list of tasks, i will start working on it soon.

ClassickTech commented 1 week ago

Ahhhh bummer. Guess I will just try it on my laptop!

Yazeed1s commented 1 week ago

@ClassickTech are you using nvidia gpu by any chance?

Yazeed1s commented 1 week ago

@ClassickTech zwm now supports multiple monitors. If you wanna try it out use the impl-multi-monitor branch. The PR is not merged to main yet, im still testing it out and fixing bugs along the way.

ClassickTech commented 1 day ago

@ClassickTech are you using nvidia gpu by any chance?

No I am not. Not a gamer and they just give way too many issues on Linux.

ClassickTech commented 1 day ago

@ClassickTech zwm now supports multiple monitors. If you wanna try it out use the impl-multi-monitor branch. The PR is not merged to main yet, im still testing it out and fixing bugs along the way.

Nice!

Yazeed1s commented 1 day ago

Multi-monitor support has been merged to main now. It should work on both nvidia and amd gpus.