From 556c51df188a37ab140935ce4930209da3d8719b Mon Sep 17 00:00:00 2001 From: Stefan Ellmauthaler Date: Tue, 9 May 2023 12:31:41 +0200 Subject: [PATCH] Add Xmonad options and base config in homemanager --- modules/graphical.nix | 15 +++--- modules/xmonad.nix | 22 ++++++++ users/ellmau/conf/xmonad/flake.nix | 47 +++++++++++++++++ users/ellmau/conf/xmonad/xmonad.hs | 81 ++++++++++++++++++++++++++++++ 4 files changed, 159 insertions(+), 6 deletions(-) create mode 100644 modules/xmonad.nix create mode 100644 users/ellmau/conf/xmonad/flake.nix create mode 100644 users/ellmau/conf/xmonad/xmonad.hs diff --git a/modules/graphical.nix b/modules/graphical.nix index 0a04e23..746544a 100644 --- a/modules/graphical.nix +++ b/modules/graphical.nix @@ -21,6 +21,8 @@ with lib; { DPI setting for the xserver ''; }; + xserver.enable = mkEnableOption "enable X server"; + xmonad.enable = mkEnableOption "enable xmonad"; i3.enable = mkEnableOption "enable i3"; }; config = let @@ -39,21 +41,20 @@ with lib; { }; in mkIf cfg.enable { - elss.users.x11.enable = - if cfg.i3.enable - then true - else false; + # cfg.xserver.enable = cfg.i3.enable; + elss.users.x11.enable = cfg.xserver.enable || cfg.xmonad.enable; + elss.networking.useNetworkManager = true; services = { - xserver = mkIf cfg.i3.enable { + xserver = mkIf cfg.xserver.enable { enable = true; dpi = cfg.dpi; displayManager.lightdm = { enable = true; greeters.gtk.cursorTheme.size = cfg.greeterCursorsize; }; - windowManager.i3 = { + windowManager.i3 = mkIf cfg.i3.enable { enable = true; extraPackages = with pkgs; [ rofi # launcher @@ -81,6 +82,8 @@ with lib; { bluetooth.enable = true; }; + security.pam.services.lightdm.enableGnomeKeyring = true; + services.blueman.enable = true; environment.systemPackages = with pkgs; [ diff --git a/modules/xmonad.nix b/modules/xmonad.nix new file mode 100644 index 0000000..a80243a --- /dev/null +++ b/modules/xmonad.nix @@ -0,0 +1,22 @@ +{ + config, + pkgs, + lib, + ... +}: +with lib; { + config = let + cfg = config.elss.graphical.xmonad; + in + mkIf cfg.enable { + elss.graphical.xserver.enable = true; + services = { + xserver = { + windowManager.xmonad = { + enable = true; + enableContribAndExtras = true; + }; + }; + }; + }; +} diff --git a/users/ellmau/conf/xmonad/flake.nix b/users/ellmau/conf/xmonad/flake.nix new file mode 100644 index 0000000..661851d --- /dev/null +++ b/users/ellmau/conf/xmonad/flake.nix @@ -0,0 +1,47 @@ +{ + description = "basic tool setup flake"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.11"; + nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + flake-utils-plus.url = "github:gytis-ivaskevicius/flake-utils-plus"; + }; + + outputs = { + self, + nixpkgs, + nixpkgs-unstable, + flake-utils, + flake-utils-plus, + ... + } @ inputs: + {} + // (flake-utils.lib.eachDefaultSystem ( + system: let + unstable = import nixpkgs-unstable { + inherit system; + }; + pkgs = import nixpkgs { + inherit system; + }; + in rec { + devShell = pkgs.mkShell { + name = "xmonad"; + nativeBuildInputs = [ + # add packages here, like + # pkgs.clingo + (pkgs.ghc.withPackages + (haskellPackages: [ + haskellPackages.dbus + haskellPackages.monad-logger + haskellPackages.hostname + haskellPackages.xmonad + haskellPackages.xmonad-contrib + ])) + pkgs.haskell-language-server + ]; + }; + } + )); +} diff --git a/users/ellmau/conf/xmonad/xmonad.hs b/users/ellmau/conf/xmonad/xmonad.hs new file mode 100644 index 0000000..38e69cc --- /dev/null +++ b/users/ellmau/conf/xmonad/xmonad.hs @@ -0,0 +1,81 @@ +module Main where + +import Data.Ratio +import XMonad hiding ((|||)) +import XMonad.Hooks.FadeInactive +import XMonad.Hooks.FadeWindows +import XMonad.Hooks.EwmhDesktops +import XMonad.Hooks.ManageDocks +import XMonad.Hooks.ManageHelpers +import XMonad.Hooks.StatusBar +import XMonad.Util.EZConfig +import Network.HostName (getHostName) +-- Imports for Polybar -- +import qualified Codec.Binary.UTF8.String as UTF8 +import qualified DBus as D +import qualified DBus.Client as D +import XMonad.Hooks.DynamicLog + +main :: IO () +main' :: D.Client -> IO () +main = mkDbusClient >>= main' + +main' dbus = do + hostname <- io $ getHostName + xmonad . docks . ewmhFullscreen . ewmh $ def + { terminal = "alacritty" + , logHook = polybarLogHook dbus + } + +mkDbusClient :: IO D.Client +mkDbusClient = do + dbus <- D.connectSession + D.requestName dbus (D.busName_ "org.xmonad.log") opts + return dbus + where + opts = [D.nameAllowReplacement, D.nameReplaceExisting, D.nameDoNotQueue] + +-- Emit a DBus signal on log updates +dbusOutput :: D.Client -> String -> IO () +dbusOutput dbus str = + let opath = D.objectPath_ "/org/xmonad/Log" + iname = D.interfaceName_ "org.xmonad.Log" + mname = D.memberName_ "Update" + signal = D.signal opath iname mname + body = [D.toVariant $ UTF8.decodeString str] + in D.emit dbus $ signal { D.signalBody = body } + +polybarHook :: D.Client -> PP +polybarHook dbus = + let wrapper c s | s /= "NSP" = wrap ("%{F" <> c <> "} ") " %{F-}" s + | otherwise = mempty + blue = "#2E9AFE" + gray = "#7F7F7F" + orange = "#ea4300" + purple = "#9058c7" + red = "#722222" + in def { ppOutput = dbusOutput dbus + , ppCurrent = wrapper blue + , ppVisible = wrapper gray + , ppUrgent = wrapper orange + , ppHidden = wrapper gray + , ppHiddenNoWindows = wrapper red + , ppTitle = shorten 100 . wrapper purple + } + +fadeHook :: Rational -> Rational -> X () +fadeHook act inact = fadeOutLogHook $ fadeAllBut exceptions act inact + where exceptions = isFullscreen + <||> className =? "firefox" + <||> className =? "Chromium-browser" + +fadeAllBut :: Query Bool -> Rational -> Rational -> Query Rational +fadeAllBut qry amt inact = do isInactive <- isUnfocused + isQry <- qry + if isQry + then return 1 + else if isInactive + then return inact + else return amt + +polybarLogHook dbus = fadeHook 0.95 0.75 <+> dynamicLogWithPP (polybarHook dbus) \ No newline at end of file