Skip to content

Commit cb139fa

Browse files
authored
Prefer non pre-existing packages (#2218)
When choosing between two packages in the plan with the same version number, choose the non pre-existing package.
1 parent 6515de8 commit cb139fa

File tree

5 files changed

+61
-16
lines changed

5 files changed

+61
-16
lines changed
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
pkgs: let baseurl = "https://github.com/input-output-hk/haskell.nix/releases/download/nix-tools-0.2.1/"; in {
2+
aarch64-darwin = pkgs.fetchurl {
3+
name = "aarch64-darwin-nix-tools-static";
4+
url = "${baseurl}aarch64-darwin-nix-tools-static.zip";
5+
sha256 = "sha256-/N2CiakRQHIjLtBbdYfkDyhlHFss9ezWc9WW+HIUOwc=";
6+
};
7+
x86_64-darwin = pkgs.fetchurl {
8+
name = "x86_64-darwin-nix-tools-static";
9+
url = "${baseurl}x86_64-darwin-nix-tools-static.zip";
10+
sha256 = "sha256-1Xbxhw7LR6EooiagmRrHg7+UdxddD0RaKjvM75hwsJo=";
11+
};
12+
aarch64-linux = pkgs.fetchurl {
13+
name = "aarch64-linux-nix-tools-static";
14+
url = "${baseurl}aarch64-linux-nix-tools-static.zip";
15+
sha256 = "sha256-1OarDAiwYbet6ol3q2dZdnsWMHcniK4zznbGiDPMrO4=";
16+
};
17+
x86_64-linux = pkgs.fetchurl {
18+
name = "x86_64-linux-nix-tools-static";
19+
url = "${baseurl}x86_64-linux-nix-tools-static.zip";
20+
sha256 = "sha256-7xckkH+T9uu3fhtTOzqHZ1udNvPJAgkcrvDXEF16qJQ=";
21+
};
22+
}

nix-tools-static.nix

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
pkgs: let baseurl = "https://github.com/input-output-hk/haskell.nix/releases/download/nix-tools-0.2.1/"; in {
1+
pkgs: let baseurl = "https://github.com/input-output-hk/haskell.nix/releases/download/nix-tools-0.2.2/"; in {
22
aarch64-darwin = pkgs.fetchurl {
33
name = "aarch64-darwin-nix-tools-static";
44
url = "${baseurl}aarch64-darwin-nix-tools-static.zip";
5-
sha256 = "sha256-/N2CiakRQHIjLtBbdYfkDyhlHFss9ezWc9WW+HIUOwc=";
5+
sha256 = "sha256-VXc99TE1bLlz1bUUw2a2tma2260VrfWNhNr8+7Mqa1Q=";
66
};
77
x86_64-darwin = pkgs.fetchurl {
88
name = "x86_64-darwin-nix-tools-static";
99
url = "${baseurl}x86_64-darwin-nix-tools-static.zip";
10-
sha256 = "sha256-1Xbxhw7LR6EooiagmRrHg7+UdxddD0RaKjvM75hwsJo=";
10+
sha256 = "sha256-05O2BL7YFX1JWGi50NZoXaRZAiRK4UN/OZ0df5apTX8=";
1111
};
1212
aarch64-linux = pkgs.fetchurl {
1313
name = "aarch64-linux-nix-tools-static";
1414
url = "${baseurl}aarch64-linux-nix-tools-static.zip";
15-
sha256 = "sha256-1OarDAiwYbet6ol3q2dZdnsWMHcniK4zznbGiDPMrO4=";
15+
sha256 = "sha256-bG5h3bVaHSM4F4vcmADw+F8uwNIknUGjdAt/CaExkNE=";
1616
};
1717
x86_64-linux = pkgs.fetchurl {
1818
name = "x86_64-linux-nix-tools-static";
1919
url = "${baseurl}x86_64-linux-nix-tools-static.zip";
20-
sha256 = "sha256-7xckkH+T9uu3fhtTOzqHZ1udNvPJAgkcrvDXEF16qJQ=";
20+
sha256 = "sha256-S1B234xk3FjZvvSVMnpo2fW4kPhPsXYmGp8BCjhEUdE=";
2121
};
2222
}

nix-tools/nix-tools/plan2nix/Plan2Nix.hs

+15-2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ writeDoc file doc =
7979
hPutDoc handle doc
8080
hClose handle
8181

82+
-- PackageKey is used when selecting which version is the most recent
83+
-- when to deduplicate the plan.
84+
-- By including PackageType as well as version we can select the
85+
-- NonPreExisting version of the package if the versions match.
86+
data PackageType = PreExisting | NotPreExisting deriving (Eq, Ord)
87+
data PackageKey = PackageKey Version PackageType deriving (Eq, Ord)
88+
8289
plan2nix :: Args -> Plan -> IO NExpr
8390
plan2nix args Plan { packages, extras, components, compilerVersion, compilerPackages } = do
8491
-- TODO: this is an aweful hack and expects plan-to-nix to be
@@ -260,13 +267,19 @@ value2plan plan = Plan { packages, components, extras, compilerVersion, compiler
260267
filterInstallPlan :: (Value -> Maybe b) -> HashMap Text b
261268
filterInstallPlan f = fmap snd .
262269
-- If the same package occurs more than once, choose the latest
263-
Map.fromListWith (\a b -> if parseVersion (fst a) > parseVersion (fst b) then a else b)
264-
$ mapMaybe (\pkg -> (,) (pkg ^. key "pkg-name" . _String) . (pkg ^. key "pkg-version" . _String,) <$> f pkg)
270+
Map.fromListWith (\a b -> if fst a > fst b then a else b)
271+
$ mapMaybe (\pkg -> (,) (pkg ^. key "pkg-name" . _String) . (getPackageKey pkg,) <$> f pkg)
265272
$ Vector.toList (plan ^. key "install-plan" . _Array)
266273

267274
parseVersion :: Text -> Version
268275
parseVersion s = fromMaybe (error $ "Unable to parse version " <> show s) . simpleParsec $ Text.unpack s
269276

277+
getPackageKey :: Value -> PackageKey
278+
getPackageKey pkg = PackageKey (parseVersion (pkg ^. key "pkg-version" . _String)) (
279+
if pkg ^. key "type" . _String == "pre-existing"
280+
then PreExisting
281+
else NotPreExisting)
282+
270283
-- Set of components that are included in the plan.
271284
components :: HashSet Text
272285
components =

overlays/default.nix

+10-3
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ let
2828
# pointing back to the same static-nix-tools derivation. This allows
2929
# downstram derivation to keep using `nix-tools.exes.make-install-plan`
3030
# as shown above.
31-
static-nix-tools =
31+
static-nix-tools' = pins:
3232
let
3333
# TODO replace once haskell-nix-examples nix-tools is in haskell.nix
34-
zipFile = (import ../nix-tools-static.nix final).${final.system};
34+
zipFile = (import pins final).${final.system};
3535
tarball = final.runCommand "nix-tools" {
3636
nativeBuildInputs = [ final.unzip ];
3737
} ''
@@ -44,6 +44,9 @@ let
4444
# add the missing exes attributes to the tarball derivation
4545
tarball // { exes = final.lib.genAttrs nix-tools-provided-exes (_: tarball); };
4646

47+
static-nix-tools = static-nix-tools' ../nix-tools-static.nix;
48+
static-nix-tools-for-default-setup = static-nix-tools' ../nix-tools-static-for-default-setup.nix;
49+
4750
# Version of nix-tools built with a pinned version of haskell.nix.
4851
pinned-nix-tools-lib = (import (final.haskell-nix.sources.flake-compat) {
4952
pkgs = final;
@@ -60,7 +63,11 @@ let
6063
prev.haskell-nix // {
6164
inherit (nix-tools-pkgs) nix-tools nix-tools-set;
6265
# either nix-tools from its overlay or from the tarball.
63-
nix-tools-unchecked = static-nix-tools;
66+
nix-tools-unchecked = static-nix-tools// {
67+
exes = static-nix-tools.exes // {
68+
inherit (static-nix-tools-for-default-setup.exes) default-setup default-setup-ghcjs;
69+
};
70+
};
6471
};
6572
# For use building hadrian. This way updating anything that modifies the
6673
# way hadrian is built will not cause a GHC rebuild.

test/cabal.project.local

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
if impl(ghc>=9.8)
1+
if impl(ghc>=9.10.1)
22
-- allow newer packages, that are bound to be newer due to
33
-- being shipped with a newer compiler. If you extend this
44
-- be very careful to only extend it for absolutely necessary packages
55
-- otherwise we risk running into broken build-plans down the line.
66
allow-newer: *:base, *:template-haskell, *:bytestring, *:text, *:ghc-prim, *:deepseq, *:Cabal
7-
if impl(ghc > 9.9)
7+
if impl(ghc > 9.11)
88
allow-newer: *:containers
99
constraints: base-compat >=0.14.0, aeson >=2.2.1.0
1010

1111
-- This prevents hsc2hs from causing old versions of packages from being added to plan.json
1212
allow-newer: hsc2hs:*
1313

14+
if impl(ghc >=9.10.1)
15+
extra-packages: process
16+
1417
repository head.hackage.ghc.haskell.org
1518
url: https://ghc.gitlab.haskell.org/head.hackage/
1619
secure: True
@@ -28,14 +31,14 @@ repository ghcjs-overlay
2831
key-threshold: 0
2932
--sha256: sha256-+Eq62mUAS6rl0PYC5U0D3fH3P5tpnH/Y5qftZMgL7OM=
3033

31-
if !impl(ghc>=9.10) && !os(ghcjs)
34+
if !impl(ghc>=9.11) && !os(ghcjs)
3235
active-repositories: hackage.haskell.org
3336

34-
if impl(ghc>=9.10) && !os(ghcjs)
37+
if impl(ghc>=9.11) && !os(ghcjs)
3538
active-repositories: hackage.haskell.org, head.hackage.ghc.haskell.org
3639

37-
if !impl(ghc>=9.10) && os(ghcjs)
40+
if !impl(ghc>=9.11) && os(ghcjs)
3841
active-repositories: hackage.haskell.org, ghcjs-overlay:override
3942

40-
if impl(ghc>=9.10) && os(ghcjs)
43+
if impl(ghc>=9.11) && os(ghcjs)
4144
active-repositories: hackage.haskell.org, head.hackage.ghc.haskell.org, ghcjs-overlay:override

0 commit comments

Comments
 (0)