Skip to content

Commit d558c32

Browse files
authored
tech(nix): update niv and remove allowbroken (#350)
#325 retrie is no longer appears to be marked broken: https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/haskell-modules/hackage-packages.nix#L215948
1 parent b6c1551 commit d558c32

File tree

3 files changed

+53
-41
lines changed

3 files changed

+53
-41
lines changed

Diff for: nix/sources.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
"homepage": "https://github.com/nmattia/niv",
66
"owner": "nmattia",
77
"repo": "niv",
8-
"rev": "ab9cc41caf44d1f1d465d8028e4bc0096fd73238",
9-
"sha256": "17k52n8zwp832cqifsc4458mhy4044wmk22f807171hf6p7l4xvr",
8+
"rev": "89ae775e9dfc2571f912156dd2f8627e14d4d507",
9+
"sha256": "0ssw6byyn79fpyzswi28s5b85x66xh4xsfhmcfl5mkdxxpmyy0ns",
1010
"type": "tarball",
11-
"url": "https://github.com/nmattia/niv/archive/ab9cc41caf44d1f1d465d8028e4bc0096fd73238.tar.gz",
11+
"url": "https://github.com/nmattia/niv/archive/89ae775e9dfc2571f912156dd2f8627e14d4d507.tar.gz",
1212
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
1313
},
1414
"nixpkgs": {
@@ -17,10 +17,10 @@
1717
"homepage": "https://github.com/NixOS/nixpkgs",
1818
"owner": "NixOS",
1919
"repo": "nixpkgs-channels",
20-
"rev": "2c4e0f37a6d5d33666b550a1b85daf46b37f1b25",
21-
"sha256": "0hqr6ci0rgg1fyfg7w2182vgbi0cq472p2j8r7mcmkbpdwwi6i69",
20+
"rev": "a332da8588aeea4feb9359d23f58d95520899e3c",
21+
"sha256": "18hlja5syv3xpi14c07h9lrn1cchq2azmj06fyalq52vl064nx75",
2222
"type": "tarball",
23-
"url": "https://github.com/NixOS/nixpkgs-channels/archive/2c4e0f37a6d5d33666b550a1b85daf46b37f1b25.tar.gz",
23+
"url": "https://github.com/NixOS/nixpkgs-channels/archive/a332da8588aeea4feb9359d23f58d95520899e3c.tar.gz",
2424
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
2525
}
2626
}

Diff for: nix/sources.nix

+46-32
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,29 @@ let
1212
else
1313
pkgs.fetchurl { inherit (spec) url sha256; };
1414

