Skip to content

Commit

Permalink
Merge branch 'master' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
vcunat committed Dec 12, 2017
2 parents 19dbfb6 + 5eb4a83 commit c2b6795
Show file tree
Hide file tree
Showing 116 changed files with 4,352 additions and 2,533 deletions.
163 changes: 162 additions & 1 deletion doc/languages-frameworks/rust.md
Expand Up @@ -20,7 +20,7 @@ For daily builds (beta and nightly) use either rustup from
nixpkgs or use the [Rust nightlies
overlay](#using-the-rust-nightlies-overlay).

## Packaging Rust applications
## Compiling Rust applications with Cargo

Rust applications are packaged by using the `buildRustPackage` helper from `rustPlatform`:

Expand Down Expand Up @@ -56,6 +56,167 @@ checksum can be then take from the failed build.
To install crates with nix there is also an experimental project called
[nixcrates](https://github.com/fractalide/nixcrates).

## Compiling Rust crates using Nix instead of Cargo

When run, `cargo build` produces a file called `Cargo.lock`,
containing pinned versions of all dependencies. Nixpkgs contains a
tool called `carnix` (`nix-env -iA nixos.carnix`), which can be used
to turn a `Cargo.lock` into a Nix expression.

That Nix expression calls `rustc` directly (hence bypassing Cargo),
and can be used to compile a crate and all its dependencies. Here is
an example for a minimal `hello` crate:


$ cargo new hello
$ cd hello
$ cargo build
Compiling hello v0.1.0 (file:///tmp/hello)
Finished dev [unoptimized + debuginfo] target(s) in 0.20 secs
$ carnix -o hello.nix --src ./. Cargo.lock --standalone
$ nix-build hello.nix

Now, the file produced by the call to `carnix`, called `hello.nix`, looks like:

```
with import <nixpkgs> {};
let kernel = buildPlatform.parsed.kernel.name;
# ... (content skipped)
hello_0_1_0_ = { dependencies?[], buildDependencies?[], features?[] }: buildRustCrate {
crateName = "hello";
version = "0.1.0";
authors = [ "Authorname <user@example.com>" ];
src = ./.;
inherit dependencies buildDependencies features;
};
in
rec {
hello_0_1_0 = hello_0_1_0_ rec {};
}
```

In particular, note that the argument given as `--src` is copied
verbatim to the source. If we look at a more complicated
dependencies, for instance by adding a single line `libc="*"` to our
`Cargo.toml`, we first need to run `cargo build` to update the
`Cargo.lock`. Then, `carnix` needs to be run again, and produces the
following nix file:

```
with import <nixpkgs> {};
let kernel = buildPlatform.parsed.kernel.name;
# ... (content skipped)
hello_0_1_0_ = { dependencies?[], buildDependencies?[], features?[] }: buildRustCrate {
crateName = "hello";
version = "0.1.0";
authors = [ "Jörg Thalheim <joerg@thalheim.io>" ];
src = ./.;
inherit dependencies buildDependencies features;
};
libc_0_2_34_ = { dependencies?[], buildDependencies?[], features?[] }: buildRustCrate {
crateName = "libc";
version = "0.2.34";
authors = [ "The Rust Project Developers" ];
sha256 = "11jmqdxmv0ka10ay0l8nzx0nl7s2lc3dbrnh1mgbr2grzwdyxi2s";
inherit dependencies buildDependencies features;
};
in
rec {
hello_0_1_0 = hello_0_1_0_ rec {
dependencies = [ libc_0_2_34 ];
};
libc_0_2_34_features."default".from_hello_0_1_0__default = true;
libc_0_2_34 = libc_0_2_34_ rec {
features = mkFeatures libc_0_2_34_features;
};
libc_0_2_34_features."use_std".self_default = hasDefault libc_0_2_34_features;
}
```

Here, the `libc` crate has no `src` attribute, so `buildRustCrate`
will fetch it from [crates.io](https://crates.io). A `sha256`
attribute is still needed for Nix purity.

Some crates require external libraries. For crates from
[crates.io](https://crates.io), such libraries can be specified in
`defaultCrateOverrides` package in nixpkgs itself.

Starting from that file, one can add more overrides, to add features
or build inputs by overriding the hello crate in a seperate file.

```
with import <nixpkgs> {};
(import ./hello.nix).hello_0_1_0.override {
crateOverrides = defaultCrateOverrides // {
hello = attrs: { buildInputs = [ openssl ]; };
};
}
```

Here, `crateOverrides` is expected to be a attribute set, where the
key is the crate name without version number and the value a function.
The function gets all attributes passed to `buildRustCrate` as first
argument and returns a set that contains all attribute that should be
overwritten.

For more complicated cases, such as when parts of the crate's
derivation depend on the the crate's version, the `attrs` argument of
the override above can be read, as in the following example, which
patches the derivation:

```
with import <nixpkgs> {};
(import ./hello.nix).hello_0_1_0.override {
crateOverrides = defaultCrateOverrides // {
hello = attrs: lib.optionalAttrs (lib.versionAtLeast attrs.version "1.0") {
postPatch = ''
substituteInPlace lib/zoneinfo.rs \
--replace "/usr/share/zoneinfo" "${tzdata}/share/zoneinfo"
'';
};
};
}
```

Another situation is when we want to override a nested
dependency. This actually works in the exact same way, since the
`crateOverrides` parameter is forwarded to the crate's
dependencies. For instance, to override the build inputs for crate
`libc` in the example above, where `libc` is a dependency of the main
crate, we could do:

```
with import <nixpkgs> {};
(import hello.nix).hello_0_1_0.override {
crateOverrides = defaultCrateOverrides // {
libc = attrs: { buildInputs = []; };
};
}
```

Three more parameters can be overridden:

- The version of rustc used to compile the crate:

```
hello_0_1_0.override { rust = pkgs.rust; };
```

- Whether to build in release mode or debug mode (release mode by
default):

```
hello_0_1_0.override { release = false; };
```

- Whether to print the commands sent to rustc when building
(equivalent to `--verbose` in cargo:

```
hello_0_1_0.override { verbose = false; };
```


## Using the Rust nightlies overlay

Mozilla provides an overlay for nixpkgs to bring a nightly version of Rust into scope.
Expand Down
2 changes: 2 additions & 0 deletions lib/maintainers.nix
Expand Up @@ -433,6 +433,7 @@
mog = "Matthew O'Gorman <mog-lists@rldn.net>";
montag451 = "montag451 <montag451@laposte.net>";
moosingin3space = "Nathan Moos <moosingin3space@gmail.com>";
moredread = "André-Patrick Bubel <code@apb.name>";
moretea = "Maarten Hoogendoorn <maarten@moretea.nl>";
mornfall = "Petr Ročkai <me@mornfall.net>";
MostAwesomeDude = "Corbin Simpson <cds@corbinsimpson.com>";
Expand Down Expand Up @@ -516,6 +517,7 @@
plcplc = "Philip Lykke Carlsen <plcplc@gmail.com>";
plumps = "Maksim Bronsky <maks.bronsky@web.de";
pmahoney = "Patrick Mahoney <pat@polycrystal.org>";
pmeunier = "Pierre-Étienne Meunier <pierre-etienne.meunier@inria.fr>";
pmiddend = "Philipp Middendorf <pmidden@secure.mailbox.org>";
polyrod = "Maurizio Di Pietro <dc1mdp@gmail.com>";
pradeepchhetri = "Pradeep Chhetri <pradeep.chhetri89@gmail.com>";
Expand Down
6 changes: 6 additions & 0 deletions nixos/doc/manual/release-notes/rl-1803.xml
Expand Up @@ -131,6 +131,12 @@ following incompatible changes:</para>
must be set to true.
</para>
</listitem>
<listitem>
<para>
The option <option>services.logstash.listenAddress</option> is now <literal>127.0.0.1</literal> by default.
Previously the default behaviour was to listen on all interfaces.
</para>
</listitem>
</itemizedlist>

</section>
Expand Down
2 changes: 0 additions & 2 deletions nixos/lib/make-disk-image.nix
Expand Up @@ -150,8 +150,6 @@ in pkgs.vmTools.runInLinuxVM (
}
''
${if partitioned then ''
. /sys/class/block/vda1/uevent
mknod /dev/vda1 b $MAJOR $MINOR
rootDisk=/dev/vda1
'' else ''
rootDisk=/dev/vda
Expand Down
7 changes: 4 additions & 3 deletions nixos/modules/installer/tools/nix-fallback-paths.nix
@@ -1,5 +1,6 @@
{
x86_64-linux = "/nix/store/b4s1gxiis1ryvybnjhdjvgc5sr1nq0ys-nix-1.11.15";
i686-linux = "/nix/store/kgb5hs7qw13bvb6icramv1ry9dard3h9-nix-1.11.15";
x86_64-darwin = "/nix/store/dgwz3dxdzs2wwd7pg7cdhvl8rv0qpnbj-nix-1.11.15";
x86_64-linux = "/nix/store/gy4yv67gv3j6in0lalw37j353zdmfcwm-nix-1.11.16";
i686-linux = "/nix/store/ifmyq5ryfxhhrzh62hiq65xyz1fwffga-nix-1.11.16";
aarch64-linux = "/nix/store/y9mfv3sx75mbfibf1zna1kq9v98fk2nb-nix-1.11.16";
x86_64-darwin = "/nix/store/hwpp7kia2f0in5ns2hiw41q38k30jpj2-nix-1.11.16";
}
2 changes: 1 addition & 1 deletion nixos/modules/services/logging/logstash.nix
Expand Up @@ -103,7 +103,7 @@ in

listenAddress = mkOption {
type = types.str;
default = "0.0.0.0";
default = "127.0.0.1";
description = "Address on which to start webserver.";
};

Expand Down
19 changes: 18 additions & 1 deletion nixos/modules/services/networking/networkmanager.nix
Expand Up @@ -241,6 +241,19 @@ in {
A list of scripts which will be executed in response to network events.
'';
};

enableStrongSwan = mkOption {
type = types.bool;
default = false;
description = ''
Enable the StrongSwan plugin.
</para><para>
If you enable this option the
<literal>networkmanager_strongswan</literal> plugin will be added to
the <option>networking.networkmanager.packages</option> option
so you don't need to to that yourself.
'';
};
};
};

Expand Down Expand Up @@ -335,7 +348,11 @@ in {

security.polkit.extraConfig = polkitConf;

services.dbus.packages = cfg.packages;
networking.networkmanager.packages =
mkIf cfg.enableStrongSwan [ pkgs.networkmanager_strongswan ];

services.dbus.packages =
optional cfg.enableStrongSwan pkgs.strongswanNM ++ cfg.packages;

services.udev.packages = cfg.packages;
};
Expand Down
5 changes: 5 additions & 0 deletions nixos/modules/virtualisation/containers.nix
Expand Up @@ -726,6 +726,11 @@ in

networking.dhcpcd.denyInterfaces = [ "ve-*" "vb-*" ];

services.udev.extraRules = optionalString config.networking.networkmanager.enable ''
# Don't manage interfaces created by nixos-container.
ENV{INTERFACE}=="v[eb]-*", ENV{NM_UNMANAGED}="1"
'';

environment.systemPackages = [ pkgs.nixos-container ];
});
}
2 changes: 1 addition & 1 deletion nixos/tests/radicale.nix
Expand Up @@ -20,7 +20,7 @@ let
'';
};
# WARNING: DON'T DO THIS IN PRODUCTION!
# This puts secrets (albeit hashed) directly into the Nix store for ease of testing.
# This puts unhashed secrets directly into the Nix store for ease of testing.
environment.etc."radicale/htpasswd".source = pkgs.runCommand "htpasswd" {} ''
${pkgs.apacheHttpd}/bin/htpasswd -bcB "$out" ${user} ${password}
'';
Expand Down
6 changes: 3 additions & 3 deletions pkgs/applications/audio/calf/default.nix
Expand Up @@ -3,14 +3,14 @@

stdenv.mkDerivation rec {
name = "calf-${version}";
version = "0.0.60";
version = "0.90.0";

src = fetchurl {
url = "http://calf-studio-gear.org/files/${name}.tar.gz";
sha256 = "019fwg00jv217a5r767z7szh7vdrarybac0pr2sk26xp81kibrx9";
sha256 = "0dijv2j7vlp76l10s4v8gbav26ibaqk8s24ci74vrc398xy00cib";
};

buildInputs = [
buildInputs = [
cairo expat fftwSinglePrec fluidsynth glib gtk2 libjack2 ladspaH
libglade lv2 pkgconfig
];
Expand Down
18 changes: 9 additions & 9 deletions pkgs/applications/audio/distrho/default.nix
Expand Up @@ -2,12 +2,12 @@
, libxslt, lv2, pkgconfig, premake3, xorg, ladspa-sdk }:

stdenv.mkDerivation rec {
name = "distrho-ports-unstable-2017-08-04";
name = "distrho-ports-unstable-2017-10-10";

src = fetchgit {
url = "https://github.com/DISTRHO/DISTRHO-Ports.git";
rev = "f591a1066cd3929536699bb516caa4b5efd9d025";
sha256 = "1qjnmpmwbq2zpwn8v1dmqn3bjp2ykj5p89fkjax7idgpx1cg7pp9";
rev = "e11e2b204c14b8e370a0bf5beafa5f162fedb8e9";
sha256 = "1nd542iian9kr2ldaf7fkkgf900ryzqigks999d1jhms6p0amvfv";
};

patchPhase = ''
Expand Down Expand Up @@ -37,12 +37,12 @@ stdenv.mkDerivation rec {
description = "A collection of cross-platform audio effects and plugins";
longDescription = ''
Includes:
Dexed drowaudio-distortion drowaudio-distortionshaper drowaudio-flanger
drowaudio-reverb drowaudio-tremolo drumsynt EasySSP eqinox
JuceDemoPlugin klangfalter LUFSMeter luftikus obxd pitchedDelay
stereosourceseparation TAL-Dub-3 TAL-Filter TAL-Filter-2 TAL-NoiseMaker
TAL-Reverb TAL-Reverb-2 TAL-Reverb-3 TAL-Vocoder-2 TheFunction
ThePilgrim Vex Wolpertinger
Dexed drowaudio-distortion drowaudio-distortionshaper drowaudio-flanger
drowaudio-reverb drowaudio-tremolo drumsynth EasySSP eqinox HiReSam
JuceDemoPlugin KlangFalter LUFSMeter LUFSMeterMulti Luftikus Obxd
PitchedDelay ReFine StereoSourceSeparation TAL-Dub-3 TAL-Filter
TAL-Filter-2 TAL-NoiseMaker TAL-Reverb TAL-Reverb-2 TAL-Reverb-3
TAL-Vocoder-2 TheFunction ThePilgrim Vex Wolpertinger
'';
maintainers = [ maintainers.goibhniu ];
platforms = platforms.linux;
Expand Down
10 changes: 5 additions & 5 deletions pkgs/applications/audio/mod-distortion/default.nix
@@ -1,19 +1,19 @@
{ stdenv, fetchFromGitHub, lv2 }:

stdenv.mkDerivation rec {
name = "mod-distortion-${version}";
version = "git-2015-05-18";
name = "mod-distortion-git-${version}";
version = "2016-08-19";

src = fetchFromGitHub {
owner = "portalmod";
repo = "mod-distortion";
rev = "0cdf186abc2a9275890b57057faf5c3f6d86d84a";
sha256 = "1wmxgpcdcy9m7j78yq85824if0wz49wv7mw13bj3sw2s87dcmw19";
rev = "e672d5feb9d631798e3d56eb96e8958c3d2c6821";
sha256 = "005wdkbhn9dgjqv019cwnziqg86yryc5vh7j5qayrzh9v446dw34";
};

buildInputs = [ lv2 ];

installFlags = [ "LV2_PATH=$(out)/lib/lv2" ];
installFlags = [ "INSTALL_PATH=$(out)/lib/lv2" ];

meta = with stdenv.lib; {
homepage = https://github.com/portalmod/mod-distortion;
Expand Down
4 changes: 2 additions & 2 deletions pkgs/applications/graphics/ImageMagick/7.0.nix
Expand Up @@ -14,8 +14,8 @@ let
else throw "ImageMagick is not supported on this platform.";

cfg = {
version = "7.0.7-9";
sha256 = "0p0879chcfrghcamwgxxcmaaj04xv0z91ris7hxi37qdw8c7836w";
version = "7.0.7-14";
sha256 = "04hpc9i6fp09iy0xkidlfhfqr7zg45izqqj5fx93n3dxalq65xqw";
patches = [];
};
in
Expand Down
4 changes: 2 additions & 2 deletions pkgs/applications/graphics/ImageMagick/default.nix
Expand Up @@ -14,8 +14,8 @@ let
else throw "ImageMagick is not supported on this platform.";

cfg = {
version = "6.9.9-23";
sha256 = "0cd6zcbcfvznf0i3q4xz1c4wm4cfplg4zc466lvlb1w8qbn25948";
version = "6.9.9-26";
sha256 = "10rcq7b9hhz50m4yqnm4g3iai7lr9jkglb7sm49ycw59arrkmwnw";
patches = [];
}
# Freeze version on mingw so we don't need to port the patch too often.
Expand Down

0 comments on commit c2b6795

Please sign in to comment.