diff options
-rw-r--r-- | nix/sources.json | 24 | ||||
-rw-r--r-- | nix/sources.nix | 78 | ||||
-rw-r--r-- | shell.nix | 14 |
3 files changed, 59 insertions, 57 deletions
diff --git a/nix/sources.json b/nix/sources.json index 0f22db7..df1e613 100644 --- a/nix/sources.json +++ b/nix/sources.json | |||
@@ -1,26 +1,14 @@ | |||
1 | { | 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": { | 2 | "niv": { |
15 | "branch": "master", | 3 | "branch": "master", |
16 | "description": "Easy dependency management for Nix projects", | 4 | "description": "Easy dependency management for Nix projects", |
17 | "homepage": "https://github.com/nmattia/niv", | 5 | "homepage": "https://github.com/nmattia/niv", |
18 | "owner": "nmattia", | 6 | "owner": "nmattia", |
19 | "repo": "niv", | 7 | "repo": "niv", |
20 | "rev": "89ae775e9dfc2571f912156dd2f8627e14d4d507", | 8 | "rev": "b50a0107691487d4948c2078a77afdc0d1f20e8b", |
21 | "sha256": "0ssw6byyn79fpyzswi28s5b85x66xh4xsfhmcfl5mkdxxpmyy0ns", | 9 | "sha256": "0cr2a6rp9g8jjadwvb65j5fjlby64mqj48wyfm5p265iqjhvqn9q", |
22 | "type": "tarball", | 10 | "type": "tarball", |
23 | "url": "https://github.com/nmattia/niv/archive/89ae775e9dfc2571f912156dd2f8627e14d4d507.tar.gz", | 11 | "url": "https://github.com/nmattia/niv/archive/b50a0107691487d4948c2078a77afdc0d1f20e8b.tar.gz", |
24 | "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" | 12 | "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" |
25 | }, | 13 | }, |
26 | "nixpkgs": { | 14 | "nixpkgs": { |
@@ -29,10 +17,10 @@ | |||
29 | "homepage": "https://github.com/NixOS/nixpkgs", | 17 | "homepage": "https://github.com/NixOS/nixpkgs", |
30 | "owner": "NixOS", | 18 | "owner": "NixOS", |
31 | "repo": "nixpkgs-channels", | 19 | "repo": "nixpkgs-channels", |
32 | "rev": "64fec31a24b50c774cdc45d4d7fa8d29b79dc165", | 20 | "rev": "42674051d12540d4a996504990c6ea3619505953", |
33 | "sha256": "101vn3lf87xl9wbhc5qn1xmh13d3dpcass536c960fs3ghanf0h3", | 21 | "sha256": "1hz1n1hghilgzk4zlya498xm5lvhsf0r5b49yii7q86h3616fhwy", |
34 | "type": "tarball", | 22 | "type": "tarball", |
35 | "url": "https://github.com/NixOS/nixpkgs-channels/archive/64fec31a24b50c774cdc45d4d7fa8d29b79dc165.tar.gz", | 23 | "url": "https://github.com/NixOS/nixpkgs-channels/archive/42674051d12540d4a996504990c6ea3619505953.tar.gz", |
36 | "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" | 24 | "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" |
37 | }, | 25 | }, |
38 | "nixpkgs-mozilla": { | 26 | "nixpkgs-mozilla": { |
diff --git a/nix/sources.nix b/nix/sources.nix index 8a725cb..b64b8f8 100644 --- a/nix/sources.nix +++ b/nix/sources.nix | |||
@@ -12,36 +12,29 @@ let | |||
12 | else | 12 | else |
13 | pkgs.fetchurl { inherit (spec) url sha256; }; | 13 | pkgs.fetchurl { inherit (spec) url sha256; }; |
14 | 14 | ||
15 | fetch_tarball = pkgs: spec: | 15 | fetch_tarball = pkgs: name: spec: |
16 | if spec.builtin or true then | 16 | let |
17 | builtins_fetchTarball { inherit (spec) url sha256; } | 17 | ok = str: ! builtins.isNull (builtins.match "[a-zA-Z0-9+-._?=]" str); |
18 | else | 18 | # sanitize the name, though nix will still fail if name starts with period |
19 | pkgs.fetchzip { inherit (spec) url sha256; }; | 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; }; | ||
20 | 25 | ||
21 | fetch_git = spec: | 26 | fetch_git = spec: |
22 | builtins.fetchGit { url = spec.repo; inherit (spec) rev ref; }; | 27 | builtins.fetchGit { url = spec.repo; inherit (spec) rev ref; }; |
23 | 28 | ||
24 | fetch_builtin-tarball = spec: | 29 | fetch_local = spec: spec.path; |
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 | 30 | ||
35 | fetch_builtin-url = spec: | 31 | fetch_builtin-tarball = name: throw |
36 | builtins.trace | 32 | ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. |
37 | '' | 33 | $ niv modify ${name} -a type=tarball -a builtin=true''; |
38 | WARNING: | ||
39 | The niv type "builtin-url" will soon be deprecated. You should | ||
40 | instead use `builtin = true`. | ||
41 | 34 | ||
42 | $ niv modify <package> -a type=file -a builtin=true | 35 | fetch_builtin-url = name: throw |
43 | '' | 36 | ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. |
44 | (builtins_fetchurl { inherit (spec) url sha256; }); | 37 | $ niv modify ${name} -a type=file -a builtin=true''; |
45 | 38 | ||
46 | # | 39 | # |
47 | # Various helpers | 40 | # Various helpers |
@@ -72,13 +65,23 @@ let | |||
72 | if ! builtins.hasAttr "type" spec then | 65 | if ! builtins.hasAttr "type" spec then |
73 | abort "ERROR: niv spec ${name} does not have a 'type' attribute" | 66 | abort "ERROR: niv spec ${name} does not have a 'type' attribute" |
74 | else if spec.type == "file" then fetch_file pkgs spec | 67 | 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 |
76 | else if spec.type == "git" then fetch_git spec | 69 | else if spec.type == "git" then fetch_git spec |
77 | else if spec.type == "builtin-tarball" then fetch_builtin-tarball spec | 70 | else if spec.type == "local" then fetch_local spec |
78 | else if spec.type == "builtin-url" then fetch_builtin-url 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 | ||
79 | else | 73 | else |
80 | abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; | 74 | abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; |
81 | 75 | ||
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 | |||
82 | # Ports of functions for older nix versions | 85 | # Ports of functions for older nix versions |
83 | 86 | ||
84 | # a Nix version of mapAttrs if the built-in doesn't exist | 87 | # a Nix version of mapAttrs if the built-in doesn't exist |
@@ -87,13 +90,23 @@ let | |||
87 | listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) | 90 | listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) |
88 | ); | 91 | ); |
89 | 92 | ||
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 | |||
90 | # fetchTarball version that is compatible between all the versions of Nix | 103 | # fetchTarball version that is compatible between all the versions of Nix |
91 | builtins_fetchTarball = { url, sha256 }@attrs: | 104 | builtins_fetchTarball = { url, name, sha256 }@attrs: |
92 | let | 105 | let |
93 | inherit (builtins) lessThan nixVersion fetchTarball; | 106 | inherit (builtins) lessThan nixVersion fetchTarball; |
94 | in | 107 | in |
95 | if lessThan nixVersion "1.12" then | 108 | if lessThan nixVersion "1.12" then |
96 | fetchTarball { inherit url; } | 109 | fetchTarball { inherit name url; } |
97 | else | 110 | else |
98 | fetchTarball attrs; | 111 | fetchTarball attrs; |
99 | 112 | ||
@@ -115,13 +128,13 @@ let | |||
115 | then abort | 128 | then abort |
116 | "The values in sources.json should not have an 'outPath' attribute" | 129 | "The values in sources.json should not have an 'outPath' attribute" |
117 | else | 130 | else |
118 | spec // { outPath = fetch config.pkgs name spec; } | 131 | spec // { outPath = replace name (fetch config.pkgs name spec); } |
119 | ) config.sources; | 132 | ) config.sources; |
120 | 133 | ||
121 | # The "config" used by the fetchers | 134 | # The "config" used by the fetchers |
122 | mkConfig = | 135 | mkConfig = |
123 | { sourcesFile ? ./sources.json | 136 | { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null |
124 | , sources ? builtins.fromJSON (builtins.readFile sourcesFile) | 137 | , sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile) |
125 | , pkgs ? mkPkgs sources | 138 | , pkgs ? mkPkgs sources |
126 | }: rec { | 139 | }: rec { |
127 | # The sources, i.e. the attribute set of spec name to spec | 140 | # The sources, i.e. the attribute set of spec name to spec |
@@ -130,5 +143,6 @@ let | |||
130 | # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers | 143 | # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers |
131 | inherit pkgs; | 144 | inherit pkgs; |
132 | }; | 145 | }; |
146 | |||
133 | in | 147 | in |
134 | mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); } | 148 | mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); } |
@@ -3,13 +3,13 @@ | |||
3 | , pkgs ? import nixpkgs | 3 | , pkgs ? import nixpkgs |
4 | }: | 4 | }: |
5 | 5 | ||
6 | pkgs.mkShell { | 6 | with pkgs; |
7 | mkShell { | ||
7 | buildInputs = [ | 8 | buildInputs = [ |
8 | pkgs.cargo | 9 | cargo |
9 | pkgs.rustc | 10 | rustc |
10 | pkgs.git | 11 | git |
11 | pkgs.shellcheck | 12 | sqlite |
12 | pkgs.sqlite | 13 | httpie |
13 | pkgs.httpie | ||
14 | ]; | 14 | ]; |
15 | } | 15 | } |