From 54fef7aa7ea37672c0cab34e49fc98297640d1c8 Mon Sep 17 00:00:00 2001 From: Alexander Kobjolke Date: Sun, 10 Mar 2024 15:37:18 +0100 Subject: [PATCH 1/4] feat(home): Enable blueman-applet service --- home/alex/home.nix | 1 + home/alex/services/blueman-applet/default.nix | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 home/alex/services/blueman-applet/default.nix diff --git a/home/alex/home.nix b/home/alex/home.nix index 9c336be..9f68cc7 100644 --- a/home/alex/home.nix +++ b/home/alex/home.nix @@ -9,6 +9,7 @@ ./services/udiskie ./services/picom ./services/screen-locker + ./services/blueman-applet ]; home = { diff --git a/home/alex/services/blueman-applet/default.nix b/home/alex/services/blueman-applet/default.nix new file mode 100644 index 0000000..649ac05 --- /dev/null +++ b/home/alex/services/blueman-applet/default.nix @@ -0,0 +1,5 @@ +{ config, lib, pkgs, ... }: + +{ + config.services.blueman-applet = { enable = true; }; +} From f4bf5bda6e3a16be58003421782d312ac70185a7 Mon Sep 17 00:00:00 2001 From: Alexander Kobjolke Date: Mon, 11 Mar 2024 21:42:19 +0100 Subject: [PATCH 2/4] security: Move sudo configuration into module --- hosts/dregil/configuration.nix | 1 + hosts/thrall/default.nix | 13 +------------ modules/sudo.nix | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 modules/sudo.nix diff --git a/hosts/dregil/configuration.nix b/hosts/dregil/configuration.nix index d38e601..cd23964 100644 --- a/hosts/dregil/configuration.nix +++ b/hosts/dregil/configuration.nix @@ -17,6 +17,7 @@ in { ./hardware-configuration.nix # ../../modules/appimage.nix + ../../modules/sudo.nix ../../modules/wm/x.nix ../../modules/wm/xmonad/default.nix ]; diff --git a/hosts/thrall/default.nix b/hosts/thrall/default.nix index b55c64c..3eb7eb4 100644 --- a/hosts/thrall/default.nix +++ b/hosts/thrall/default.nix @@ -12,6 +12,7 @@ in { inputs.snm.nixosModule inputs.agenix.nixosModules.age ../../modules/security.nix + ../../modules/sudo.nix ../../modules/upgrade-pg-cluster.nix ../../modules/nix-config.nix ../../modules/iohk.nix @@ -110,18 +111,6 @@ in { defaults.email = "alex@jakalx.net"; }; - security.sudo = { - enable = true; - execWheelOnly = true; - extraRules = [{ - groups = [ "wheel" ]; - commands = [{ - command = "/run/current-system/sw/bin/nixos-rebuild"; - options = [ "NOPASSWD" ]; - }]; - }]; - }; - # Select internationalization properties. i18n.defaultLocale = "en_US.UTF-8"; console = { diff --git a/modules/sudo.nix b/modules/sudo.nix new file mode 100644 index 0000000..f2c4915 --- /dev/null +++ b/modules/sudo.nix @@ -0,0 +1,15 @@ +{ config, lib, pkgs, ... }: + +{ + config.security.sudo = { + enable = true; + execWheelOnly = true; + extraRules = [{ + groups = [ "wheel" ]; + commands = [{ + command = "/run/current-system/sw/bin/nixos-rebuild"; + options = [ "NOPASSWD" ]; + }]; + }]; + }; +} From fe6d16b2e6ca593c36d9a5ec661ec76d000249df Mon Sep 17 00:00:00 2001 From: Alexander Kobjolke Date: Mon, 11 Mar 2024 21:47:12 +0100 Subject: [PATCH 3/4] home: Configure xmonad via home-manager --- home/alex/home.nix | 1 + home/alex/programs/xmonad/config.hs | 146 ++++++++++++++++++++++++++ home/alex/programs/xmonad/default.nix | 9 ++ 3 files changed, 156 insertions(+) create mode 100644 home/alex/programs/xmonad/config.hs create mode 100644 home/alex/programs/xmonad/default.nix diff --git a/home/alex/home.nix b/home/alex/home.nix index 9f68cc7..e88d65b 100644 --- a/home/alex/home.nix +++ b/home/alex/home.nix @@ -4,6 +4,7 @@ imports = [ ./cli.nix ./programs/rofi + ./programs/xmonad ./services/polybar ./services/dunst ./services/udiskie diff --git a/home/alex/programs/xmonad/config.hs b/home/alex/programs/xmonad/config.hs new file mode 100644 index 0000000..7e262e6 --- /dev/null +++ b/home/alex/programs/xmonad/config.hs @@ -0,0 +1,146 @@ +import XMonad +import XMonad.Actions.CycleWS qualified as WS +import XMonad.Actions.Navigation2D (navigation2DP, windowGo, windowSwap) +import XMonad.Hooks.EwmhDesktops +import XMonad.Hooks.ManageDocks qualified as Docks +import XMonad.Hooks.ManageHelpers (doCenterFloat, doFullFloat, isDialog, isFullscreen) +import XMonad.Hooks.SetWMName +import XMonad.Layout.BinarySpacePartition +import XMonad.Layout.BorderResize (borderResize) +import XMonad.Layout.NoBorders (smartBorders) +import XMonad.Layout.ThreeColumns +import XMonad.Layout.ToggleLayouts (ToggleLayout (..), toggleLayouts) +import XMonad.ManageHook (doFloat) +import XMonad.StackSet as W +import XMonad.Util.EZConfig qualified as EZ +import XMonad.Util.NamedScratchpad +import XMonad.Util.Ungrab (unGrab) +import XMonad.Util.WorkspaceCompare qualified as WS + +import Control.Monad (when) +import Numeric.Natural +import System.Environment (getArgs) +import System.FilePath (()) +import System.Info (arch, os) +import System.Posix.Process (executeFile) +import Text.Printf (printf) + +compiledConfig = printf "xmonad-%s-%s" arch os + +compileRestart resume = do + dirs <- asks directories + whenX (recompile dirs True) $ do + when resume writeStateToFile + catchIO + ( do + args <- getArgs + executeFile (cacheDir dirs compiledConfig) False args Nothing + ) + +myLayout = smartBorders . borderResize . Docks.avoidStruts $ toggleLayouts emptyBSP Full + +main :: IO () +main = getDirectories >>= launch myConfig + +-- change size of window using direction so that it can be used together with the navigation2D function +-- see: similar to windowGo and windowSwap +windowMoveSplit :: Direction2D -> Bool -> X () +windowMoveSplit direction _ = sendMessage $ MoveSplit direction + +data VolumeCommand + = ToggleVolume + | LowerVolume Natural + | RaiseVolume Natural + +interpretVolumeCommand :: VolumeCommand -> String +interpretVolumeCommand command = "amixer -q set Master " <> cmd + where + cmd = case command of + ToggleVolume -> "toggle" + LowerVolume delta -> show delta <> "%-" + RaiseVolume delta -> show delta <> "%+" + +changeVolume :: VolumeCommand -> X () +changeVolume = spawn . interpretVolumeCommand + +myWorkspaceFilter :: X WS.WorkspaceSort +myWorkspaceFilter = do + sortXineramaAware <- WS.getSortByXineramaRule + pure $ sortXineramaAware . WS.filterOutWs [scratchpadWorkspaceTag] + +scratchpads = + [ NS + "notes" + "emacsclient -c -F '((name . \"gtd\"))'" + (resource =? "gtd") + doCenterFloat + , -- (customFloating $ W.RationalRect (1/6) (1/6) (2/3) (2/3)) + NS + "shell" + "alacritty --class scratchpad" + (resource =? "scratchpad") + (customFloating $ W.RationalRect (1 / 6) (1 / 6) (2 / 3) (2 / 3)) + ] + +myConfig = + addEwmhWorkspaceSort myWorkspaceFilter + . ewmhFullscreen + . ewmh + . Docks.docks + . nav + $ def + { modMask = mod4Mask -- Use Super instead of Alt + , terminal = "alacritty" + , layoutHook = myLayout + , handleEventHook = handleEventHook def <+> fullscreenEventHook + , -- this seems to be necessary to make java gui applications work :( + startupHook = ewmhDesktopsStartup >> setWMName "LG3D" + , manageHook = + mconcat + [ namedScratchpadManageHook scratchpads + , isDialog --> doFloat + , isFullscreen --> doFullFloat + , manageHook def + ] + } + `EZ.additionalKeysP` [ ("M-S-z", spawn "xscreensaver-command -lock") + , ("M-S-r", compileRestart True) + , ("M-S-q", restart "xmonad" True) + , ("M-C-s", unGrab *> spawn "scrot -s") + , ("M-b", sendMessage Docks.ToggleStruts) + , ("M-f", sendMessage (Toggle "Full")) + , ("M-p", spawn appLauncher) + , ("M-i", spawn passLauncher) + , ("M-w", kill) + , ("M-l", WS.toggleWS) + , ("M-g", WS.prevWS) + , ("M-r", WS.nextWS) + , -- scratchpads + ("M-s n", namedScratchpadAction scratchpads "notes") + , ("M-s s", namedScratchpadAction scratchpads "shell") + , -- backlight control + + ("", spawn "xbacklight -dec 5") + , ("", spawn "xbacklight -inc 5") + , ("", spawn "xbacklight -dec 5") + , ("", spawn "xbacklight -inc 5") + , -- volume control + + ("", changeVolume ToggleVolume) + , ("", changeVolume $ LowerVolume 5) + , ("", changeVolume $ RaiseVolume 5) + , ("M-a", sendMessage Balance) + , ("M-S-a", sendMessage Equalize) + , ("M-o", sendMessage Rotate) + ] + where + -- navigate using dvorak bindings + nav = navigation2DP def ("c", "h", "t", "n") [("M-", windowGo), ("M-C-", windowSwap), ("M-S-", windowMoveSplit)] True + appLauncher = "rofi -show combi -modes combi -combi-modes window,drun,run,ssh" + passLauncher = "rofi-pass" + +-- myManageHook :: ManageHook +-- myManageHook = composeAll +-- [ className =? "Gimp" --> doFloat +-- , isDialog --> doFloat +-- ] diff --git a/home/alex/programs/xmonad/default.nix b/home/alex/programs/xmonad/default.nix new file mode 100644 index 0000000..af59330 --- /dev/null +++ b/home/alex/programs/xmonad/default.nix @@ -0,0 +1,9 @@ +{ config, lib, pkgs, ... }: + +{ + config.xsession.windowManager.xmonad = { + enable = true; + enableContribAndExtras = true; + config = ./config.hs; + }; +} From a96bcaf989bbc6215d27ecae7d19b0a2bf7acb68 Mon Sep 17 00:00:00 2001 From: Alexander Kobjolke Date: Mon, 11 Mar 2024 22:13:32 +0100 Subject: [PATCH 4/4] home: Remove system-wide xmonad config --- home/alex/programs/xmonad/default.nix | 3 + modules/wm/xmonad/config.hs | 146 -------------------------- modules/wm/xmonad/default.nix | 5 - 3 files changed, 3 insertions(+), 151 deletions(-) delete mode 100644 modules/wm/xmonad/config.hs diff --git a/home/alex/programs/xmonad/default.nix b/home/alex/programs/xmonad/default.nix index af59330..486cc14 100644 --- a/home/alex/programs/xmonad/default.nix +++ b/home/alex/programs/xmonad/default.nix @@ -6,4 +6,7 @@ enableContribAndExtras = true; config = ./config.hs; }; + + # control backlight + config.home.packages = [ pkgs.xorg.xbacklight pkgs.scrot ]; } diff --git a/modules/wm/xmonad/config.hs b/modules/wm/xmonad/config.hs deleted file mode 100644 index 7e262e6..0000000 --- a/modules/wm/xmonad/config.hs +++ /dev/null @@ -1,146 +0,0 @@ -import XMonad -import XMonad.Actions.CycleWS qualified as WS -import XMonad.Actions.Navigation2D (navigation2DP, windowGo, windowSwap) -import XMonad.Hooks.EwmhDesktops -import XMonad.Hooks.ManageDocks qualified as Docks -import XMonad.Hooks.ManageHelpers (doCenterFloat, doFullFloat, isDialog, isFullscreen) -import XMonad.Hooks.SetWMName -import XMonad.Layout.BinarySpacePartition -import XMonad.Layout.BorderResize (borderResize) -import XMonad.Layout.NoBorders (smartBorders) -import XMonad.Layout.ThreeColumns -import XMonad.Layout.ToggleLayouts (ToggleLayout (..), toggleLayouts) -import XMonad.ManageHook (doFloat) -import XMonad.StackSet as W -import XMonad.Util.EZConfig qualified as EZ -import XMonad.Util.NamedScratchpad -import XMonad.Util.Ungrab (unGrab) -import XMonad.Util.WorkspaceCompare qualified as WS - -import Control.Monad (when) -import Numeric.Natural -import System.Environment (getArgs) -import System.FilePath (()) -import System.Info (arch, os) -import System.Posix.Process (executeFile) -import Text.Printf (printf) - -compiledConfig = printf "xmonad-%s-%s" arch os - -compileRestart resume = do - dirs <- asks directories - whenX (recompile dirs True) $ do - when resume writeStateToFile - catchIO - ( do - args <- getArgs - executeFile (cacheDir dirs compiledConfig) False args Nothing - ) - -myLayout = smartBorders . borderResize . Docks.avoidStruts $ toggleLayouts emptyBSP Full - -main :: IO () -main = getDirectories >>= launch myConfig - --- change size of window using direction so that it can be used together with the navigation2D function --- see: similar to windowGo and windowSwap -windowMoveSplit :: Direction2D -> Bool -> X () -windowMoveSplit direction _ = sendMessage $ MoveSplit direction - -data VolumeCommand - = ToggleVolume - | LowerVolume Natural - | RaiseVolume Natural - -interpretVolumeCommand :: VolumeCommand -> String -interpretVolumeCommand command = "amixer -q set Master " <> cmd - where - cmd = case command of - ToggleVolume -> "toggle" - LowerVolume delta -> show delta <> "%-" - RaiseVolume delta -> show delta <> "%+" - -changeVolume :: VolumeCommand -> X () -changeVolume = spawn . interpretVolumeCommand - -myWorkspaceFilter :: X WS.WorkspaceSort -myWorkspaceFilter = do - sortXineramaAware <- WS.getSortByXineramaRule - pure $ sortXineramaAware . WS.filterOutWs [scratchpadWorkspaceTag] - -scratchpads = - [ NS - "notes" - "emacsclient -c -F '((name . \"gtd\"))'" - (resource =? "gtd") - doCenterFloat - , -- (customFloating $ W.RationalRect (1/6) (1/6) (2/3) (2/3)) - NS - "shell" - "alacritty --class scratchpad" - (resource =? "scratchpad") - (customFloating $ W.RationalRect (1 / 6) (1 / 6) (2 / 3) (2 / 3)) - ] - -myConfig = - addEwmhWorkspaceSort myWorkspaceFilter - . ewmhFullscreen - . ewmh - . Docks.docks - . nav - $ def - { modMask = mod4Mask -- Use Super instead of Alt - , terminal = "alacritty" - , layoutHook = myLayout - , handleEventHook = handleEventHook def <+> fullscreenEventHook - , -- this seems to be necessary to make java gui applications work :( - startupHook = ewmhDesktopsStartup >> setWMName "LG3D" - , manageHook = - mconcat - [ namedScratchpadManageHook scratchpads - , isDialog --> doFloat - , isFullscreen --> doFullFloat - , manageHook def - ] - } - `EZ.additionalKeysP` [ ("M-S-z", spawn "xscreensaver-command -lock") - , ("M-S-r", compileRestart True) - , ("M-S-q", restart "xmonad" True) - , ("M-C-s", unGrab *> spawn "scrot -s") - , ("M-b", sendMessage Docks.ToggleStruts) - , ("M-f", sendMessage (Toggle "Full")) - , ("M-p", spawn appLauncher) - , ("M-i", spawn passLauncher) - , ("M-w", kill) - , ("M-l", WS.toggleWS) - , ("M-g", WS.prevWS) - , ("M-r", WS.nextWS) - , -- scratchpads - ("M-s n", namedScratchpadAction scratchpads "notes") - , ("M-s s", namedScratchpadAction scratchpads "shell") - , -- backlight control - - ("", spawn "xbacklight -dec 5") - , ("", spawn "xbacklight -inc 5") - , ("", spawn "xbacklight -dec 5") - , ("", spawn "xbacklight -inc 5") - , -- volume control - - ("", changeVolume ToggleVolume) - , ("", changeVolume $ LowerVolume 5) - , ("", changeVolume $ RaiseVolume 5) - , ("M-a", sendMessage Balance) - , ("M-S-a", sendMessage Equalize) - , ("M-o", sendMessage Rotate) - ] - where - -- navigate using dvorak bindings - nav = navigation2DP def ("c", "h", "t", "n") [("M-", windowGo), ("M-C-", windowSwap), ("M-S-", windowMoveSplit)] True - appLauncher = "rofi -show combi -modes combi -combi-modes window,drun,run,ssh" - passLauncher = "rofi-pass" - --- myManageHook :: ManageHook --- myManageHook = composeAll --- [ className =? "Gimp" --> doFloat --- , isDialog --> doFloat --- ] diff --git a/modules/wm/xmonad/default.nix b/modules/wm/xmonad/default.nix index dab287a..05ae3d3 100644 --- a/modules/wm/xmonad/default.nix +++ b/modules/wm/xmonad/default.nix @@ -8,14 +8,9 @@ windowManager.xmonad = { enable = true; enableContribAndExtras = true; - config = ./config.hs; - extraPackages = hp: [ hp.dbus hp.monad-logger hp.xmonad-contrib ]; }; }; }; - # control backlight - config.environment.systemPackages = [ pkgs.xorg.xbacklight pkgs.scrot ]; - config.systemd.services.upower.enable = true; }