Skip to content

Commit

Permalink
haskellPackages.xmonad_0_17_0: respect NIX_GHC and XMONAD_XMESSAGE
Browse files Browse the repository at this point in the history
Adds xmonad-nix.patch adjusted for xmonad 0.17.0.

Originally posted here: https://discourse.nixos.org/t/use-latest-version-of-xmonad-0-17-0/16191/5

Co-Authored-By: ento <ping@stillspinning.cc>
Co-Authored-By: sternenseemann <sternenseemann@systemli.org>
  • Loading branch information
3 people committed Dec 1, 2021
1 parent c85d141 commit 36d5761
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkgs/development/haskell-modules/configuration-nix.nix
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ self: super: builtins.intersectAttrs super {

# Nix-specific workaround
xmonad = appendPatch ./patches/xmonad-nix.patch (dontCheck super.xmonad);
xmonad_0_17_0 = doDistribute (appendPatch ./patches/xmonad_0_17_0-nix.patch (super.xmonad_0_17_0));

# wxc supports wxGTX >= 3.0, but our current default version points to 2.8.
# http://hydra.cryp.to/build/1331287/log/raw
Expand Down
34 changes: 34 additions & 0 deletions pkgs/development/haskell-modules/patches/xmonad_0_17_0-nix.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
diff --git a/src/XMonad/Core.hs b/src/XMonad/Core.hs
index 46a0939..92af53d 100644
--- a/src/XMonad/Core.hs
+++ b/src/XMonad/Core.hs
@@ -46,6 +46,7 @@ import Data.Traversable (for)
import Data.Time.Clock (UTCTime)
import Data.Default.Class
import Data.List (isInfixOf)
+import System.Environment (lookupEnv)
import System.FilePath
import System.IO
import System.Info
@@ -458,7 +459,8 @@ xfork x = io . forkProcess . finally nullStdin $ do
-- | Use @xmessage@ to show information to the user.
xmessage :: MonadIO m => String -> m ()
xmessage msg = void . xfork $ do
- executeFile "xmessage" True
+ xmessageBin <- fromMaybe "xmessage" <$> liftIO (lookupEnv "XMONAD_XMESSAGE")
+ executeFile xmessageBin True
[ "-default", "okay"
, "-xrm", "*international:true"
, "-xrm", "*fontSet:-*-fixed-medium-r-normal-*-18-*-*-*-*-*-*-*,-*-fixed-*-*-*-*-18-*-*-*-*-*-*-*,-*-*-*-*-*-*-18-*-*-*-*-*-*-*"
@@ -654,8 +656,9 @@ compile dirs method =
bracket (openFile (errFileName dirs) WriteMode) hClose $ \err -> do
let run = runProc (cfgDir dirs) err
case method of
- CompileGhc ->
- run "ghc" ghcArgs
+ CompileGhc -> do
+ ghc <- fromMaybe "ghc" <$> (lookupEnv "NIX_GHC")
+ run ghc ghcArgs
CompileStackGhc stackYaml ->
run "stack" ["build", "--silent", "--stack-yaml", stackYaml] .&&.
run "stack" ("ghc" : "--stack-yaml" : stackYaml : "--" : ghcArgs)

4 comments on commit 36d5761

@liskin
Copy link

@liskin liskin commented on 36d5761 Jun 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This no longer applies to xmonad master since xmonad/xmonad@165e25f#diff-206141305e4cc4e20f2b6ee7b8b99b238c57cff3a9fa442848427958e4c64f63L48, can you folks please update the patch?

Alternatively, we might even accept such a change upstream, although we'd first need to understand under what circumstances these env vars can be set (not just in Nix, but in general).
Is there any precedent for any upstream carrying such a Nix-specific hack?

@sternenseemann
Copy link
Member

@sternenseemann sternenseemann commented on 36d5761 Jun 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The patch is intended for xmonad 0.17, so it doesn't really make sense for us to update it before the next release (or rather before the next release hits stackage).

NIX_GHC and related environment variables are set for synthesized ghcWithPackages environments which create an environment in which a specific GHC and a certain list of installed Haskell packages are available. NIX_GHC is used to let things that try to find the path / prefix of GHC know about the environment which is constructed by symlinking a lot of stuff into a new store path. Symlinking of course means that this environment path is not even known to GHC itself, hence the environment variable.

However, in the case of xmonad this is actually not needed / used in this way since xmonad just needs to find the ghc executable to call to recompile itself and NIX_GHC was probably used because the name was familiar:

--set NIX_GHC "${xmonadEnv}/bin/ghc" \
'' + ''
--set XMONAD_XMESSAGE "${pkgs.xorg.xmessage}/bin/xmessage"
'');

For nixpkgs it would be satisfactory if upstream xmonad could provide us with a way to set the path to the xmessage and ghc binaries called by xmonad via environment variables, e.g. XMONAD_XMESSAGE and XMONAD_GHC would be satisfactory. This is necessary because we can't necessarily (especially in the case of ghc) install them globally so that they are always available from PATH.

@slotThe
Copy link
Contributor

@slotThe slotThe commented on 36d5761 Aug 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sternenseemann

For nixpkgs it would be satisfactory if upstream xmonad could provide us with a way to set the path to the xmessage and ghc binaries called by xmonad via environment variables, e.g. XMONAD_XMESSAGE and XMONAD_GHC would be satisfactory. This is necessary because we can't necessarily (especially in the case of ghc) install them globally so that they are always available from PATH.

As of xmonad/xmonad@117583e we have done this now.

@sternenseemann
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's great, thanks! I'll see that the xmonad module in nixpkgs is adjusted as soon.

Please sign in to comment.