NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.81k stars 13.91k forks source link

Overriding gtk2hs-buildtools through overrides is not complete #48891

Open Fuuzetsu opened 5 years ago

Fuuzetsu commented 5 years ago

Issue description

I want to use a different version of gtk2hs-buildtools. However if I simply do

myPackages = haskellPackages.override { overrides = self: super: gtk2hs-buildtools = {…}; };

It does not override all the uses of gtk2hs-buildtools.

Notably in configuration-common.nix (and configuration-nix.nix) we can find the following lines:

  gio = disableHardening (addPkgconfigDepend (addBuildTool super.gio self.buildHaskellPackages.gtk2hs-buildtools) pkgs.glib) ["fortify"];
  glib = disableHardening (addPkgconfigDepend (addBuildTool super.glib self.buildHaskellPackages.gtk2hs-buildtools) pkgs.glib) ["fortify"];

These are pulled in by things such as gtk package. It appears to me that this is what uses the gtk2hs-buildtools from non-overriden package set.

Steps to reproduce

Override gtk2hs-buildtools to a different version through overrides. Depend on gtk Haskell package from that override package set. See both versions being pulled in.

Technical details

Please run nix-shell -p nix-info --run "nix-info -m" and paste the results.

Fuuzetsu commented 5 years ago

(is @peti still the person in charge of Haskell infra?)

guibou commented 5 years ago

I'm hitting the same issue. I solved it manually by removing gtk2hs-buildtools from the nativeBuildInputs. e.g.:

       hackGtk2Hs = p : p.overrideAttrs (oldAttrs: {
         nativeBuildInputs = (builtins.filter
                (p : 
                   !isNull p &&
                   (builtins.parseDrvName (p.name)).name != "gtk2hs-buildtools") 
                oldAttrs.nativeBuildInputs
            ) ++ [self.gtk2hs-buildtools];
       });

       glib = hackGtk2Hs (super.glib);
       gio = hackGtk2Hs super.gio;
       cairo = hackGtk2Hs super.cairo;
       pango = hackGtk2Hs super.pango;
jtojnar commented 5 years ago

Haskell attribute sets do not have overrideScope like sets created with makeScope do, but you can override the overrides argument of the compiler packages. See https://nixos.org/nixpkgs/manual/#how-to-override-package-versions-in-a-compiler-specific-package-set and https://nixos.org/nixpkgs/manual/#how-to-override-packages-in-all-compiler-specific-package-sets

neilmayhew commented 5 years ago

I solved it like this:

{
    haskellPackages = super.haskellPackages.override {
      overrides = self: hsuper: rec {
        gtk2hs-buildtools = overrideCabal hsuper.gtk2hs-buildtools (_: {
          patches = [
            ./patches/gtk2hs-buildtools/ghc-8.6.1.patch
          ];
        });
        buildHaskellPackages = hsuper.buildHaskellPackages // { inherit gtk2hs-buildtools; };
      };
    };
}

The patch I'm using is based on the one from @Fuuzetsu at https://github.com/gtk2hs/gtk2hs/issues/254. I'll attach it.

neilmayhew commented 5 years ago
diff --git a/c2hs/base/state/StateBase.hs b/c2hs/base/state/StateBase.hs
index aebd885..df50c77 100644
--- a/c2hs/base/state/StateBase.hs
+++ b/c2hs/base/state/StateBase.hs
@@ -58,6 +58,7 @@ where

 import Control.Applicative (Applicative(..))
 import Control.Monad (liftM, ap)
+import Control.Monad.Fail

 import Position   (Position)
 import UNames     (NameSupply)
@@ -110,6 +111,8 @@ instance Monad (PreCST e s) where
   (>>=)  = (+>=)
   (>>)   = (+>)

+instance MonadFail (PreCST e s) where
+  fail = error

 -- unwrapper coercion function (EXPORTED)
 --
diff --git a/c2hs/c/CParserMonad.hs b/c2hs/c/CParserMonad.hs
index 12c4ffa..fb9df09 100644
--- a/c2hs/c/CParserMonad.hs
+++ b/c2hs/c/CParserMonad.hs
@@ -56,6 +56,7 @@ module CParserMonad (
   setLastToken,      -- :: CToken -> P ()
   ) where

+import Prelude hiding (fail)
 import Position  (Position(..), Pos(posOf))
 import Errors    (interr)
 import UNames    (Name)
@@ -67,6 +68,7 @@ import Data.Set  (Set)
 import qualified Data.Set as Set (fromList, insert, member, delete)

 import CTokens (CToken)
+import Control.Monad.Fail

 data ParseResult a
   = POk !PState a
@@ -93,6 +95,8 @@ instance Applicative P where
 instance Monad P where
   return = returnP
   (>>=) = thenP
+
+instance MonadFail P where
   fail m = getPos >>= \pos -> failP pos [m]

 execParser :: P a -> String -> Position -> [Ident] -> [Name]
diff --git a/gtk2hs-buildtools.cabal b/gtk2hs-buildtools.cabal
index fc4a7d5..8b6be30 100644
--- a/gtk2hs-buildtools.cabal
+++ b/gtk2hs-buildtools.cabal
@@ -38,7 +38,7 @@ Flag ClosureSignals
 --        Default:        False

 Library
-        build-depends:   base >= 4 && < 4.12,
+        build-depends:   base >= 4 && < 4.13,
                          process, array, pretty,
                          filepath, random,
                          Cabal >= 1.24.0.0,
stale[bot] commented 4 years ago

Thank you for your contributions.

This has been automatically marked as stale because it has had no activity for 180 days.

If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.

Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse.
  3. Ask on the #nixos channel on irc.freenode.net.
Fuuzetsu commented 4 years ago

I think it's important, the experience is really bad any time these "special" packages need to be overridden and in my experience, introduces many strange build errors if not done exactly right, including tweaking some GHC-related variables in build phases.

stale[bot] commented 3 years ago

I marked this as stale due to inactivity. → More info