Redo xmonad config, allows for new packages and LSP

Signed-off-by: MagicRB <richard@brezak.sk>
This commit is contained in:
MagicRB 2023-10-03 16:54:07 +02:00
parent 580fec0979
commit 05d186d304
No known key found for this signature in database
GPG key ID: 08D5287CC5DDCA0E
16 changed files with 441 additions and 124 deletions

View file

@ -199,14 +199,58 @@
matlab;
};
devShells.default = pkgs.mkShell {
devShells.default =
let
unpackSrc = package: pkgs.stdenv.mkDerivation {
pname = package.pname;
version = package.version;
src = package.src;
phases = [ "unpackPhase" "installPhase" ];
installPhase = ''
mkdir $out
cp -r . $out
'';
};
prepareDeps = pkgs.writeShellScript "prepare-deps.sh" ''
cd "$(git rev-parse --show-toplevel)/home-manager/modules/xmonad"
mkdir -p .packages
_rsync_args=("--no-perms" "--no-owner" "--no-group" "--del" "--exclude=.stack-work" "--chmod=ugo=rwX" "-crvP")
rsync "''${_rsync_args[@]}" ${unpackSrc pkgs.haskell.packages.ghc946.xmonad}/. .packages/xmonad >/dev/null 2>&1
rsync "''${_rsync_args[@]}" ${unpackSrc pkgs.haskell.packages.ghc946.xmonad-contrib}/. .packages/xmonad-contrib >/dev/null 2>&1
rsync "''${_rsync_args[@]}" ${unpackSrc pkgs.haskell.packages.ghc946.xmobar}/. .packages/xmobar >/dev/null 2>&1
'';
stack-wrapped = pkgs.symlinkJoin {
name = "stack"; # will be available as the usual `stack` in terminal
paths = [ pkgs.stack ];
buildInputs = [ pkgs.makeWrapper ];
postBuild = ''
wrapProgram $out/bin/stack \
--run "${prepareDeps}"\
--add-flags "\
--no-nix \
--system-ghc \
--no-install-ghc \
"
'';
};
in
pkgs.mkShell {
nativeBuildInputs = with pkgs; [
(pkgs.writeShellScriptBin "update-secret" ''
nix flake lock --update-input secret
'')
nil
nomad consul vault
];
haskell.compiler.ghc946
stack-wrapped
pkg-config
haskell.packages.ghc946.haskell-language-server
] ++ (lib.foldl (acc: x: acc ++ x) [] (map (x: pkgs.haskell.packages.ghc946.${x}.buildInputs) [ "gi-pangocairo" "X11" "cairo" "glib" ]));
};
};

View file

@ -0,0 +1,2 @@
.packages
.stack-work

View file

@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain

View file

