Skip to content

Commit 94f29ac

Browse files
committed
move to niv and update nixpkgs
1 parent d99c236 commit 94f29ac

File tree

5 files changed

+202
-15
lines changed

5 files changed

+202
-15
lines changed

.bundler-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.1.4
1+
2.2.33

.ruby-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.6.6
1+
2.7.5

nix/sources.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"nixpkgs": {
3+
"branch": "release-21.11",
4+
"description": "Nix Packages collection",
5+
"homepage": "",
6+
"owner": "NixOS",
7+
"repo": "nixpkgs",
8+
"rev": "17d83d4085268918c4cc277146d1f7bec485da94",
9+
"sha256": "0xqdg1m7l6mcfybsg8nnggs93jlpazr0q3zib9j52k37fkpxq3cv",
10+
"type": "tarball",
11+
"url": "https://github.com/NixOS/nixpkgs/archive/17d83d4085268918c4cc277146d1f7bec485da94.tar.gz",
12+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
13+
}
14+
}

nix/sources.nix

+176
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
# This file has been generated by Niv.
2+
3+
let
4+
5+
#
6+
# The fetchers. fetch_<type> fetches specs of type <type>.
7+
#
8+
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'; };
17+
18+
fetch_tarball = pkgs: name: spec:
19+
let
20+
name' = sanitizeName name + "-src";
21+
in
22+
if spec.builtin or true then
23+
builtins_fetchTarball { name = name'; inherit (spec) url sha256; }
24+
else
25+
pkgs.fetchzip { name = name'; inherit (spec) url sha256; };
26+
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+
submodules = if spec ? submodules then spec.submodules else false;
35+
in
36+
builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; }
37+
// (if builtins.compareVersions builtins.nixVersion "2.4" >= 0 then { inherit submodules; } else {});
38+
39+
fetch_local = spec: spec.path;
40+
41+
fetch_builtin-tarball = name: throw
42+
''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`.
43+
$ niv modify ${name} -a type=tarball -a builtin=true'';
44+
45+
fetch_builtin-url = name: throw
46+
''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`.
47+
$ niv modify ${name} -a type=file -a builtin=true'';
48+
49+
#
50+
# Various helpers
51+
#
52+
53+
# https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695
54+
sanitizeName = name:
55+
(
56+
concatMapStrings (s: if builtins.isList s then "-" else s)
57+
(
58+
builtins.split "[^[:alnum:]+._?=-]+"
59+
((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name)
60+
)
61+
);
62+
63+
# The set of packages used when specs are fetched using non-builtins.
64+
mkPkgs = sources: system:
65+
let
66+
sourcesNixpkgs =
67+
import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; };
68+
hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
69+
hasThisAsNixpkgsPath = <nixpkgs> == ./.;
70+
in
71+
if builtins.hasAttr "nixpkgs" sources
72+
then sourcesNixpkgs
73+
else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
74+
import <nixpkgs> {}
75+
else
76+
abort
77+
''
78+
Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
79+
add a package called "nixpkgs" to your sources.json.
80+
'';
81+
82+
# The actual fetching function.
83+
fetch = pkgs: name: spec:
84+
85+
if ! builtins.hasAttr "type" spec then
86+
abort "ERROR: niv spec ${name} does not have a 'type' attribute"
87+
else if spec.type == "file" then fetch_file pkgs name spec
88+
else if spec.type == "tarball" then fetch_tarball pkgs name spec
89+
else if spec.type == "git" then fetch_git name spec
90+
else if spec.type == "local" then fetch_local spec
91+
else if spec.type == "builtin-tarball" then fetch_builtin-tarball name
92+
else if spec.type == "builtin-url" then fetch_builtin-url name
93+
else
94+
abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}";
95+
96+
# If the environment variable NIV_OVERRIDE_${name} is set, then use
97+
# the path directly as opposed to the fetched source.
98+
replace = name: drv:
99+
let
100+
saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name;
101+
ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}";
102+
in
103+
if ersatz == "" then drv else
104+
# this turns the string into an actual Nix path (for both absolute and
105+
# relative paths)
106+
if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}";
107+
108+
# Ports of functions for older nix versions
109+
110+
# a Nix version of mapAttrs if the built-in doesn't exist
111+
mapAttrs = builtins.mapAttrs or (
112+
f: set: with builtins;
113+
listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set))
114+
);
115+
116+
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295
117+
range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1);
118+
119+
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257
120+
stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1));
121+
122+
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269
123+
stringAsChars = f: s: concatStrings (map f (stringToCharacters s));
124+
concatMapStrings = f: list: concatStrings (map f list);
125+
concatStrings = builtins.concatStringsSep "";
126+
127+
# https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331
128+
optionalAttrs = cond: as: if cond then as else {};
129+
130+
# fetchTarball version that is compatible between all the versions of Nix
131+
builtins_fetchTarball = { url, name ? null, sha256 }@attrs:
132+
let
133+
inherit (builtins) lessThan nixVersion fetchTarball;
134+
in
135+
if lessThan nixVersion "1.12" then
136+
fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
137+
else
138+
fetchTarball attrs;
139+
140+
# fetchurl version that is compatible between all the versions of Nix
141+
builtins_fetchurl = { url, name ? null, sha256 }@attrs:
142+
let
143+
inherit (builtins) lessThan nixVersion fetchurl;
144+
in
145+
if lessThan nixVersion "1.12" then
146+
fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
147+
else
148+
fetchurl attrs;
149+
150+
# Create the final "sources" from the config
151+
mkSources = config:
152+
mapAttrs (
153+
name: spec:
154+
if builtins.hasAttr "outPath" spec
155+
then abort
156+
"The values in sources.json should not have an 'outPath' attribute"
157+
else
158+
spec // { outPath = replace name (fetch config.pkgs name spec); }
159+
) config.sources;
160+
161+
# The "config" used by the fetchers
162+
mkConfig =
163+
{ sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null
164+
, sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile)
165+
, system ? builtins.currentSystem
166+
, pkgs ? mkPkgs sources system
167+
}: rec {
168+
# The sources, i.e. the attribute set of spec name to spec
169+
inherit sources;
170+
171+
# The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers
172+
inherit pkgs;
173+
};
174+
175+
in
176+
mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); }

