Skip to content

Commit de9f34b

Browse files
committed
Update niv and nixpkgs
1 parent 3995f3a commit de9f34b

File tree

2 files changed

+55
-29
lines changed

2 files changed

+55
-29
lines changed

nix/sources.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
"homepage": "",
66
"owner": "hercules-ci",
77
"repo": "gitignore",
8-
"rev": "c4662e662462e7bf3c2a968483478a665d00e717",
9-
"sha256": "1npnx0h6bd0d7ql93ka7azhj40zgjp815fw2r6smg8ch9p7mzdlx",
8+
"rev": "211907489e9f198594c0eb0ca9256a1949c9d412",
9+
"sha256": "06j7wpvj54khw0z10fjyi31kpafkr6hi1k0di13k1xp8kywvfyx8",
1010
"type": "tarball",
11-
"url": "https://github.com/hercules-ci/gitignore/archive/c4662e662462e7bf3c2a968483478a665d00e717.tar.gz",
11+
"url": "https://github.com/hercules-ci/gitignore/archive/211907489e9f198594c0eb0ca9256a1949c9d412.tar.gz",
1212
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
1313
},
1414
"niv": {
@@ -17,10 +17,10 @@
1717
"homepage": "https://github.com/nmattia/niv",
1818
"owner": "nmattia",
1919
"repo": "niv",
20-
"rev": "89ae775e9dfc2571f912156dd2f8627e14d4d507",
21-
"sha256": "0ssw6byyn79fpyzswi28s5b85x66xh4xsfhmcfl5mkdxxpmyy0ns",
20+
"rev": "af958e8057f345ee1aca714c1247ef3ba1c15f5e",
21+
"sha256": "1qjavxabbrsh73yck5dcq8jggvh3r2jkbr6b5nlz5d9yrqm9255n",
2222
"type": "tarball",
23-
"url": "https://github.com/nmattia/niv/archive/89ae775e9dfc2571f912156dd2f8627e14d4d507.tar.gz",
23+
"url": "https://github.com/nmattia/niv/archive/af958e8057f345ee1aca714c1247ef3ba1c15f5e.tar.gz",
2424
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
2525
},
2626
"nixpkgs": {
@@ -29,10 +29,10 @@
2929
"homepage": "https://github.com/NixOS/nixpkgs",
3030
"owner": "NixOS",
3131
"repo": "nixpkgs",
32-
"rev": "8911c99c2f1bf44210be7ff35314430f02f0f33d",
33-
"sha256": "06mi91yxidjyyrc7q5dbi1j8bxi2iird0ivqcnb4kiglpw0ivpkr",
32+
"rev": "01742ad805d6faef06a696d489573026fe32f496",
33+
"sha256": "13scmisrglk0mrj28lscb9imkhlnqh5f3s54l0rx8dayg1ysr0kw",
3434
"type": "tarball",
35-
"url": "https://github.com/NixOS/nixpkgs/archive/8911c99c2f1bf44210be7ff35314430f02f0f33d.tar.gz",
35+
"url": "https://github.com/NixOS/nixpkgs/archive/01742ad805d6faef06a696d489573026fe32f496.tar.gz",
3636
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
3737
}
3838
}

nix/sources.nix

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,33 @@ let
66
# The fetchers. fetch_<type> fetches specs of type <type>.
77
#
88