@ -21,6 +21,7 @@ import Data.Maybe
import Data.Function
import Data.Functor
import System.Exit
import System.Environment
import XMonad.Util.EZConfig
import XMonad.Util.SpawnOnce
import XMonad.Util.WindowProperties
@ -68,7 +69,7 @@ myKeymap c =
[ ("M-S-<Return>", spawn "alacritty")
-- launch dmenu
, ("M-e", spawn "@dmenu_run@")
, ("M-e", spawn "dmenu_run")
-- close focused window
, ("M-S-q", io (exitWith ExitSuccess))
@ -121,9 +122,9 @@ myKeymap c =
, ("M-d", warpToWindow 0.5 0.5)
-- , ("M-b", spawn ("pkill xmobar && " ++ xmobarCmd))
, ("<Print>", spawn "sleep 0.1 ; @screenshot@ select")
, ("S-<Print>", spawn "@screenshot@ screen && sleep 0.1 && @notify@ -t 5000 \"snap\"")
, ("C-S-<Print>", spawn "@screenshot@ focused && sleep 0.1 && @notify@ -t 5000 \"snap\"")
, ("<Print>", spawn "sleep 0.1 ; screenshot select")
, ("S-<Print>", spawn "screenshot screen && sleep 0.1 && notify -t 5000 \"snap\"")
, ("C-S-<Print>", spawn "screenshot focused && sleep 0.1 && notify -t 5000 \"snap\"")
-- Toggle the status bar gap
-- Use this binding with avoidStruts from Hooks.ManageDocks.
@ -135,7 +136,7 @@ myKeymap c =
, ("M-S-k", kill)
-- Restart xmonad
, ("M-k", spawn "@reload@")
, ("M-k", spawn "reload")
-- float keys
, ("M-g", withFocused (keysResizeWindow (-10, 0) (0, 0)))
@ -152,17 +153,17 @@ myKeymap c =
, ("<XF86AudioMute>" , spawn "wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle")
, ("<XF86AudioRaiseVolume>" , spawn "wpctl set-volume -l 1.5 @DEFAULT_AUDIO_SINK@ 5%+")
, ("<XF86AudioLowerVolume>" , spawn "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-")
, ("<XF86MonBrightnessUp>" , spawn "@brightnessctl@ set +5%")
, ("<XF86MonBrightnessDown>" , spawn "@brightnessctl@ set 5%-")
, ("<XF86MonBrightnessUp>" , spawn "brightnessctl set +5%")
, ("<XF86MonBrightnessDown>" , spawn "brightnessctl set 5%-")
, ("<XF86AudioPlay>" , spawn "@notify@ -t 5000 \"Music: Play\"" >> spawn "@playerctl@ play-pause")
, ("<XF86AudioStop>" , spawn "@notify@ -t 5000 \"Music: Stop\"" >> spawn "@playerctl@ stop")
, ("<XF86AudioPrev>" , spawn "@notify@ -t 5000 \"Music: Prev\"" >> spawn "@playerctl@ previous")
, ("<XF86AudioNext>" , spawn "@notify@ -t 5000 \"Music: Next\"" >> spawn "@playerctl@ next")
, ("<XF86AudioPlay>" , spawn "notify -t 5000 \"Music: Play\"" >> spawn "playerctl play-pause")
, ("<XF86AudioStop>" , spawn "notify -t 5000 \"Music: Stop\"" >> spawn "playerctl stop")
, ("<XF86AudioPrev>" , spawn "notify -t 5000 \"Music: Prev\"" >> spawn "playerctl previous")
, ("<XF86AudioNext>" , spawn "notify -t 5000 \"Music: Next\"" >> spawn "playerctl next")
, ("<XF86TouchpadToggle>" , spawn "@toggle_touchpad@")
, ("<XF86TouchpadToggle>" , spawn "toggle-touchpad")
, ("M-<F1>", spawn "@auxmenu@")
, ("M-<F1>", spawn "auxmenu")
, ("M-<F11>", withDisplay $ \dpy -> withFocused $ \win -> do
wmstate <- getAtom "_NET_WM_STATE"
@ -262,7 +263,7 @@ myPP = def
}
spawnBar :: ScreenId -> IO StatusBarConfig
spawnBar screen = pure $ statusBarPropTo ("_XMONAD_LOG_" <> screenString ) ("@polybar@ " <> screenString) (pure myPP)
spawnBar screen = pure $ statusBarPropTo ("_XMONAD_LOG_" <> screenString ) ("polybar-mm " <> screenString) (pure myPP)
where screenString = show (fromIntegral screen :: Int)
------------------------------------------------------------------------
@ -272,6 +273,7 @@ spawnBar screen = pure $ statusBarPropTo ("_XMONAD_LOG_" <> screenString ) ("@po
--
-- main = xmonad $ ewmh $ docks $ defaults
main = do
getEnv "PATH" >>= \path -> setEnv "PATH" (path <> ":/home/main/.xmonad/runenv/bin")
pure defaults <&> dynamicSBs spawnBar <&> docks >>= xmonad
getNetWMState :: Window -> X [Atom]

View file

@ -1,105 +1,50 @@
{ pkgs, lib, ... }:
{ pkgs, lib, inputs', ... }:
{
home.file.".xmonad/xmonad.hs".source = pkgs.writeSubstitutedFile {
name = "xmonad.hs";
file = ./xmonad.hs;
substitutes = {
"brightnessctl" = lib.getExe pkgs.brightnessctl;
"playerctl" = lib.getExe pkgs.playerctl;
"dmenu_run" = "${pkgs.dmenu}/bin/dmenu_run";
"polybar" = pkgs.writeShellScript "polybar"
''
export PATH=${lib.makeBinPath [ pkgs.polybarFull ]}:$PATH
monitors=$(polybar --list-monitors | cut -f 1 -d':' | tr '\n' ' ')
monitors=($monitors)
MONITOR=''${monitors[$1]} polybar -c ${./polybar.ini} top
home.file.".xmonad/build".executable = true;
home.file.".xmonad/build".text = ''
#!/usr/bin/env bash
cd ~/dotfiles/home-manager/modules/xmonad
eval "$(direnv export bash)"
stack build
rm "$1"
cp "$(stack path --local-install-root)/bin/xmonad-exe" "$1"
'';
"reload" = pkgs.writeShellScript "xmonad-reload"
''
${lib.getExe pkgs.libnotify} -t 5000 "recompiling xmonad"
if xmonad --recompile
then
${lib.getExe pkgs.libnotify} -t 5000 "compilation succeeded"
xmonad --restart
else
${lib.getExe pkgs.libnotify} -t 5000 "compilation failed"
fi
'';
"toggle_touchpad" = pkgs.writeShellScript "toggle-touchpad"
''
read TPdevice <<< $( xinput | sed -nre '/TouchPad|Touchpad/s/.*id=([0-9]*).*/\1/p' )
state=$( xinput list-props "$TPdevice" | grep "Device Enabled" | grep -o "[01]$" )
if [ "$state" -eq '1' ];then
xinput --disable "$TPdevice" && notify-send -i emblem-nowrite "Touchpad" "Disabled"
else
xinput --enable "$TPdevice" && notify-send -i emblem-nowrite "Touchpad" "Enabled"
fi
'';
"auxmenu" = pkgs.writeShellScript "auxmenu"
''
export SUDO_ASKPASS=${pkgs.x11_ssh_askpass}/libexec/x11-ssh-askpass
_options="toggle-mic\ntoggle-wifi\ntoggle-bluetooth\nscreenshot-all\nscreenshot-select\nscreenshot-focused\nsuspend\nreboot\nkexec\npoweroff\nlogout\nnmtui"
_option="$(echo -e $_options | emacs-rofi "command: " 90 30 | awk '{print $1}' | tr -d '\r\n')"
if [ ''${#_option} -gt 0 ]
then
case $_option in
toggle-mic)
wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle
;;
toggle-wifi)
if [ "$(nmcli radio wifi)" = "enabled" ]
then
nmcli radio wifi off
else
nmcli radio wifi on
fi
;;
toggle-bluetooth)
if [ "$(nmcli radio wifi)" = "enabled" ]
then
nmcli radio wifi off
else
nmcli radio wifi on
fi
;;
screenshot-all)
${lib.getExe pkgs.magic-screenshot} screen
;;
screenshot-select)
${lib.getExe pkgs.magic-screenshot} select
;;
screenshot-focused)
${lib.getExe pkgs.magic-screenshot} focused
;;
suspend)
systemctl suspend
;;
reboot)
systemctl reboot
;;
poweroff)
systemctl poweroff
;;
kexec)
sudo -A kexec -l /run/current-system/kernel --initrd=/run/current-system/initrd --reuse-cmdline
systemctl kexec
;;
logout)
loginctl terminate-session $XDG_SESSION_ID
;;
nmtui)
alacritty -e nmtui
;;
*)
;;
esac
fi
'';
home.file.".xmonad/buildenv".source =
pkgs.buildEnv {
name = "xmonad-buildenv";
ignoreCollisions = true;
paths = inputs'.self.devShells.${pkgs.stdenv.system}.default.nativeBuildInputs;
};
home.file.".xmonad/runenv".source =
let
polybar-mm =
pkgs.writeShellScriptBin "polybar-mm"
(builtins.readFile ./scripts/polybar-mm.sh);
reload =
pkgs.writeShellScriptBin "xmonad-reload"
(builtins.readFile ./scripts/polybar-mm.sh);
toggle-touchpad =
pkgs.writeShellScriptBin "toggle-touchpad"
(builtins.readFile ./scripts/toggle-touchpad.sh);
auxmenu =
pkgs.writeShellScriptBin "auxmenu"
(builtins.readFile ./scripts/auxmenu.sh);
in
pkgs.buildEnv {
name = "xmonad-runenv";
paths = with pkgs; [
brightnessctl
playerctl
dmenu
polybar-mm
polybar
reload
toggle-touchpad
auxmenu
libnotify
x11_ssh_askpass
];
};
}

