Skip to content

Commit f1ba84f

Browse files
committed
Update docs
- changes for new style of invoking NUR (passing pkgs argument) - Using fetchTarball instead of fetchGit for speed - Add more sections to readme
1 parent 2981c89 commit f1ba84f

File tree

1 file changed

+80
-36
lines changed

1 file changed

+80
-36
lines changed

README.md

+80-36
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ more decentralized way.
1414
NUR automatically check its list of repositories and perform evaluation checks
1515
before it propagated the updates.
1616

17-
## How to use
17+
## Installation
1818

1919
First include NUR in your `packageOverrides`:
2020

@@ -23,9 +23,9 @@ To make NUR accessible for your login user, add the following to `~/.config/nixp
2323
```nix
2424
{
2525
packageOverrides = pkgs: {
26-
nur = pkgs.callPackage (import (builtins.fetchGit {
27-
url = "https://github.com/nix-community/NUR";
28-
})) {};
26+
nur = import (builtins.fetchTarball "https://github.com/nix-community/NUR/archive/master.tar.gz") {
27+
inherit pkgs;
28+
};
2929
};
3030
}
3131
```
@@ -35,13 +35,28 @@ For NixOS add the following to your `/etc/nixos/configuration.nix`:
3535
```nix
3636
{
3737
nixpkgs.config.packageOverrides = pkgs: {
38-
nur = pkgs.callPackage (import (builtins.fetchGit {
39-
url = "https://github.com/nix-community/NUR";
40-
})) {};
38+
nur = import (builtins.fetchTarball "https://github.com/nix-community/NUR/archive/master.tar.gz") {
39+
inherit pkgs;
40+
};
4141
};
4242
}
4343
```
4444

45+
### Pinning
46+
47+
Using `builtins.fetchTarball` without a sha256 will only cache the download for 1 hour by default, so you need internet access almost every time you build something. You can pin the version if you don't want that:
48+
49+
```nix
50+
builtins.fetchTarball {
51+
# Get the revision by choosing a version from https://github.com/nix-community/NUR/commits/master
52+
url = "https://github.com/nix-community/NUR/archive/3a6a6f4da737da41e27922ce2cfacf68a109ebce.tar.gz";
53+
# Get the hash by running `nix-prefetch-url --unpack <url>` on the above url
54+
sha256 = "04387gzgl8y555b3lkz9aiw9xsldfg4zmzp930m62qw8zbrvrshd";
55+
}
56+
```
57+
58+
## How to use
59+
4560
Then packages can be used or installed from the NUR namespace.
4661

4762
```console
@@ -62,7 +77,7 @@ or
6277

6378
```console
6479
# configuration.nix
65-
environment.systemPackages = [
80+
environment.systemPackages = with pkgs; [
6681
nur.repos.mic92.inxi
6782
];
6883
```
@@ -73,19 +88,39 @@ for its content.
7388
***NUR does not check repository for malicious content on a regular base and it is
7489
recommend to check expression before installing them.***
7590

91+
### Using modules overlays or library functions on NixOS
92+
93+
If you intend to use modules, overlays or library functions in your NixOS configuration.nix, you need to take care to not introduce infinite recursion. Specifically, you need to import NUR like this in the modules:
94+
95+
```nix
96+
{ pkgs, config, lib, ... }:
97+
let
98+
nur-no-pkgs = import (builtins.fetchTarball "https://github.com/nix-community/NUR/archive/master.tar.gz") {};
99+
in {
100+
101+
imports = [
102+
nur-no-pkgs.repos.paul.modules.foo
103+
];
104+
105+
nixpkgs.overlays = [
106+
nur-no-pkgs.repos.ben.overlays.bar
107+
];
108+
109+
}
110+
```
76111

77112
## How to add your own repository.
78113

79114
First create a repository that contains a `default.nix` in its top-level directory.
80115

81116
DO NOT import packages for example `with import <nixpkgs> {};`.
82-
Instead take all dependency you want to import from Nixpkgs by function arguments.
117+
Instead take all dependency you want to import from Nixpkgs from the given `pkgs` and `lib` arguments.
83118
Each repository should return a set of Nix derivations:
84119

85120
```nix
86-
{ callPackage }:
121+
{ pkgs, lib }:
87122
{
88-
inxi = callPackage ./inxi {};
123+
inxi = pkgs.callPackage ./inxi {};
89124
}
90125
```
91126