9-
fetch_file = pkgs: spec:
10-
if spec.builtin or true then
11-
builtins_fetchurl { inherit (spec) url sha256; }
12-
else
13-
pkgs.fetchurl { inherit (spec) url sha256; };
9+
fetch_file = pkgs: name: spec:
10+
let
11+
name' = sanitizeName name + "-src";
12+
in
13+
if spec.builtin or true then
14+
builtins_fetchurl { inherit (spec) url sha256; name = name'; }
15+
else
16+
pkgs.fetchurl { inherit (spec) url sha256; name = name'; };
1417

1518
fetch_tarball = pkgs: name: spec:
1619
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+
name' = sanitizeName name + "-src";
2021
in
2122
if spec.builtin or true then
2223
builtins_fetchTarball { name = name'; inherit (spec) url sha256; }
2324
else
2425
pkgs.fetchzip { name = name'; inherit (spec) url sha256; };
2526

26-
fetch_git = spec:
27-
builtins.fetchGit { url = spec.repo; inherit (spec) rev ref; };
27+
fetch_git = name: spec:
28+
let
29+
ref =
30+
if spec ? ref then spec.ref else
31+
if spec ? branch then "refs/heads/${spec.branch}" else
32+
if spec ? tag then "refs/tags/${spec.tag}" else
33+
abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!";
34+
in
35+
builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; };
2836

2937
fetch_local = spec: spec.path;
3038

@@ -40,11 +48,21 @@ let
4048
# Various helpers
4149
#
4250

51+
# https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695
52+
sanitizeName = name:
53+
(
54+
concatMapStrings (s: if builtins.isList s then "-" else s)
55+
(
56+
builtins.split "[^[:alnum:]+._?=-]+"
57+
((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name)
58+
)
59+
);
60+
4361
# The set of packages used when specs are fetched using non-builtins.
44-
mkPkgs = sources:
62+
mkPkgs = sources: system:
4563
let
4664
sourcesNixpkgs =
47-
import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) {};
65+
import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; };
4866
hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
4967
hasThisAsNixpkgsPath = <nixpkgs> == ./.;
5068
in
@@ -64,9 +82,9 @@ let
6482

6583
if ! builtins.hasAttr "type" spec then
6684
abort "ERROR: niv spec ${name} does not have a 'type' attribute"
67-
else if spec.type == "file" then fetch_file pkgs spec
85+
else if spec.type == "file" then fetch_file pkgs name spec
6886
else if spec.type == "tarball" then fetch_tarball pkgs name spec
69-
else if spec.type == "git" then fetch_git spec
87+
else if spec.type == "git" then fetch_git name spec
7088
else if spec.type == "local" then fetch_local spec
7189
else if spec.type == "builtin-tarball" then fetch_builtin-tarball name
7290
else if spec.type == "builtin-url" then fetch_builtin-url name
@@ -80,7 +98,10 @@ let
8098
saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name;
8199
ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}";
82100
in
83-
if ersatz == "" then drv else ersatz;
101+
if ersatz == "" then drv else
102+
# this turns the string into an actual Nix path (for both absolute and
103+
# relative paths)
104+
if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}";
84105

85106
# Ports of functions for older nix versions
86107

@@ -98,25 +119,29 @@ let
98119

99120
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269
100121
stringAsChars = f: s: concatStrings (map f (stringToCharacters s));
122+
concatMapStrings = f: list: concatStrings (map f list);
101123
concatStrings = builtins.concatStringsSep "";
102124

125+
# https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331
126+
optionalAttrs = cond: as: if cond then as else {};
127+
103128
# fetchTarball version that is compatible between all the versions of Nix
104-
builtins_fetchTarball = { url, name, sha256 }@attrs:
129+
builtins_fetchTarball = { url, name ? null, sha256 }@attrs:
105130
let
106131
inherit (builtins) lessThan nixVersion fetchTarball;
107132
in
108133
if lessThan nixVersion "1.12" then
109-
fetchTarball { inherit name url; }
134+
fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
110135
else
111136
fetchTarball attrs;
112137

113138
# fetchurl version that is compatible between all the versions of Nix
114-
builtins_fetchurl = { url, sha256 }@attrs:
139+
builtins_fetchurl = { url, name ? null, sha256 }@attrs:
115140
let
116141
inherit (builtins) lessThan nixVersion fetchurl;
117142
in
118143
if lessThan nixVersion "1.12" then
119-
fetchurl { inherit url; }
144+
fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
120145
else
121146
fetchurl attrs;
122147

@@ -135,7 +160,8 @@ let
135160
mkConfig =
136161
{ sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null
137162
, sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile)
138-
, pkgs ? mkPkgs sources
163+
, system ? builtins.currentSystem
164+
, pkgs ? mkPkgs sources system
139165
}: rec {
140166
# The sources, i.e. the attribute set of spec name to spec
141167
inherit sources;

0 commit comments

Comments
 (0)