View file

@ -0,0 +1,10 @@
cradle:
stack:
- path: "./src"
component: "xmonad-config:lib"
- path: "./app/Main.hs"
component: "xmonad-config:exe:xmonad-exe"
- path: "./test"
component: "xmonad-config:test:xmonad-test"

View file

@ -0,0 +1,64 @@
name: xmonad-config
version: 0.1.0.0
github: "githubuser/xmonad"
license: BSD-3-Clause
author: "Author name here"
maintainer: "example@example.com"
copyright: "2023 Author name here"
extra-source-files:
- README.md
- CHANGELOG.md
# Metadata used when publishing your package
# synopsis: Short description of your package
# category: Web
# To avoid duplicated efforts in documentation and dealing with the
# complications of embedding Haddock markup inside cabal files, it is
# common to point users to the README.md file.
description: Please see the README on GitHub at <https://github.com/githubuser/xmonad#readme>
dependencies:
- base >= 4.7 && < 5
- containers
- text
- xmobar
- xmonad
- xmonad-contrib
ghc-options:
- -Wall
- -Wcompat
- -Widentities
- -Wincomplete-record-updates
- -Wincomplete-uni-patterns
- -Wmissing-export-lists
- -Wmissing-home-modules
- -Wpartial-fields
- -Wredundant-constraints
library:
source-dirs: src
executables:
xmonad-exe:
main: Main.hs
source-dirs: app
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- xmonad-config
tests:
xmonad-test:
main: Spec.hs
source-dirs: test
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- xmonad