@@ -135,13 +170,26 @@ in stdenv.mkDerivation rec {
135170
You can use `nix-shell` or `nix-build` to build your packages:
136171

137172
```console
138-
$ nix-shell -E 'with import <nixpkgs>{}; (callPackage ./default.nix {}).inxi'
173+
$ nix-shell --arg pkgs 'import <nixpkgs> {}' -A inxi
139174
nix-shell> inxi
140175
nix-shell> find $buildInputs
141176
```
142177

143178
```console
144-
$ nix-build -E 'with import <nixpkgs>{}; (callPackage ./default.nix {})'
179+
$ nix-build --arg pkgs 'import <nixpkgs> {}' -A inxi
180+
```
181+
182+
For development convenience, you can also set a default value for the pkgs argument:
183+
184+
```nix
185+
{ pkgs ? import <nixpkgs> {} }:
186+
{
187+
inxi = pkgs.callPackage ./inxi {};
188+
}
189+
```
190+
191+
```console
192+
$ nix-build -A inxi
145193
```
146194

147195
Add your own repository to in the `repos.json` of NUR:
@@ -181,7 +229,7 @@ and open a pull request towards [https://github.com/nix-community/NUR](https://g
181229
At the moment repositories should be buildable on Nixpkgs unstable. Later we
182230
will add options to also provide branches for other Nixpkgs channels.
183231

184-
## Use a different nix file as root expression
232+
### Use a different nix file as root expression
185233

186234
To use a different file instead of `default.nix` to load packages from, set the `file`
187235
option to a path relative to the repository root:
@@ -197,7 +245,7 @@ option to a path relative to the repository root:
197245
}
198246
```
199247

200-
## Update NUR's lock file after updating your repository
248+
### Update NUR's lock file after updating your repository
201249

202250
By default we only check for repository updates once a day with an automatic
203251
cron job in travis ci to update our lock file `repos.json.lock`.
@@ -210,7 +258,7 @@ curl -XPOST https://nur-update.herokuapp.com/update?repo=mic92
210258

211259
Check out the [github page](https://github.com/nix-community/nur-update#nur-update-endpoint) for further details
212260

213-
## Git submodules
261+
### Git submodules
214262

215263
To fetch git submodules in repositories set `submodules`:
216264

@@ -225,49 +273,43 @@ To fetch git submodules in repositories set `submodules`:
225273
}
226274
```
227275

228-
<!--
229-
This currently does not work as advertised at least for modules
276+
### NixOS modules, overlays and library function support
230277

231-
## Conventions for NixOS modules, overlays and library functions
278+
It is also possible to define more than just packages. In fact any Nix expression can be used.
232279

233280
To make NixOS modules, overlays and library functions more discoverable,
234281
we propose to put them in their own namespace within the repository.
235282
This allows us to make them later searchable, when the indexer is ready.
236283

237-
Put all NixOS modules in the `modules` attribute of your repository:
284+
285+
#### Providing NixOS modules
286+
287+
NixOS modules should be placed in the `modules` attribute:
238288

239289
```nix
240-
# default.nix
241-
{
242-
modules = ./import modules;
290+
{ pkgs }: {
291+
modules = import ./modules;
243292
}
244293
```
245294

246295
```nix
247296
# modules/default.nix
248297
{
249-
example-module = ./import example-module.nix;
298+
example-module = import ./example-module.nix;
250299
}
251300
```
252301

253302
An example can be found [here](https://github.com/Mic92/nur-packages/tree/master/modules).
254303

255-
The resulting module can be then added to `imports = [];` within `configuration.nix`:
256-
257-
```nix
258-
# /etc/nixos/configuration.nix
259-
{...}: {
260-
imports = [ nur.repos.mic92.modules.transocks ];
261-
}
262-
```
304+
#### Providing Overlays
263305

264306
For overlays use the `overlays` attribute:
265307

266308
```nix
267309
# default.nix
268310
{
269311
overlays = {
270-
hello-overlay = ./import hello-overlay;
312+
hello-overlay = import ./hello-overlay;
271313
};
272314
}
273315
```
@@ -293,10 +335,12 @@ The result can be used like this:
293335
}
294336
```
295337

296-
Put reusable nix functions that are intend for public use in the `lib` attribute:
338+
#### Providing library functions
339+
340+
Put reusable nix functions that are intend for public use in the `lib` attribute. Make sure to use the given `lib` argument instead of `pkgs.lib` if you depend on nixpkgs functions.
297341

298342
```nix
299-
{ lib }:
343+
{ pkgs, lib }:
300344
with lib;
301345
{
302346
lib = {
@@ -307,7 +351,7 @@ with lib;
307351
};
308352
}
309353
```
310-
-->
354+
311355

312356
## Contribution guideline
313357

0 commit comments

Comments
 (0)