15-
fetch_tarball = pkgs: spec:
16-
if spec.builtin or true then
17-
builtins_fetchTarball { inherit (spec) url sha256; }
18-
else
19-
pkgs.fetchzip { inherit (spec) url sha256; };
15+
fetch_tarball = pkgs: name: spec:
16+
let
17+
ok = str: ! builtins.isNull (builtins.match "[a-zA-Z0-9+-._?=]" str);
18+
# sanitize the name, though nix will still fail if name starts with period
19+
name' = stringAsChars (x: if ! ok x then "-" else x) "${name}-src";
20+
in
21+
if spec.builtin or true then
22+
builtins_fetchTarball { name = name'; inherit (spec) url sha256; }
23+
else
24+
pkgs.fetchzip { name = name'; inherit (spec) url sha256; };
2025

2126
fetch_git = spec:
2227
builtins.fetchGit { url = spec.repo; inherit (spec) rev ref; };
2328

24-
fetch_builtin-tarball = spec:
25-
builtins.trace
26-
''
27-
WARNING:
28-
The niv type "builtin-tarball" will soon be deprecated. You should
29-
instead use `builtin = true`.
30-
31-
$ niv modify <package> -a type=tarball -a builtin=true
32-
''
33-
builtins_fetchTarball { inherit (spec) url sha256; };
29+
fetch_local = spec: spec.path;
3430

35-
fetch_builtin-url = spec:
36-
builtins.trace
37-
''
38-
WARNING:
39-
The niv type "builtin-url" will soon be deprecated. You should
40-
instead use `builtin = true`.
31+
fetch_builtin-tarball = name: throw
32+
''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`.
33+
$ niv modify ${name} -a type=tarball -a builtin=true'';
4134

42-
$ niv modify <package> -a type=file -a builtin=true
43-
''
44-
(builtins_fetchurl { inherit (spec) url sha256; });
35+
fetch_builtin-url = name: throw
36+
''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`.
37+
$ niv modify ${name} -a type=file -a builtin=true'';
4538

4639
#
4740
# Various helpers
@@ -72,13 +65,23 @@ let
7265
if ! builtins.hasAttr "type" spec then
7366
abort "ERROR: niv spec ${name} does not have a 'type' attribute"
7467
else if spec.type == "file" then fetch_file pkgs spec
75-
else if spec.type == "tarball" then fetch_tarball pkgs spec
68+
else if spec.type == "tarball" then fetch_tarball pkgs name spec
7669
else if spec.type == "git" then fetch_git spec
77-
else if spec.type == "builtin-tarball" then fetch_builtin-tarball spec
78-
else if spec.type == "builtin-url" then fetch_builtin-url spec
70+
else if spec.type == "local" then fetch_local spec
71+
else if spec.type == "builtin-tarball" then fetch_builtin-tarball name
72+
else if spec.type == "builtin-url" then fetch_builtin-url name
7973
else
8074
abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}";
8175

76+
# If the environment variable NIV_OVERRIDE_${name} is set, then use
77+
# the path directly as opposed to the fetched source.
78+
replace = name: drv:
79+
let
80+
saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name;
81+
ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}";
82+
in
83+
if ersatz == "" then drv else ersatz;
84+
8285
# Ports of functions for older nix versions
8386

8487
# a Nix version of mapAttrs if the built-in doesn't exist
@@ -87,13 +90,23 @@ let
8790
listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set))
8891
);
8992

93+
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295
94+
range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1);
95+
96+
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257
97+
stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1));
98+
99+
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269
100+
stringAsChars = f: s: concatStrings (map f (stringToCharacters s));
101+
concatStrings = builtins.concatStringsSep "";
102+
90103
# fetchTarball version that is compatible between all the versions of Nix
91-
builtins_fetchTarball = { url, sha256 }@attrs:
104+
builtins_fetchTarball = { url, name, sha256 }@attrs:
92105
let
93106
inherit (builtins) lessThan nixVersion fetchTarball;
94107
in
95108
if lessThan nixVersion "1.12" then
96-
fetchTarball { inherit url; }
109+
fetchTarball { inherit name url; }
97110
else
98111
fetchTarball attrs;
99112

@@ -115,13 +128,13 @@ let
115128
then abort
116129
"The values in sources.json should not have an 'outPath' attribute"
117130
else
118-
spec // { outPath = fetch config.pkgs name spec; }
131+
spec // { outPath = replace name (fetch config.pkgs name spec); }
119132
) config.sources;
120133

121134
# The "config" used by the fetchers
122135
mkConfig =
123-
{ sourcesFile ? ./sources.json
124-
, sources ? builtins.fromJSON (builtins.readFile sourcesFile)
136+
{ sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null
137+
, sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile)
125138
, pkgs ? mkPkgs sources
126139
}: rec {
127140
# The sources, i.e. the attribute set of spec name to spec
@@ -130,5 +143,6 @@ let
130143
# The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers
131144
inherit pkgs;
132145
};
146+
133147
in
134148
mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); }

Diff for: shell.nix

+1-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
# assuming that cabal new-build does succeed outside nix-shell
1717

1818
{ sources ? import nix/sources.nix,
19-
# TODO Remove allowBroken once retrie is no longer marked as broken in Nixpkgs
20-
# See https://github.com/haskell/haskell-language-server/issues/325
21-
nixpkgs ? import sources.nixpkgs { config.allowBroken = true; },
19+
nixpkgs ? import sources.nixpkgs { },
2220
compiler ? "default",
2321
hoogle ? false
2422
}:

0 commit comments

Comments
 (0)