View file

@ -0,0 +1,59 @@
export SUDO_ASKPASS=/home/main/.xmonad/runenv/libexec/x11-ssh-askpass
_options="toggle-mic\ntoggle-wifi\ntoggle-bluetooth\nscreenshot-all\nscreenshot-select\nscreenshot-focused\nsuspend\nreboot\nkexec\npoweroff\nlogout\nnmtui"
_option="$(echo -e $_options | emacs-rofi "command: " 90 30 | awk '{print $1}' | tr -d '\r\n')"
if [ ''${#_option} -gt 0 ]
then
case $_option in
toggle-mic)
wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle
;;
toggle-wifi)
if [ "$(nmcli radio wifi)" = "enabled" ]
then
nmcli radio wifi off
else
nmcli radio wifi on
fi
;;
toggle-bluetooth)
if [ "$(nmcli radio wifi)" = "enabled" ]
then
nmcli radio wifi off
else
nmcli radio wifi on
fi
;;
screenshot-all)
screenshot screen
;;
screenshot-select)
screenshot select
;;
screenshot-focused)
screenshot focused
;;
suspend)
systemctl suspend
;;
reboot)
systemctl reboot
;;
poweroff)
systemctl poweroff
;;
kexec)
sudo -A kexec -l /run/current-system/kernel --initrd=/run/current-system/initrd --reuse-cmdline
systemctl kexec
;;
logout)
loginctl terminate-session $XDG_SESSION_ID
;;
nmtui)
alacritty -e nmtui
;;
*)
;;
esac
fi

View file

@ -0,0 +1,3 @@
monitors=$(polybar --list-monitors | cut -f 1 -d':' | tr '\n' ' ')
monitors=($monitors)
MONITOR=''${monitors[$1]} polybar -c /home/main/dotfiles/home-manager/modules/xmonad/polybar.ini top

View file

@ -0,0 +1,8 @@
read TPdevice <<< $( xinput | sed -nre '/TouchPad|Touchpad/s/.*id=([0-9]*).*/\1/p' )
state=$( xinput list-props "$TPdevice" | grep "Device Enabled" | grep -o "[01]$" )
if [ "$state" -eq '1' ];then
xinput --disable "$TPdevice" && notify-send -i emblem-nowrite "Touchpad" "Disabled"
else
xinput --enable "$TPdevice" && notify-send -i emblem-nowrite "Touchpad" "Enabled"
fi

View file

@ -0,0 +1,9 @@
notify-send -t 5000 "recompiling xmonad"
if xmonad --recompile
then
notify-send -t 5000 "compilation succeeded"
xmonad --restart
else
notify-send -t 5000 "compilation failed"
fi

View file

