diff options
Diffstat (limited to 'nix')
-rw-r--r-- | nix/nixpkgs.nix | 27 | ||||
-rw-r--r-- | nix/sources.json | 50 | ||||
-rw-r--r-- | nix/sources.nix | 134 |
3 files changed, 211 insertions, 0 deletions
diff --git a/nix/nixpkgs.nix b/nix/nixpkgs.nix new file mode 100644 index 0000000..b5675fb --- /dev/null +++ b/nix/nixpkgs.nix | |||
@@ -0,0 +1,27 @@ | |||
1 | |||
2 | let | ||
3 | # Manage this with https://github.com/nmattia/niv | ||
4 | # or define { nixpkgs = ...; nixpkgs-mozilla = ...; } | ||
5 | # yourself. | ||
6 | sources = import ./sources.nix; | ||
7 | |||
8 | rustChannelsOverlay = import "${sources.nixpkgs-mozilla}/rust-overlay.nix"; | ||
9 | # Useful if you also want to provide that in a nix-shell since some rust tools depend | ||
10 | # on that. | ||
11 | rustChannelsSrcOverlay = import "${sources.nixpkgs-mozilla}/rust-src-overlay.nix"; | ||
12 | |||
13 | in import sources.nixpkgs { | ||
14 | overlays = [ | ||
15 | rustChannelsOverlay | ||
16 | rustChannelsSrcOverlay | ||
17 | (self: super: { | ||
18 | # Replace "latest.rustChannels.stable" with the version of the rust tools that | ||
19 | # you would like. Look at the documentation of nixpkgs-mozilla for examples. | ||
20 | # | ||
21 | # NOTE: "rust" instead of "rustc" is not a typo: It will include more than needed | ||
22 | # but also the much needed "rust-std". | ||
23 | rustc = super.latest.rustChannels.stable.rust; | ||
24 | inherit (super.latest.rustChannels.stable) cargo rust rust-fmt rust-std clippy; | ||
25 | }) | ||
26 | ]; | ||
27 | } | ||
diff --git a/nix/sources.json b/nix/sources.json new file mode 100644 index 0000000..0f22db7 --- /dev/null +++ b/nix/sources.json | |||
@@ -0,0 +1,50 @@ | |||
1 | { | ||
2 | "httpie": { | ||
3 | "branch": "master", | ||
4 | "description": "As easy as /aitch-tee-tee-pie/ 🥧 Modern, user-friendly command-line HTTP client for the API era. JSON support, colors, sessions, downloads, plugins & more. https://twitter.com/clihttp", | ||
5 | "homepage": "https://httpie.org", | ||
6 | "owner": "httpie", | ||
7 | "repo": "httpie", | ||
8 | "rev": "100872b5cf493b355453a9dff89f39b0c124d524", | ||
9 | "sha256": "10raamh8ri4b4ir17avvlm5ckaly3755555is14glnfj70sdf25g", | ||
10 | "type": "tarball", | ||
11 | "url": "https://github.com/httpie/httpie/archive/100872b5cf493b355453a9dff89f39b0c124d524.tar.gz", | ||
12 | "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" | ||
13 | }, | ||
14 | "niv": { | ||
15 | "branch": "master", | ||
16 | "description": "Easy dependency management for Nix projects", | ||
17 | "homepage": "https://github.com/nmattia/niv", | ||
18 | "owner": "nmattia", | ||
19 | "repo": "niv", | ||
20 | "rev": "89ae775e9dfc2571f912156dd2f8627e14d4d507", | ||
21 | "sha256": "0ssw6byyn79fpyzswi28s5b85x66xh4xsfhmcfl5mkdxxpmyy0ns", | ||
22 | "type": "tarball", | ||
23 | "url": "https://github.com/nmattia/niv/archive/89ae775e9dfc2571f912156dd2f8627e14d4d507.tar.gz", | ||
24 | "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" | ||
25 | }, | ||
26 | "nixpkgs": { | ||
27 | "branch": "nixos-20.03", | ||
28 | "description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to", | ||
29 | "homepage": "https://github.com/NixOS/nixpkgs", | ||
30 | "owner": "NixOS", | ||
31 | "repo": "nixpkgs-channels", | ||
32 | "rev": "64fec31a24b50c774cdc45d4d7fa8d29b79dc165", | ||
33 | "sha256": "101vn3lf87xl9wbhc5qn1xmh13d3dpcass536c960fs3ghanf0h3", | ||
34 | "type": "tarball", | ||
35 | "url": "https://github.com/NixOS/nixpkgs-channels/archive/64fec31a24b50c774cdc45d4d7fa8d29b79dc165.tar.gz", | ||
36 | "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" | ||
37 | }, | ||
38 | "nixpkgs-mozilla": { | ||
39 | "branch": "master", | ||
40 | "description": "mozilla related nixpkgs (extends nixos/nixpkgs repo)", | ||
41 | "homepage": null, | ||
42 | "owner": "mozilla", | ||
43 | "repo": "nixpkgs-mozilla", | ||
44 | "rev": "efda5b357451dbb0431f983cca679ae3cd9b9829", | ||
45 | "sha256": "11wqrg86g3qva67vnk81ynvqyfj0zxk83cbrf0p9hsvxiwxs8469", | ||
46 | "type": "tarball", | ||
47 | "url": "https://github.com/mozilla/nixpkgs-mozilla/archive/efda5b357451dbb0431f983cca679ae3cd9b9829.tar.gz", | ||
48 | "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" | ||
49 | } | ||
50 | } | ||
diff --git a/nix/sources.nix b/nix/sources.nix new file mode 100644 index 0000000..8a725cb --- /dev/null +++ b/nix/sources.nix | |||
@@ -0,0 +1,134 @@ | |||
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: spec: | ||
10 | if spec.builtin or true then | ||
11 | builtins_fetchurl { inherit (spec) url sha256; } | ||
12 | else | ||
13 | pkgs.fetchurl { inherit (spec) url sha256; }; | ||
14 | |||
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; }; | ||
20 | |||
21 | fetch_git = spec: | ||
22 | builtins.fetchGit { url = spec.repo; inherit (spec) rev ref; }; | ||
23 | |||
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; }; | ||
34 | |||
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`. | ||
41 | |||
42 | $ niv modify <package> -a type=file -a builtin=true | ||
43 | '' | ||
44 | (builtins_fetchurl { inherit (spec) url sha256; }); | ||
45 | |||
46 | # | ||
47 | # Various helpers | ||
48 | # | ||
49 | |||
50 | # The set of packages used when specs are fetched using non-builtins. | ||
51 | mkPkgs = sources: | ||
52 | let | ||
53 | sourcesNixpkgs = | ||
54 | import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) {}; | ||
55 | hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; | ||
56 | hasThisAsNixpkgsPath = <nixpkgs> == ./.; | ||
57 | in | ||
58 | if builtins.hasAttr "nixpkgs" sources | ||
59 | then sourcesNixpkgs | ||
60 | else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then | ||
61 | import <nixpkgs> {} | ||
62 | else | ||
63 | abort | ||
64 | '' | ||
65 | Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or | ||
66 | add a package called "nixpkgs" to your sources.json. | ||
67 | ''; | ||
68 | |||
69 | # The actual fetching function. | ||
70 | fetch = pkgs: name: spec: | ||
71 | |||
72 | if ! builtins.hasAttr "type" spec then | ||
73 | abort "ERROR: niv spec ${name} does not have a 'type' attribute" | ||
74 | else if spec.type == "file" then fetch_file pkgs spec | ||
75 | else if spec.type == "tarball" then fetch_tarball pkgs spec | ||
76 | 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 | ||
79 | else | ||
80 | abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; | ||
81 | |||
82 | # Ports of functions for older nix versions | ||
83 | |||
84 | # a Nix version of mapAttrs if the built-in doesn't exist | ||
85 | mapAttrs = builtins.mapAttrs or ( | ||
86 | f: set: with builtins; | ||
87 | listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) | ||
88 | ); | ||
89 | |||
90 | # fetchTarball version that is compatible between all the versions of Nix | ||
91 | builtins_fetchTarball = { url, sha256 }@attrs: | ||
92 | let | ||
93 | inherit (builtins) lessThan nixVersion fetchTarball; | ||
94 | in | ||
95 | if lessThan nixVersion "1.12" then | ||
96 | fetchTarball { inherit url; } | ||
97 | else | ||
98 | fetchTarball attrs; | ||
99 | |||
100 | # fetchurl version that is compatible between all the versions of Nix | ||
101 | builtins_fetchurl = { url, sha256 }@attrs: | ||
102 | let | ||
103 | inherit (builtins) lessThan nixVersion fetchurl; | ||
104 | in | ||
105 | if lessThan nixVersion "1.12" then | ||
106 | fetchurl { inherit url; } | ||
107 | else | ||
108 | fetchurl attrs; | ||
109 | |||
110 | # Create the final "sources" from the config | ||
111 | mkSources = config: | ||
112 | mapAttrs ( | ||
113 | name: spec: | ||
114 | if builtins.hasAttr "outPath" spec | ||
115 | then abort | ||
116 | "The values in sources.json should not have an 'outPath' attribute" | ||
117 | else | ||
118 | spec // { outPath = fetch config.pkgs name spec; } | ||
119 | ) config.sources; | ||
120 | |||
121 | # The "config" used by the fetchers | ||
122 | mkConfig = | ||
123 | { sourcesFile ? ./sources.json | ||
124 | , sources ? builtins.fromJSON (builtins.readFile sourcesFile) | ||
125 | , pkgs ? mkPkgs sources | ||
126 | }: rec { | ||
127 | # The sources, i.e. the attribute set of spec name to spec | ||
128 | inherit sources; | ||
129 | |||
130 | # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers | ||
131 | inherit pkgs; | ||
132 | }; | ||
133 | in | ||
134 | mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); } | ||