shell.nix

+10-13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
with import (builtins.fetchTarball rec {
2-
# grab a hash from here: https://nixos.org/channels/
3-
name = "nixpkgs-darwin-20.03pre214403.c23427de0d5";
4-
url =
5-
"https://github.com/nixos/nixpkgs/archive/c23427de0d501009b9c6d77ff8dda3763c6eb1b4.tar.gz";
6-
# Hash obtained using `nix-prefetch-url --unpack <url>`
7-
sha256 = "0fgv4pyzn39y8ibskn37x9cabmg6gflisigr5l45bkplm06bss91";
8-
}) { };
1+
{ ... }:
92
let
3+
sources = import ./nix/sources.nix { };
4+
pkgs = import sources.nixpkgs { };
5+
lib = pkgs.lib;
6+
107
expectVersion = version: pkg:
118
let actual = lib.getVersion pkg;
129
in assert (lib.assertMsg (builtins.toString actual == version) ''
@@ -18,12 +15,12 @@ let
1815
rubyVersion = lib.fileContents ./.ruby-version;
1916
bundlerVersion = lib.fileContents ./.bundler-version;
2017

21-
ruby = ruby_2_6;
22-
in stdenv.mkDerivation {
18+
ruby = pkgs.ruby;
19+
in pkgs.stdenv.mkDerivation {
2320
name = "deploy-complexity";
2421
buildInputs = [
25-
git
26-
(expectVersion rubyVersion ruby)
27-
(expectVersion bundlerVersion (bundler.override { inherit ruby; }))
22+
pkgs.git
23+
(expectVersion rubyVersion pkgs.ruby)
24+
(expectVersion bundlerVersion (pkgs.bundler.override { inherit ruby; }))
2825
];
2926
}

0 commit comments

Comments
 (0)