@ -0,0 +1,6 @@
module Lib
( someFunc
) where
someFunc :: IO ()
someFunc = putStrLn "someFunc"

View file

@ -0,0 +1,69 @@
# This file was automatically generated by 'stack init'
#
# Some commonly used options have been documented as comments in this file.
# For advanced use and comprehensive documentation of the format, please see:
# https://docs.haskellstack.org/en/stable/yaml_configuration/
# Resolver to choose a 'specific' stackage snapshot or a compiler version.
# A snapshot resolver dictates the compiler version and the set of packages
# to be used for project dependencies. For example:
#
# resolver: lts-3.5
# resolver: nightly-2015-09-21
# resolver: ghc-7.10.2
#
# The location of a snapshot can be provided as a file or url. Stack assumes
# a snapshot provided as a file might change, whereas a url resource does not.
#
# resolver: ./custom-snapshot.yaml
# resolver: https://example.com/snapshots/2018-01-01.yaml
resolver: lts-21.11
# User packages to be built.
# Various formats can be used as shown in the example below.
#
# packages:
# - some-directory
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
# subdirs:
# - auto-update
# - wai
packages:
- .
# Dependency packages to be pulled from upstream that are not in the resolver.
# These entries can reference officially published versions as well as
# forks / in-progress versions pinned to a git hash. For example:
#
extra-deps:
- .packages/xmobar
- .packages/xmonad-contrib
- .packages/xmonad
#
# extra-deps: []
# Override default flag values for local packages and extra-deps
flags:
# xmobar:
# all_extensions: true
# Extra package databases containing global packages
# extra-package-dbs: []
# Control whether we use the GHC we find on the path
# system-ghc: true
#
# Require a specific version of Stack, using version ranges
# require-stack-version: -any # Default
# require-stack-version: ">=2.11"
#
# Override the architecture used by Stack, especially useful on Windows
# arch: i386
# arch: x86_64
#
# Extra directories used by Stack for building
# extra-include-dirs: [/path/to/dir]
# extra-lib-dirs: [/path/to/dir]
#
# Allow a newer minor version of GHC than the snapshot specifies
# compiler-check: newer-minor
allow-newer: true

View file

@ -0,0 +1,12 @@
# This file was autogenerated by Stack.
# You should not edit this file by hand.
# For more information, please see the documentation at:
# https://docs.haskellstack.org/en/stable/lock_files
packages: []
snapshots:
- completed:
sha256: 64d66303f927e87ffe6b8ccf736229bf608731e80d7afdf62bdd63c59f857740
size: 640037
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/11.yaml
original: lts-21.11

View file

@ -0,0 +1,2 @@
main :: IO ()
main = putStrLn "Test suite not yet implemented"

View file

@ -0,0 +1,80 @@
cabal-version: 2.2
-- This file has been generated from package.yaml by hpack version 0.35.2.
--
-- see: https://github.com/sol/hpack
name: xmonad-config
version: 0.1.0.0
description: Please see the README on GitHub at <https://github.com/githubuser/xmonad#readme>
homepage: https://github.com/githubuser/xmonad#readme
bug-reports: https://github.com/githubuser/xmonad/issues
author: Author name here
maintainer: example@example.com
copyright: 2023 Author name here
license: BSD-3-Clause
build-type: Simple
extra-source-files:
README.md
CHANGELOG.md
source-repository head
type: git
location: https://github.com/githubuser/xmonad
library
exposed-modules:
Lib
other-modules:
Paths_xmonad_config
autogen-modules:
Paths_xmonad_config
hs-source-dirs:
src
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints
build-depends:
base >=4.7 && <5
, containers
, text
, xmobar
, xmonad
, xmonad-contrib
default-language: Haskell2010
executable xmonad-exe
main-is: Main.hs
other-modules:
Paths_xmonad_config
autogen-modules:
Paths_xmonad_config
hs-source-dirs:
app
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, containers
, text
, xmobar
, xmonad
, xmonad-config
, xmonad-contrib
default-language: Haskell2010
test-suite xmonad-test
type: exitcode-stdio-1.0
main-is: Spec.hs
other-modules:
Paths_xmonad_config
autogen-modules:
Paths_xmonad_config
hs-source-dirs:
test
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, containers
, text
, xmobar
, xmonad
, xmonad-contrib
default-language: Haskell2010