Compare commits

...

69 Commits

Author SHA1 Message Date
Eelco Dolstra
2097983218 Doh 2020-02-18 21:30:31 +01:00
Eelco Dolstra
2f0122b23c Disable the progress bar if $TERM == dumb or unset
Fixes #3363.

(cherry picked from commit d8fd31f50f)
2020-02-18 18:36:33 +01:00
Eelco Dolstra
db3d3a5618 Build with large config Boehm GC
(cherry picked from commit 583d06385d)
2020-02-18 18:02:58 +01:00
Eelco Dolstra
91030eae50 Enable debug symbols
(cherry picked from commit f46bc0e8eb)
2020-02-18 18:00:54 +01:00
Eelco Dolstra
8950ae95a4 Disable shellcheck
It's broken at the moment: https://hydra.nixos.org/build/105746055

Also it pulls in GHC which is a pretty big dependency.

(cherry picked from commit b4e260d887)
2020-02-18 16:57:46 +01:00
Benjamin Hipple
6605ea0197 doc: touchup release notes for 2.3
- At the top of the release notes, we announce sandboxing is now enabled by default,
then at the bottom it says it's now disabled when missing kernel support. These
can be merged into one point for clarity.

- The point about `max-jobs` defaulting to 1 appears unrelated to sandboxing.

(cherry picked from commit 5d24e18e29)
2020-02-18 16:45:56 +01:00
Robin Gloster
b51ecc02c8 structured-attrs: chown .attrs.* files to builder
Otherwise `chmod .`'ing the build directory doesn't work anymore, which
is done in nixpkgs if sourceRoot is set to '.'.

(cherry picked from commit f8dbde0813)
2020-02-18 16:45:43 +01:00
Domen Kožar
ed25fdd66e retry on HTTP status code 429
(cherry picked from commit 48ddb8e481)
2020-02-18 16:45:34 +01:00
Eelco Dolstra
475c2e5de7 Bump version number 2020-02-18 16:44:55 +01:00
Eelco Dolstra
e3eecb5927 Move #include
(cherry picked from commit 8beedd4486)
(cherry picked from commit 0678e4d56a)
2020-01-05 16:30:52 +01:00
Eelco Dolstra
f84c3f9d65 Hide FunctionCallTrace constructor/destructor
This prevents them from being inlined. On gcc 9, this reduces the
stack size needed for

  nix-instantiate '<nixpkgs>' -A texlive.combined.scheme-full --dry-run

from 12.9 MiB to 4.8 MiB.

(cherry picked from commit cb90e382b5)
2020-01-05 16:30:38 +01:00
zimbatm
c94fd5f51a function-trace: always show the trace
If the user invokes nix with --trace-function-calls it means that they
want to see the trace.

(cherry picked from commit 619cc4af85)
2020-01-05 16:30:32 +01:00
Eelco Dolstra
60429b86ba .version: Remove newline 2020-01-04 14:16:04 +01:00
Arnout Engelen
95be8d3b12 Document builtins.placeholder
(cherry picked from commit 4e70652ee3)
2020-01-04 14:12:22 +01:00
Puck Meerburg
9879e25473 Add testcase for attrset using __overrides and dynamic attrs
(cherry picked from commit cdadbf7708)
2020-01-04 14:12:18 +01:00
Puck Meerburg
59bbc31701 Ensure enough space in attrset bindings when using both __overrides and dynamic attributes
(cherry picked from commit cd55f91ad2)
2020-01-04 14:12:13 +01:00
Maximilian Bosch
195cc3f883 doc: Document --dry-run option for nix-build
(cherry picked from commit 52ffe2797a)
2020-01-04 14:11:52 +01:00
Kevin Stock
a118444f36 docs: correct default location of log directory
(cherry picked from commit cea05e5ee7)
2020-01-04 14:11:31 +01:00
Robin Gloster
3130aafd01 builtins.toJSON: fix __toString usage
(cherry picked from commit e583df5280)
2020-01-04 14:10:56 +01:00
Eelco Dolstra
6c90e3b9ac install-multi-user.sh: Remove unused variables
https://hydra.nixos.org/build/104119659
(cherry picked from commit 2f96a89646)
2020-01-04 14:10:29 +01:00
Chaz Schlarp
9f524d9423 Remove superfluous IAM action for S3 cache
`s3:ListObjects` isn't a real IAM action, but _is_ the name of an S3 API method. `s3:ListBucket` is the relevant action for that method.

https://docs.aws.amazon.com/IAM/latest/UserGuide/list_amazons3.html
(cherry picked from commit c92ea927e5)
2020-01-04 14:10:23 +01:00
Ersin Akinci
93d6814847 Tweak path hint
(cherry picked from commit f107a27002)
2020-01-04 14:10:19 +01:00
Ersin Akinci
e9c0c772b0 Add hint about path in builtins.import
(cherry picked from commit b7a936224e)
2020-01-04 14:10:15 +01:00
Ersin Akinci
1ea63a5931 Revert "Document import <path> syntax"
This reverts commit d8730fb86f.

(cherry picked from commit 9be7787ec0)
2020-01-04 14:09:59 +01:00
Steven Shaw
e1fb586138 Fix unset variable in installer
(cherry picked from commit f0ec4b4ce4)
2020-01-04 14:09:14 +01:00
Dan Callahan
34bf1a8b5f Make nix-daemon.plist less fragile on macOS
We're calling `wait4path` on the full, resolved `@bindir@/nix-daemon` path.

That means we're hardcoding something like:

    /bin/wait4path /nix/store/zs9c5xhp3zv9p23qnjxp87nl5injsi1i-nix-2.3/bin/nix-daemon &amp;&amp; /nix/var/nix/profiles/default/bin/nix-daemon

That seems unnecessarily fragile.

It might be better to wait4path on the path we intend to call.

(cherry picked from commit 8c4a5e7ba1)
2020-01-04 14:07:41 +01:00
Matthew Bauer
7a011ded77 Copy instead of linking launch agent
On Catalina, the /nix filesystem might not be mounted at start time.
To avoid this service not starting, we need to keep the launch agent
outside of the Nix store. A wait4pid will hold for our /nix dir to be
mounted.

Fixes #3125.

(cherry picked from commit 0847f2f1b3)
2020-01-04 14:06:29 +01:00
Eelco Dolstra
eacc510572 Bump version number 2020-01-04 14:04:38 +01:00
Eelco Dolstra
9cf52dd1cc Disable the evalNixOS test
It also OOMs.

https://hydra.nixos.org/build/105942679
(cherry picked from commit 99af822004)
2020-01-04 14:02:40 +01:00
Eelco Dolstra
5526f725a8 Disable the evalNixpkgs test
It constantly OOMs.

https://hydra.nixos.org/build/105784912
(cherry picked from commit 35732a95bc)
2020-01-04 14:02:35 +01:00
Matthew Bauer
421f1f4493 Move tmpDirInSandbox to initTmpDir
(cherry picked from commit 96c84937c4)
2020-01-04 13:41:42 +01:00
Matthew Bauer
10bf5340ca Fix sandbox fallback settings
The tmpDirInSandbox is different when in sandboxed vs. non-sandboxed.
Since we don’t know ahead of time here whether sandboxing is enabled,
we need to reset all of the env vars we’ve set previously. This fixes
the issue encountered in https://github.com/NixOS/nixpkgs/issues/70856.

(cherry picked from commit 499b038875)
2020-01-04 13:41:35 +01:00
Eelco Dolstra
8b44ed08e7 ssh-ng: Don't set CPU affinity on the remote
Fixes #3138.

(cherry picked from commit 906d56a96b)
2020-01-04 13:41:06 +01:00
Eelco Dolstra
1ac8c0269a SourceExprCommand::getSourceExpr(): Allocate more space
Fixes #3140.

(cherry picked from commit 389a2cebed)
2020-01-04 13:40:56 +01:00
Ersin Akinci
c7b4bf1c9c Document import <path> syntax
(cherry picked from commit d8730fb86f)
2020-01-04 13:40:46 +01:00
ng0
a53e4e217b include netinet/in.h in src/nix/main.cc
Fixes #3186

(cherry picked from commit b811bd2172)
2020-01-04 13:40:14 +01:00
Harald van Dijk
61855a4e7b Fix progress bar when nix-prefetch-url is piped.
The intent of the code was that if the window size cannot be determined,
it would be treated as having the maximum possible size. Because of a
missing assignment, it was actually treated as having a width of 0.

The reason the width could not be determined was because it was obtained
from stdout, not stderr, even though the printing was done to stderr.

This commit addresses both issues.

(cherry picked from commit c935ad3f02)
2020-01-04 13:40:03 +01:00
Brian Wignall
9b4e99801f Fix typos
(cherry picked from commit 8737980e75)
2020-01-04 13:39:19 +01:00
Eelco Dolstra
8be0440d44 EvalState::callFunction(): Make FunctionCallTrace use less stack space
The FunctionCallTrace object consumes a few hundred bytes of stack
space, even when tracing is disabled. This was causing stack overflows:

  $ nix-instantiate '<nixpkgs> -A texlive.combined.scheme-full --dry-run
  error: stack overflow (possible infinite recursion)

This is with the default stack size of 8 MiB.

Putting the object on the heap reduces stack usage to < 5 MiB.

(cherry picked from commit 98ef11677c)
2020-01-04 13:38:42 +01:00
Eelco Dolstra
61e816217b nix verify: Fix uninitialized variable
(cherry picked from commit 95cf23ee7c)
2019-10-10 15:03:46 +02:00
Eelco Dolstra
21f48ff26a nix-env: Ignore failures creating ~/.nix-profile and ~/.nix-defexpr
https://hydra.nixos.org/build/102803093
(cherry picked from commit c3aaf3b8da)
2019-10-10 09:42:22 +02:00
Eelco Dolstra
e3d44a3b83 Doh
https://hydra.nixos.org/build/102803044
(cherry picked from commit bda64a2b0f)
2019-10-10 00:14:59 +02:00
Eelco Dolstra
0fb4744467 nix-env: Create ~/.nix-defexpr automatically
(cherry picked from commit c9159f86cc)
2019-10-10 00:00:58 +02:00
Eelco Dolstra
f66108f738 nix-env: Create ~/.nix-profile automatically
(cherry picked from commit 9348f9291e)
2019-10-10 00:00:54 +02:00
Eelco Dolstra
2070d55b0b Force per-user group to a known value
(cherry picked from commit 20eec802ff)
2019-10-09 23:58:59 +02:00
Eelco Dolstra
fe51fbaf81 Typo
(cherry picked from commit 9277e72cb0)
2019-10-09 23:58:55 +02:00
Eelco Dolstra
7c4589854b Go back to 755 permission on per-user directories
700 is pointless since the store is world-readable anyway. And
per-user/root/channels must be world-readable.

(cherry picked from commit d7bae5680f)
2019-10-09 23:58:51 +02:00
Eelco Dolstra
1c10f739eb nix-profile.sh: Remove coreutils dependency
(cherry picked from commit 61a6176aca)
2019-10-09 23:57:41 +02:00
Eelco Dolstra
2522757e83 nix-profile.sh: Don't create .nix-channels
This is already done by the installer, so no need to do it again.

(cherry picked from commit 26762ceb86)
2019-10-09 23:57:35 +02:00
Eelco Dolstra
923b6bd83c Remove some redundant initialization
(cherry picked from commit c43d9f6131)
2019-10-09 23:57:30 +02:00
Eelco Dolstra
65953789bc Remove world-writability from per-user directories
'nix-daemon' now creates subdirectories for users when they first
connect.

Fixes #509 (CVE-2019-17365).
Should also fix #3127.

(cherry picked from commit 5a303093dc)
2019-10-09 23:57:25 +02:00
Eelco Dolstra
910b0fcc11 Filter ANSI escape sequences in -L output
Otherwise, builds like NixOS VM tests may leave the terminal in a
weird state and do resets.

(cherry picked from commit 4331eeb13d)
2019-10-09 23:57:14 +02:00
Eelco Dolstra
e232bf2b69 Bump version number 2019-10-09 16:26:03 +02:00
Silvan Mosberger
7c9ad4d0d7 docs: Note that tryEval doesn't do deep evaluation
(cherry picked from commit e4ea3e0306)
2019-10-09 16:25:42 +02:00
Eelco Dolstra
fa028194e9 Disable OpenSSL lock callback on OpenSSL >= 1.1.1
(cherry picked from commit a56b51a0ba)
2019-10-09 16:25:23 +02:00
Julien Tanguy
ff7fcd3805 docs: Fix a typo in github in an example
(cherry picked from commit 92ede15dd9)
2019-10-09 16:25:17 +02:00
Julien Tanguy
ceddbc921f docs: Use the explicit ref for fetchGit with a tag
With the merge of #2582, the syntax "tags/1.9" for refs does not work
anymore.
However, the new syntax "refs/tags/1.9" seems to support annotated tags,
such as "refs/tags/2.0".

Closes #2385.

(cherry picked from commit ae244af242)
2019-10-09 16:25:11 +02:00
Alexandre Esteves
62d1c60fb3 Move 'builtins.splitVersion' to position respecting alphabetical order
(cherry picked from commit 9533d85ce0)
2019-10-09 16:24:49 +02:00
zimbatm
f4106e76ff libstore: don't forward --show-trace
(cherry picked from commit e63c9e73e3)
2019-10-09 16:24:35 +02:00
Eelco Dolstra
f3ce4453a6 Don't catch exceptions by value
(cherry picked from commit 893be6f5e3)
(cherry picked from commit bd79c1f6f6)
2019-10-09 16:24:28 +02:00
Eelco Dolstra
9f53bc33e7 Shut up some warnings
(cherry picked from commit 99e8e58f2d)
(cherry picked from commit 3a022d4599)
2019-10-09 16:24:23 +02:00
Joseph Lucas
4d83eb6206 Update garbage-collection.xml readability
1. remove a typo space
2. Simplify negative style by using affirmative style

(cherry picked from commit 10bfc5c0d0)
2019-10-09 16:24:10 +02:00
Eelco Dolstra
3919093e9a Fix fetchTarball with chroot stores
Fixes #2405.

(cherry picked from commit 168a887916)
2019-10-09 16:23:49 +02:00
Sam Doshi
b0ae8fe2db nix search: remove verbose example
(cherry picked from commit 6f6cb5e388)
2019-10-09 16:23:39 +02:00
Danny Bautista
3c5788d094 Fix typos in the Nix Manual.
(cherry picked from commit 00a567588e)
2019-10-09 16:23:31 +02:00
Matthew Bauer
9f698c4530 Handle empty sandbox_shell
Previously, SANDBOX_SHELL was set to empty when unavailable. This
caused issues when actually generating the sandbox. Instead, just set
SANDBOX_SHELL when --with-sandbox-shell= is non-empty. Alternative
implementation to https://github.com/NixOS/nix/pull/3038.

(cherry picked from commit 199e888785)
2019-10-09 16:23:16 +02:00
Eelco Dolstra
1b78bbb414 nix search: Don't quietly ignore errors
(cherry picked from commit 7c74f075f4)
2019-10-09 16:23:00 +02:00
Eelco Dolstra
1d5cb6ad48 getSourceExpr(): Handle channels
Fixes #1892.
Fixes #1865.
Fixes #3119.

(cherry picked from commit e6e61f0a54)
2019-10-09 16:22:51 +02:00
Eelco Dolstra
22d4ea7a98 Tweak release notes 2019-09-04 16:00:03 +02:00
64 changed files with 345 additions and 300 deletions

View File

@@ -1 +1 @@
2.3 2.3.3

View File

@@ -1,12 +1,11 @@
#!/usr/bin/env nix-shell #!/usr/bin/env nix-shell
#!nix-shell -i python3 -p python3 --pure #!nix-shell -i python3 -p python3 --pure
# To be used with `--trace-function-calls` and `-vvvv` and # To be used with `--trace-function-calls` and `flamegraph.pl`.
# `flamegraph.pl`.
# #
# For example: # For example:
# #
# nix-instantiate --trace-function-calls -vvvv '<nixpkgs>' -A hello 2> nix-function-calls.trace # nix-instantiate --trace-function-calls '<nixpkgs>' -A hello 2> nix-function-calls.trace
# ./contrib/stack-collapse.py nix-function-calls.trace > nix-function-calls.folded # ./contrib/stack-collapse.py nix-function-calls.trace > nix-function-calls.folded
# nix-shell -p flamegraph --run "flamegraph.pl nix-function-calls.folded > nix-function-calls.svg" # nix-shell -p flamegraph --run "flamegraph.pl nix-function-calls.folded > nix-function-calls.svg"

View File

@@ -433,7 +433,7 @@ builtins.fetchurl {
<varlistentry xml:id="conf-keep-env-derivations"><term><literal>keep-env-derivations</literal></term> <varlistentry xml:id="conf-keep-env-derivations"><term><literal>keep-env-derivations</literal></term>
<listitem><para>If <literal>false</literal> (default), derivations <listitem><para>If <literal>false</literal> (default), derivations
are not stored in Nix user environments. That is, the derivation are not stored in Nix user environments. That is, the derivations of
any build-time-only dependencies may be garbage-collected.</para> any build-time-only dependencies may be garbage-collected.</para>
<para>If <literal>true</literal>, when you add a Nix derivation to <para>If <literal>true</literal>, when you add a Nix derivation to

View File

@@ -122,7 +122,7 @@ $ mount -o bind /mnt/otherdisk/nix /nix</screen>
<varlistentry><term><envar>NIX_LOG_DIR</envar></term> <varlistentry><term><envar>NIX_LOG_DIR</envar></term>
<listitem><para>Overrides the location of the Nix log directory <listitem><para>Overrides the location of the Nix log directory
(default <filename><replaceable>prefix</replaceable>/log/nix</filename>).</para></listitem> (default <filename><replaceable>prefix</replaceable>/var/log/nix</filename>).</para></listitem>
</varlistentry> </varlistentry>

View File

@@ -30,6 +30,7 @@
<replaceable>attrPath</replaceable> <replaceable>attrPath</replaceable>
</arg> </arg>
<arg><option>--no-out-link</option></arg> <arg><option>--no-out-link</option></arg>
<arg><option>--dry-run</option></arg>
<arg> <arg>
<group choice='req'> <group choice='req'>
<arg choice='plain'><option>--out-link</option></arg> <arg choice='plain'><option>--out-link</option></arg>
@@ -98,6 +99,10 @@ also <xref linkend="sec-common-options" />.</phrase></para>
</varlistentry> </varlistentry>
<varlistentry><term><option>--dry-run</option></term>
<listitem><para>Show what store paths would be built or downloaded</para></listitem>
</varlistentry>
<varlistentry xml:id='opt-out-link'><term><option>--out-link</option> / <varlistentry xml:id='opt-out-link'><term><option>--out-link</option> /
<option>-o</option> <replaceable>outlink</replaceable></term> <option>-o</option> <replaceable>outlink</replaceable></term>

View File

@@ -659,7 +659,7 @@ upgrading `mozilla-1.2' to `mozilla-1.4'</screen>
<literal>gcc-3.3.1</literal> are split into two parts: the package <literal>gcc-3.3.1</literal> are split into two parts: the package
name (<literal>gcc</literal>), and the version name (<literal>gcc</literal>), and the version
(<literal>3.3.1</literal>). The version part starts after the first (<literal>3.3.1</literal>). The version part starts after the first
dash not following by a letter. <varname>x</varname> is considered an dash not followed by a letter. <varname>x</varname> is considered an
upgrade of <varname>y</varname> if their package names match, and the upgrade of <varname>y</varname> if their package names match, and the
version of <varname>y</varname> is higher that that of version of <varname>y</varname> is higher that that of
<varname>x</varname>.</para> <varname>x</varname>.</para>

View File

@@ -53,7 +53,7 @@ avoided.</para>
<para>If <replaceable>hash</replaceable> is specified, then a download <para>If <replaceable>hash</replaceable> is specified, then a download
is not performed if the Nix store already contains a file with the is not performed if the Nix store already contains a file with the
same hash and base name. Otherwise, the file is downloaded, and an same hash and base name. Otherwise, the file is downloaded, and an
error if signaled if the actual hash of the file does not match the error is signaled if the actual hash of the file does not match the
specified hash.</para> specified hash.</para>
<para>This command prints the hash on standard output. Additionally, <para>This command prints the hash on standard output. Additionally,

View File

@@ -170,18 +170,6 @@ if builtins ? getEnv then builtins.getEnv "PATH" else ""</programlisting>
</varlistentry> </varlistentry>
<varlistentry xml:id='builtin-splitVersion'>
<term><function>builtins.splitVersion</function>
<replaceable>s</replaceable></term>
<listitem><para>Split a string representing a version into its
components, by the same version splitting logic underlying the
version comparison in <link linkend="ssec-version-comparisons">
<command>nix-env -u</command></link>.</para></listitem>
</varlistentry>
<varlistentry xml:id='builtin-concatLists'> <varlistentry xml:id='builtin-concatLists'>
<term><function>builtins.concatLists</function> <term><function>builtins.concatLists</function>
<replaceable>lists</replaceable></term> <replaceable>lists</replaceable></term>
@@ -301,7 +289,7 @@ if builtins ? getEnv then builtins.getEnv "PATH" else ""</programlisting>
<listitem><para>Return element <replaceable>n</replaceable> from <listitem><para>Return element <replaceable>n</replaceable> from
the list <replaceable>xs</replaceable>. Elements are counted the list <replaceable>xs</replaceable>. Elements are counted
starting from 0. A fatal error occurs in the index is out of starting from 0. A fatal error occurs if the index is out of
bounds.</para></listitem> bounds.</para></listitem>
</varlistentry> </varlistentry>
@@ -448,7 +436,7 @@ stdenv.mkDerivation { … }
<example> <example>
<title>Fetching an arbitrary ref</title> <title>Fetching an arbitrary ref</title>
<programlisting>builtins.fetchGit { <programlisting>builtins.fetchGit {
url = "https://gitub.com/NixOS/nix.git"; url = "https://github.com/NixOS/nix.git";
ref = "refs/heads/0.5-release"; ref = "refs/heads/0.5-release";
}</programlisting> }</programlisting>
</example> </example>
@@ -499,11 +487,8 @@ stdenv.mkDerivation { … }
<title>Fetching a tag</title> <title>Fetching a tag</title>
<programlisting>builtins.fetchGit { <programlisting>builtins.fetchGit {
url = "https://github.com/nixos/nix.git"; url = "https://github.com/nixos/nix.git";
ref = "tags/1.9"; ref = "refs/tags/1.9";
}</programlisting> }</programlisting>
<note><para>Due to a bug (<link
xlink:href="https://github.com/NixOS/nix/issues/2385">#2385</link>),
only non-annotated tags can be fetched.</para></note>
</example> </example>
<example> <example>
@@ -761,6 +746,11 @@ builtins.genList (x: x * x) 5
separate file, and use it from Nix expressions in other separate file, and use it from Nix expressions in other
files.</para> files.</para>
<note><para>Unlike some languages, <function>import</function> is a regular
function in Nix. Paths using the angle bracket syntax (e.g., <function>
import</function> <replaceable>&lt;foo&gt;</replaceable>) are normal path
values (see <xref linkend='ssec-values' />).</para></note>
<para>A Nix expression loaded by <function>import</function> must <para>A Nix expression loaded by <function>import</function> must
not contain any <emphasis>free variables</emphasis> (identifiers not contain any <emphasis>free variables</emphasis> (identifiers
that are not defined in the Nix expression itself and are not that are not defined in the Nix expression itself and are not
@@ -1130,6 +1120,16 @@ Evaluates to <literal>[ "foo" ]</literal>.
</varlistentry> </varlistentry>
<varlistentry xml:id='builtin-placeholder'>
<term><function>builtins.placeholder</function>
<replaceable>output</replaceable></term>
<listitem><para>Return a placeholder string for the specified
<replaceable>output</replaceable> that will be substituted by the
corresponding output path at build time. Typical outputs would be
<literal>"out"</literal>, <literal>"bin"</literal> or
<literal>"dev"</literal>.</para></listitem>
</varlistentry>
<varlistentry xml:id='builtin-readDir'> <varlistentry xml:id='builtin-readDir'>
<term><function>builtins.readDir</function> <term><function>builtins.readDir</function>
@@ -1275,6 +1275,19 @@ Evaluates to <literal>[ " " [ "FOO" ] " " ]</literal>.
</para></listitem> </para></listitem>
</varlistentry> </varlistentry>
<varlistentry xml:id='builtin-splitVersion'>
<term><function>builtins.splitVersion</function>
<replaceable>s</replaceable></term>
<listitem><para>Split a string representing a version into its
components, by the same version splitting logic underlying the
version comparison in <link linkend="ssec-version-comparisons">
<command>nix-env -u</command></link>.</para></listitem>
</varlistentry>
<varlistentry xml:id='builtin-stringLength'> <varlistentry xml:id='builtin-stringLength'>
<term><function>builtins.stringLength</function> <term><function>builtins.stringLength</function>
<replaceable>e</replaceable></term> <replaceable>e</replaceable></term>
@@ -1468,7 +1481,7 @@ in foo</programlisting>
<listitem><para>A set containing <literal>{ __toString = self: ...; }</literal>.</para></listitem> <listitem><para>A set containing <literal>{ __toString = self: ...; }</literal>.</para></listitem>
<listitem><para>An integer.</para></listitem> <listitem><para>An integer.</para></listitem>
<listitem><para>A list, in which case the string representations of its elements are joined with spaces.</para></listitem> <listitem><para>A list, in which case the string representations of its elements are joined with spaces.</para></listitem>
<listitem><para>A Boolean (<literal>false</literal> yields <literal>""</literal>, <literal>true</literal> yields <literal>"1"</literal>.</para></listitem> <listitem><para>A Boolean (<literal>false</literal> yields <literal>""</literal>, <literal>true</literal> yields <literal>"1"</literal>).</para></listitem>
<listitem><para><literal>null</literal>, which yields the empty string.</para></listitem> <listitem><para><literal>null</literal>, which yields the empty string.</para></listitem>
</itemizedlist> </itemizedlist>
</listitem> </listitem>
@@ -1607,12 +1620,18 @@ stdenv.mkDerivation (rec {
<term><function>builtins.tryEval</function> <term><function>builtins.tryEval</function>
<replaceable>e</replaceable></term> <replaceable>e</replaceable></term>
<listitem><para>Try to evaluate <replaceable>e</replaceable>. <listitem><para>Try to shallowly evaluate <replaceable>e</replaceable>.
Return a set containing the attributes <literal>success</literal> Return a set containing the attributes <literal>success</literal>
(<literal>true</literal> if <replaceable>e</replaceable> evaluated (<literal>true</literal> if <replaceable>e</replaceable> evaluated
successfully, <literal>false</literal> if an error was thrown) and successfully, <literal>false</literal> if an error was thrown) and
<literal>value</literal>, equalling <replaceable>e</replaceable> <literal>value</literal>, equalling <replaceable>e</replaceable>
if successful and <literal>false</literal> otherwise. if successful and <literal>false</literal> otherwise. Note that this
doesn't evaluate <replaceable>e</replaceable> deeply, so
<literal>let e = { x = throw ""; }; in (builtins.tryEval e).success
</literal> will be <literal>true</literal>. Using <literal>builtins.deepSeq
</literal> one can get the expected result: <literal>let e = { x = throw "";
}; in (builtins.tryEval (builtins.deepSeq e e)).success</literal> will be
<literal>false</literal>.
</para></listitem> </para></listitem>
</varlistentry> </varlistentry>

View File

@@ -43,7 +43,7 @@ use <command>nix-build</command>s <option
linkend='opt-out-link'>-o</option> switch to give the symlink another linkend='opt-out-link'>-o</option> switch to give the symlink another
name.</para> name.</para>
<para>Nix has a transactional semantics. Once a build finishes <para>Nix has transactional semantics. Once a build finishes
successfully, Nix makes a note of this in its database: it registers successfully, Nix makes a note of this in its database: it registers
that the path denoted by <envar>out</envar> is now that the path denoted by <envar>out</envar> is now
<quote>valid</quote>. If you try to build the derivation again, Nix <quote>valid</quote>. If you try to build the derivation again, Nix

View File

@@ -52,12 +52,13 @@ garbage collector as follows:
<screen> <screen>
$ nix-store --gc</screen> $ nix-store --gc</screen>
The behaviour of the gargage collector is affected by the <literal>keep- The behaviour of the gargage collector is affected by the
derivations</literal> (default: true) and <literal>keep-outputs</literal> <literal>keep-derivations</literal> (default: true) and <literal>keep-outputs</literal>
(default: false) options in the Nix configuration file. The defaults will ensure (default: false) options in the Nix configuration file. The defaults will ensure
that all derivations that are not build-time dependencies of garbage collector roots that all derivations that are build-time dependencies of garbage collector roots
will be collected but that all output paths that are not runtime dependencies will be kept and that all output paths that are runtime dependencies
will be collected. (This is usually what you want, but while you are developing will be kept as well. All other derivations or paths will be collected.
(This is usually what you want, but while you are developing
it may make sense to keep outputs to ensure that rebuild times are quick.) it may make sense to keep outputs to ensure that rebuild times are quick.)
If you are feeling uncertain, you can also first view what files would If you are feeling uncertain, you can also first view what files would

View File

@@ -159,7 +159,6 @@ the S3 URL:</para>
"s3:ListBucket", "s3:ListBucket",
"s3:ListBucketMultipartUploads", "s3:ListBucketMultipartUploads",
"s3:ListMultipartUploadParts", "s3:ListMultipartUploadParts",
"s3:ListObjects",
"s3:PutObject" "s3:PutObject"
], ],
"Resource": [ "Resource": [

View File

@@ -13,9 +13,8 @@ incompatible changes:</para>
<listitem> <listitem>
<para>Nix now uses BSD file locks instead of POSIX file <para>Nix now uses BSD file locks instead of POSIX file
locks. Since previous releases used POSIX file locks, you should locks. Because of this, you should not use Nix 2.3 and previous
not use Nix 2.2 and previous releases at the same time on a Nix releases at the same time on a Nix store.</para>
store.</para>
</listitem> </listitem>
</itemizedlist> </itemizedlist>
@@ -34,9 +33,13 @@ incompatible changes:</para>
</listitem> </listitem>
<listitem> <listitem>
<para>The installer now enables sandboxing by default on <para>The installer now enables sandboxing by default on Linux when the
Linux. The <literal>max-jobs</literal> setting now defaults to system has the necessary kernel support.
1.</para> </para>
</listitem>
<listitem>
<para>The <literal>max-jobs</literal> setting now defaults to 1.</para>
</listitem> </listitem>
<listitem> <listitem>
@@ -47,9 +50,9 @@ incompatible changes:</para>
</listitem> </listitem>
<listitem> <listitem>
<para><command>nix</command>: Add <para>The <command>nix</command> command has a new
<option>--print-build-logs</option> (<option>-L</option>) flag to <option>--print-build-logs</option> (<option>-L</option>) flag to
print build log output to stderr rather than showing the last log print build log output to stderr, rather than showing the last log
line in the progress bar. To distinguish between concurrent line in the progress bar. To distinguish between concurrent
builds, log lines are prefixed by the name of the package. builds, log lines are prefixed by the name of the package.
</para> </para>
@@ -57,7 +60,7 @@ incompatible changes:</para>
<listitem> <listitem>
<para>Builds are now executed in a pseudo-terminal, and the <para>Builds are now executed in a pseudo-terminal, and the
<envar>TERM</envar> evnironment variable is set to <envar>TERM</envar> environment variable is set to
<literal>xterm-256color</literal>. This allows many programs <literal>xterm-256color</literal>. This allows many programs
(e.g. <command>gcc</command>, <command>clang</command>, (e.g. <command>gcc</command>, <command>clang</command>,
<command>cmake</command>) to print colorized log output.</para> <command>cmake</command>) to print colorized log output.</para>
@@ -83,11 +86,6 @@ incompatible changes:</para>
the duration of Nix function calls to stderr.</para> the duration of Nix function calls to stderr.</para>
</listitem> </listitem>
<listitem>
<para>On Linux, sandboxing is now disabled by default on systems
that dont have the necessary kernel support.</para>
</listitem>
</itemizedlist> </itemizedlist>
</section> </section>

View File

@@ -17,7 +17,7 @@
<array> <array>
<string>/bin/sh</string> <string>/bin/sh</string>
<string>-c</string> <string>-c</string>
<string>/bin/wait4path @bindir@/nix-daemon &amp;&amp; @bindir@/nix-daemon</string> <string>/bin/wait4path /nix/var/nix/profiles/default/bin/nix-daemon &amp;&amp; /nix/var/nix/profiles/default/bin/nix-daemon</string>
</array> </array>
<key>StandardErrorPath</key> <key>StandardErrorPath</key>
<string>/var/log/nix-daemon.log</string> <string>/var/log/nix-daemon.log</string>

View File

@@ -106,7 +106,7 @@ chmod 1775 $RPM_BUILD_ROOT/nix/store
for d in profiles gcroots; for d in profiles gcroots;
do do
mkdir -p $RPM_BUILD_ROOT/nix/var/nix/$d/per-user mkdir -p $RPM_BUILD_ROOT/nix/var/nix/$d/per-user
chmod 1777 $RPM_BUILD_ROOT/nix/var/nix/$d/per-user chmod 755 $RPM_BUILD_ROOT/nix/var/nix/$d/per-user
done done
# fix permission of nix profile # fix permission of nix profile

View File

@@ -50,7 +50,7 @@ rec {
buildDeps = buildDeps =
[ curl [ curl
bzip2 xz brotli editline bzip2 xz brotli editline
openssl pkgconfig sqlite boehmgc openssl pkgconfig sqlite
boost boost
# Tests # Tests
@@ -72,6 +72,10 @@ rec {
*/ */
})); }));
propagatedDeps =
[ (boehmgc.override { enableLargeConfig = true; })
];
perlDeps = perlDeps =
[ perl [ perl
perlPackages.DBDSQLite perlPackages.DBDSQLite

View File

@@ -23,7 +23,7 @@ let
src = nix; src = nix;
inherit officialRelease; inherit officialRelease;
buildInputs = tarballDeps ++ buildDeps; buildInputs = tarballDeps ++ buildDeps ++ propagatedDeps;
configureFlags = "--enable-gc"; configureFlags = "--enable-gc";
@@ -67,6 +67,8 @@ let
buildInputs = buildDeps; buildInputs = buildDeps;
propagatedBuildInputs = propagatedDeps;
preConfigure = preConfigure =
# Copy libboost_context so we don't get all of Boost in our closure. # Copy libboost_context so we don't get all of Boost in our closure.
# https://github.com/NixOS/nixpkgs/issues/45462 # https://github.com/NixOS/nixpkgs/issues/45462
@@ -91,6 +93,8 @@ let
doInstallCheck = true; doInstallCheck = true;
installCheckFlags = "sysconfdir=$(out)/etc"; installCheckFlags = "sysconfdir=$(out)/etc";
separateDebugInfo = true;
}); });
@@ -128,7 +132,7 @@ let
in in
runCommand "nix-binary-tarball-${version}" runCommand "nix-binary-tarball-${version}"
{ nativeBuildInputs = lib.optional (system != "aarch64-linux") shellcheck; { #nativeBuildInputs = lib.optional (system != "aarch64-linux") shellcheck;
meta.description = "Distribution-independent Nix bootstrap binaries for ${system}"; meta.description = "Distribution-independent Nix bootstrap binaries for ${system}";
} }
'' ''
@@ -196,7 +200,9 @@ let
name = "nix-build"; name = "nix-build";
src = tarball; src = tarball;
buildInputs = buildDeps; enableParallelBuilding = true;
buildInputs = buildDeps ++ propagatedDeps;
dontInstall = false; dontInstall = false;
@@ -271,6 +277,7 @@ let
umount /nix umount /nix
''); # */ ''); # */
/*
tests.evalNixpkgs = tests.evalNixpkgs =
import (nixpkgs + "/pkgs/top-level/make-tarball.nix") { import (nixpkgs + "/pkgs/top-level/make-tarball.nix") {
inherit nixpkgs; inherit nixpkgs;
@@ -289,6 +296,7 @@ let
touch $out touch $out
''; '';
*/
installerScript = installerScript =
@@ -326,8 +334,8 @@ let
tests.remoteBuilds tests.remoteBuilds
tests.nix-copy-closure tests.nix-copy-closure
tests.binaryTarball tests.binaryTarball
tests.evalNixpkgs #tests.evalNixpkgs
tests.evalNixOS #tests.evalNixOS
installerScript installerScript
]; ];
}; };

View File

@@ -39,7 +39,7 @@ EOF
poly_configure_nix_daemon_service() { poly_configure_nix_daemon_service() {
_sudo "to set up the nix-daemon as a LaunchDaemon" \ _sudo "to set up the nix-daemon as a LaunchDaemon" \
ln -sfn "/nix/var/nix/profiles/default$PLIST_DEST" "$PLIST_DEST" cp -f "/nix/var/nix/profiles/default$PLIST_DEST" "$PLIST_DEST"
_sudo "to load the LaunchDaemon plist for nix-daemon" \ _sudo "to load the LaunchDaemon plist for nix-daemon" \
launchctl load /Library/LaunchDaemons/org.nixos.nix-daemon.plist launchctl load /Library/LaunchDaemons/org.nixos.nix-daemon.plist

View File

@@ -19,9 +19,6 @@ readonly BLUE_UL='\033[38;4;34m'
readonly GREEN='\033[38;32m' readonly GREEN='\033[38;32m'
readonly GREEN_UL='\033[38;4;32m' readonly GREEN_UL='\033[38;4;32m'
readonly RED='\033[38;31m' readonly RED='\033[38;31m'
readonly RED_UL='\033[38;4;31m'
readonly YELLOW='\033[38;33m'
readonly YELLOW_UL='\033[38;4;33m'
readonly NIX_USER_COUNT="32" readonly NIX_USER_COUNT="32"
readonly NIX_BUILD_GROUP_ID="30000" readonly NIX_BUILD_GROUP_ID="30000"
@@ -529,24 +526,17 @@ create_build_users() {
} }
create_directories() { create_directories() {
# FIXME: remove all of this because it duplicates LocalStore::LocalStore().
_sudo "to make the basic directory structure of Nix (part 1)" \ _sudo "to make the basic directory structure of Nix (part 1)" \
mkdir -pv -m 0755 /nix /nix/var /nix/var/log /nix/var/log/nix /nix/var/log/nix/drvs /nix/var/nix{,/db,/gcroots,/profiles,/temproots,/userpool} mkdir -pv -m 0755 /nix /nix/var /nix/var/log /nix/var/log/nix /nix/var/log/nix/drvs /nix/var/nix{,/db,/gcroots,/profiles,/temproots,/userpool} /nix/var/nix/{gcroots,profiles}/per-user
_sudo "to make the basic directory structure of Nix (part 2)" \ _sudo "to make the basic directory structure of Nix (part 2)" \
mkdir -pv -m 1777 /nix/var/nix/{gcroots,profiles}/per-user
_sudo "to make the basic directory structure of Nix (part 3)" \
mkdir -pv -m 1775 /nix/store mkdir -pv -m 1775 /nix/store
_sudo "to make the basic directory structure of Nix (part 4)" \ _sudo "to make the basic directory structure of Nix (part 3)" \
chgrp "$NIX_BUILD_GROUP_NAME" /nix/store chgrp "$NIX_BUILD_GROUP_NAME" /nix/store
_sudo "to set up the root user's profile (part 1)" \
mkdir -pv -m 0755 /nix/var/nix/profiles/per-user/root
_sudo "to set up the root user's profile (part 2)" \
mkdir -pv -m 0700 "$ROOT_HOME/.nix-defexpr"
_sudo "to place the default nix daemon configuration (part 1)" \ _sudo "to place the default nix daemon configuration (part 1)" \
mkdir -pv -m 0555 /etc/nix mkdir -pv -m 0555 /etc/nix
} }
@@ -589,7 +579,7 @@ EOF
We will: We will:
- make sure your computer doesn't already have Nix files - make sure your computer doesn't already have Nix files
(if it does, I will tell you how to clean them up.) (if it does, I will tell you how to clean them up.)
- create local users (see the list above for the users we'll make) - create local users (see the list above for the users we'll make)
- create a local group ($NIX_BUILD_GROUP_NAME) - create a local group ($NIX_BUILD_GROUP_NAME)
- install Nix in to $NIX_ROOT - install Nix in to $NIX_ROOT

View File

@@ -141,11 +141,9 @@ if [ -z "$_NIX_INSTALLER_TEST" ]; then
fi fi
added= added=
p=$HOME/.nix-profile/etc/profile.d/nix.sh
if [ -z "$NIX_INSTALLER_NO_MODIFY_PROFILE" ]; then if [ -z "$NIX_INSTALLER_NO_MODIFY_PROFILE" ]; then
# Make the shell source nix.sh during login. # Make the shell source nix.sh during login.
p=$HOME/.nix-profile/etc/profile.d/nix.sh
for i in .bash_profile .bash_login .profile; do for i in .bash_profile .bash_login .profile; do
fn="$HOME/$i" fn="$HOME/$i"
if [ -w "$fn" ]; then if [ -w "$fn" ]; then
@@ -157,7 +155,6 @@ if [ -z "$NIX_INSTALLER_NO_MODIFY_PROFILE" ]; then
break break
fi fi
done done
fi fi
if [ -z "$added" ]; then if [ -z "$added" ]; then

View File

@@ -5,45 +5,6 @@ __ETC_PROFILE_NIX_SOURCED=1
export NIX_USER_PROFILE_DIR="@localstatedir@/nix/profiles/per-user/$USER" export NIX_USER_PROFILE_DIR="@localstatedir@/nix/profiles/per-user/$USER"
export NIX_PROFILES="@localstatedir@/nix/profiles/default $HOME/.nix-profile" export NIX_PROFILES="@localstatedir@/nix/profiles/default $HOME/.nix-profile"
# Set up the per-user profile.
mkdir -m 0755 -p $NIX_USER_PROFILE_DIR
if ! test -O "$NIX_USER_PROFILE_DIR"; then
echo "WARNING: bad ownership on $NIX_USER_PROFILE_DIR" >&2
fi
if test -w $HOME; then
if ! test -L $HOME/.nix-profile; then
if test "$USER" != root; then
ln -s $NIX_USER_PROFILE_DIR/profile $HOME/.nix-profile
else
# Root installs in the system-wide profile by default.
ln -s @localstatedir@/nix/profiles/default $HOME/.nix-profile
fi
fi
# Subscribe the root user to the NixOS channel by default.
if [ "$USER" = root -a ! -e $HOME/.nix-channels ]; then
echo "https://nixos.org/channels/nixpkgs-unstable nixpkgs" > $HOME/.nix-channels
fi
# Create the per-user garbage collector roots directory.
NIX_USER_GCROOTS_DIR=@localstatedir@/nix/gcroots/per-user/$USER
mkdir -m 0755 -p $NIX_USER_GCROOTS_DIR
if ! test -O "$NIX_USER_GCROOTS_DIR"; then
echo "WARNING: bad ownership on $NIX_USER_GCROOTS_DIR" >&2
fi
# Set up a default Nix expression from which to install stuff.
if [ ! -e $HOME/.nix-defexpr -o -L $HOME/.nix-defexpr ]; then
rm -f $HOME/.nix-defexpr
mkdir -p $HOME/.nix-defexpr
if [ "$USER" != root ]; then
ln -s @localstatedir@/nix/profiles/per-user/root/channels $HOME/.nix-defexpr/channels_root
fi
fi
fi
# Set $NIX_SSL_CERT_FILE so that Nixpkgs applications like curl work. # Set $NIX_SSL_CERT_FILE so that Nixpkgs applications like curl work.
if [ ! -z "${NIX_SSL_CERT_FILE:-}" ]; then if [ ! -z "${NIX_SSL_CERT_FILE:-}" ]; then
: # Allow users to override the NIX_SSL_CERT_FILE : # Allow users to override the NIX_SSL_CERT_FILE

View File

@@ -1,6 +1,4 @@
if [ -n "$HOME" ] && [ -n "$USER" ]; then if [ -n "$HOME" ] && [ -n "$USER" ]; then
__savedpath="$PATH"
export PATH=@coreutils@
# Set up the per-user profile. # Set up the per-user profile.
# This part should be kept in sync with nixpkgs:nixos/modules/programs/shell.nix # This part should be kept in sync with nixpkgs:nixos/modules/programs/shell.nix
@@ -9,48 +7,6 @@ if [ -n "$HOME" ] && [ -n "$USER" ]; then
NIX_USER_PROFILE_DIR=@localstatedir@/nix/profiles/per-user/$USER NIX_USER_PROFILE_DIR=@localstatedir@/nix/profiles/per-user/$USER
mkdir -m 0755 -p "$NIX_USER_PROFILE_DIR"
if [ "$(stat --printf '%u' "$NIX_USER_PROFILE_DIR")" != "$(id -u)" ]; then
echo "Nix: WARNING: bad ownership on "$NIX_USER_PROFILE_DIR", should be $(id -u)" >&2
fi
if [ -w "$HOME" ]; then
if ! [ -L "$NIX_LINK" ]; then
echo "Nix: creating $NIX_LINK" >&2
if [ "$USER" != root ]; then
if ! ln -s "$NIX_USER_PROFILE_DIR"/profile "$NIX_LINK"; then
echo "Nix: WARNING: could not create $NIX_LINK -> $NIX_USER_PROFILE_DIR/profile" >&2
fi
else
# Root installs in the system-wide profile by default.
ln -s @localstatedir@/nix/profiles/default "$NIX_LINK"
fi
fi
# Subscribe the user to the unstable Nixpkgs channel by default.
if [ ! -e "$HOME/.nix-channels" ]; then
echo "https://nixos.org/channels/nixpkgs-unstable nixpkgs" > "$HOME/.nix-channels"
fi
# Create the per-user garbage collector roots directory.
__user_gcroots=@localstatedir@/nix/gcroots/per-user/"$USER"
mkdir -m 0755 -p "$__user_gcroots"
if [ "$(stat --printf '%u' "$__user_gcroots")" != "$(id -u)" ]; then
echo "Nix: WARNING: bad ownership on $__user_gcroots, should be $(id -u)" >&2
fi
unset __user_gcroots
# Set up a default Nix expression from which to install stuff.
__nix_defexpr="$HOME"/.nix-defexpr
[ -L "$__nix_defexpr" ] && rm -f "$__nix_defexpr"
mkdir -m 0755 -p "$__nix_defexpr"
if [ "$USER" != root ] && [ ! -L "$__nix_defexpr"/channels_root ]; then
ln -s @localstatedir@/nix/profiles/per-user/root/channels "$__nix_defexpr"/channels_root
fi
unset __nix_defexpr
fi
# Append ~/.nix-defexpr/channels to $NIX_PATH so that <nixpkgs> # Append ~/.nix-defexpr/channels to $NIX_PATH so that <nixpkgs>
# paths work when the user has fetched the Nixpkgs channel. # paths work when the user has fetched the Nixpkgs channel.
export NIX_PATH=${NIX_PATH:+$NIX_PATH:}$HOME/.nix-defexpr/channels export NIX_PATH=${NIX_PATH:+$NIX_PATH:}$HOME/.nix-defexpr/channels
@@ -78,6 +34,6 @@ if [ -n "$HOME" ] && [ -n "$USER" ]; then
export MANPATH="$NIX_LINK/share/man:$MANPATH" export MANPATH="$NIX_LINK/share/man:$MANPATH"
fi fi
export PATH="$NIX_LINK/bin:$__savedpath" export PATH="$NIX_LINK/bin:$PATH"
unset __savedpath NIX_LINK NIX_USER_PROFILE_DIR unset NIX_LINK NIX_USER_PROFILE_DIR
fi fi

View File

@@ -7,7 +7,7 @@ with import ./release-common.nix { inherit pkgs; };
(if useClang then clangStdenv else stdenv).mkDerivation { (if useClang then clangStdenv else stdenv).mkDerivation {
name = "nix"; name = "nix";
buildInputs = buildDeps ++ tarballDeps ++ perlDeps; buildInputs = buildDeps ++ propagatedDeps ++ tarballDeps ++ perlDeps;
inherit configureFlags; inherit configureFlags;

View File

@@ -7,6 +7,7 @@
#include "eval-inline.hh" #include "eval-inline.hh"
#include "download.hh" #include "download.hh"
#include "json.hh" #include "json.hh"
#include "function-trace.hh"
#include <algorithm> #include <algorithm>
#include <chrono> #include <chrono>
@@ -877,7 +878,7 @@ void ExprAttrs::eval(EvalState & state, Env & env, Value & v)
if (hasOverrides) { if (hasOverrides) {
Value * vOverrides = (*v.attrs)[overrides->second.displ].value; Value * vOverrides = (*v.attrs)[overrides->second.displ].value;
state.forceAttrs(*vOverrides); state.forceAttrs(*vOverrides);
Bindings * newBnds = state.allocBindings(v.attrs->size() + vOverrides->attrs->size()); Bindings * newBnds = state.allocBindings(v.attrs->capacity() + vOverrides->attrs->size());
for (auto & i : *v.attrs) for (auto & i : *v.attrs)
newBnds->push_back(i); newBnds->push_back(i);
for (auto & i : *vOverrides->attrs) { for (auto & i : *vOverrides->attrs) {
@@ -1096,10 +1097,7 @@ void EvalState::callPrimOp(Value & fun, Value & arg, Value & v, const Pos & pos)
void EvalState::callFunction(Value & fun, Value & arg, Value & v, const Pos & pos) void EvalState::callFunction(Value & fun, Value & arg, Value & v, const Pos & pos)
{ {
std::optional<FunctionCallTrace> trace; auto trace = evalSettings.traceFunctionCalls ? std::make_unique<FunctionCallTrace>(pos) : nullptr;
if (evalSettings.traceFunctionCalls) {
trace.emplace(pos);
}
forceValue(fun, pos); forceValue(fun, pos);
@@ -1569,6 +1567,19 @@ bool EvalState::isDerivation(Value & v)
} }
std::optional<string> EvalState::tryAttrsToString(const Pos & pos, Value & v,
PathSet & context, bool coerceMore, bool copyToStore)
{
auto i = v.attrs->find(sToString);
if (i != v.attrs->end()) {
Value v1;
callFunction(*i->value, v, v1, pos);
return coerceToString(pos, v1, context, coerceMore, copyToStore);
}
return {};
}
string EvalState::coerceToString(const Pos & pos, Value & v, PathSet & context, string EvalState::coerceToString(const Pos & pos, Value & v, PathSet & context,
bool coerceMore, bool copyToStore) bool coerceMore, bool copyToStore)
{ {
@@ -1587,13 +1598,11 @@ string EvalState::coerceToString(const Pos & pos, Value & v, PathSet & context,
} }
if (v.type == tAttrs) { if (v.type == tAttrs) {
auto i = v.attrs->find(sToString); auto maybeString = tryAttrsToString(pos, v, context, coerceMore, copyToStore);
if (i != v.attrs->end()) { if (maybeString) {
Value v1; return *maybeString;
callFunction(*i->value, v, v1, pos);
return coerceToString(pos, v1, context, coerceMore, copyToStore);
} }
i = v.attrs->find(sOutPath); auto i = v.attrs->find(sOutPath);
if (i == v.attrs->end()) throwTypeError("cannot coerce a set to a string, at %1%", pos); if (i == v.attrs->end()) throwTypeError("cannot coerce a set to a string, at %1%", pos);
return coerceToString(pos, *i->value, context, coerceMore, copyToStore); return coerceToString(pos, *i->value, context, coerceMore, copyToStore);
} }

View File

@@ -6,9 +6,9 @@
#include "symbol-table.hh" #include "symbol-table.hh"
#include "hash.hh" #include "hash.hh"
#include "config.hh" #include "config.hh"
#include "function-trace.hh"
#include <map> #include <map>
#include <optional>
#include <unordered_map> #include <unordered_map>
@@ -196,6 +196,9 @@ public:
set with attribute `type = "derivation"'). */ set with attribute `type = "derivation"'). */
bool isDerivation(Value & v); bool isDerivation(Value & v);
std::optional<string> tryAttrsToString(const Pos & pos, Value & v,
PathSet & context, bool coerceMore = false, bool copyToStore = true);
/* String coercion. Converts strings, paths and derivations to a /* String coercion. Converts strings, paths and derivations to a
string. If `coerceMore' is set, also converts nulls, integers, string. If `coerceMore' is set, also converts nulls, integers,
booleans and lists to a string. If `copyToStore' is set, booleans and lists to a string. If `copyToStore' is set,

View File

@@ -0,0 +1,17 @@
#include "function-trace.hh"
namespace nix {
FunctionCallTrace::FunctionCallTrace(const Pos & pos) : pos(pos) {
auto duration = std::chrono::high_resolution_clock::now().time_since_epoch();
auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(duration);
printMsg(lvlInfo, "function-trace entered %1% at %2%", pos, ns.count());
}
FunctionCallTrace::~FunctionCallTrace() {
auto duration = std::chrono::high_resolution_clock::now().time_since_epoch();
auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(duration);
printMsg(lvlInfo, "function-trace exited %1% at %2%", pos, ns.count());
}
}

View File

@@ -1,24 +1,15 @@
#pragma once #pragma once
#include "eval.hh" #include "eval.hh"
#include <sys/time.h>
#include <chrono>
namespace nix { namespace nix {
struct FunctionCallTrace struct FunctionCallTrace
{ {
const Pos & pos; const Pos & pos;
FunctionCallTrace(const Pos & pos);
FunctionCallTrace(const Pos & pos) : pos(pos) { ~FunctionCallTrace();
auto duration = std::chrono::high_resolution_clock::now().time_since_epoch();
auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(duration);
vomit("function-trace entered %1% at %2%", pos, ns.count());
}
~FunctionCallTrace() {
auto duration = std::chrono::high_resolution_clock::now().time_since_epoch();
auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(duration);
vomit("function-trace exited %1% at %2%", pos, ns.count());
}
}; };
} }

View File

@@ -111,9 +111,9 @@ static void parseJSON(EvalState & state, const char * & s, Value & v)
mkFloat(v, stod(tmp_number)); mkFloat(v, stod(tmp_number));
else else
mkInt(v, stol(tmp_number)); mkInt(v, stol(tmp_number));
} catch (std::invalid_argument e) { } catch (std::invalid_argument & e) {
throw JSONParseError("invalid JSON number"); throw JSONParseError("invalid JSON number");
} catch (std::out_of_range e) { } catch (std::out_of_range & e) {
throw JSONParseError("out-of-range JSON number"); throw JSONParseError("out-of-range JSON number");
} }
} }

View File

@@ -2089,12 +2089,12 @@ void fetch(EvalState & state, const Pos & pos, Value * * args, Value & v,
if (evalSettings.pureEval && !request.expectedHash) if (evalSettings.pureEval && !request.expectedHash)
throw Error("in pure evaluation mode, '%s' requires a 'sha256' argument", who); throw Error("in pure evaluation mode, '%s' requires a 'sha256' argument", who);
Path res = getDownloader()->downloadCached(state.store, request).path; auto res = getDownloader()->downloadCached(state.store, request);
if (state.allowedPaths) if (state.allowedPaths)
state.allowedPaths->insert(res); state.allowedPaths->insert(res.path);
mkString(v, res, PathSet({res})); mkString(v, res.storePath, PathSet({res.storePath}));
} }

View File

@@ -38,7 +38,7 @@ GitInfo exportGit(ref<Store> store, const std::string & uri,
try { try {
runProgram("git", true, { "-C", uri, "diff-index", "--quiet", "HEAD", "--" }); runProgram("git", true, { "-C", uri, "diff-index", "--quiet", "HEAD", "--" });
} catch (ExecError e) { } catch (ExecError & e) {
if (!WIFEXITED(e.status) || WEXITSTATUS(e.status) != 1) throw; if (!WIFEXITED(e.status) || WEXITSTATUS(e.status) != 1) throw;
clean = false; clean = false;
} }

View File

@@ -40,7 +40,12 @@ void printValueAsJSON(EvalState & state, bool strict,
break; break;
case tAttrs: { case tAttrs: {
Bindings::iterator i = v.attrs->find(state.sOutPath); auto maybeString = state.tryAttrsToString(noPos, v, context, false, false);
if (maybeString) {
out.write(*maybeString);
break;
}
auto i = v.attrs->find(state.sOutPath);
if (i == v.attrs->end()) { if (i == v.attrs->end()) {
auto obj(out.object()); auto obj(out.object());
StringSet names; StringSet names;

View File

@@ -80,6 +80,7 @@ string getArg(const string & opt,
} }
#if OPENSSL_VERSION_NUMBER < 0x10101000L
/* OpenSSL is not thread-safe by default - it will randomly crash /* OpenSSL is not thread-safe by default - it will randomly crash
unless the user supplies a mutex locking function. So let's do unless the user supplies a mutex locking function. So let's do
that. */ that. */
@@ -92,6 +93,7 @@ static void opensslLockCallback(int mode, int type, const char * file, int line)
else else
opensslLocks[type].unlock(); opensslLocks[type].unlock();
} }
#endif
static void sigHandler(int signo) { } static void sigHandler(int signo) { }
@@ -105,9 +107,11 @@ void initNix()
std::cerr.rdbuf()->pubsetbuf(buf, sizeof(buf)); std::cerr.rdbuf()->pubsetbuf(buf, sizeof(buf));
#endif #endif
#if OPENSSL_VERSION_NUMBER < 0x10101000L
/* Initialise OpenSSL locking. */ /* Initialise OpenSSL locking. */
opensslLocks = std::vector<std::mutex>(CRYPTO_num_locks()); opensslLocks = std::vector<std::mutex>(CRYPTO_num_locks());
CRYPTO_set_locking_callback(opensslLockCallback); CRYPTO_set_locking_callback(opensslLockCallback);
#endif
loadConfFile(); loadConfFile();

View File

@@ -957,6 +957,9 @@ private:
/* Fill in the environment for the builder. */ /* Fill in the environment for the builder. */
void initEnv(); void initEnv();
/* Setup tmp dir location. */
void initTmpDir();
/* Write a JSON file containing the derivation attributes. */ /* Write a JSON file containing the derivation attributes. */
void writeStructuredAttrs(); void writeStructuredAttrs();
@@ -1961,13 +1964,6 @@ void DerivationGoal::startBuilder()
auto drvName = storePathToName(drvPath); auto drvName = storePathToName(drvPath);
tmpDir = createTempDir("", "nix-build-" + drvName, false, false, 0700); tmpDir = createTempDir("", "nix-build-" + drvName, false, false, 0700);
/* In a sandbox, for determinism, always use the same temporary
directory. */
#if __linux__
tmpDirInSandbox = useChroot ? settings.sandboxBuildDir : tmpDir;
#else
tmpDirInSandbox = tmpDir;
#endif
chownToBuilder(tmpDir); chownToBuilder(tmpDir);
/* Substitute output placeholders with the actual output paths. */ /* Substitute output placeholders with the actual output paths. */
@@ -2385,7 +2381,7 @@ void DerivationGoal::startBuilder()
int res = helper.wait(); int res = helper.wait();
if (res != 0 && settings.sandboxFallback) { if (res != 0 && settings.sandboxFallback) {
useChroot = false; useChroot = false;
tmpDirInSandbox = tmpDir; initTmpDir();
goto fallback; goto fallback;
} else if (res != 0) } else if (res != 0)
throw Error("unable to start build process"); throw Error("unable to start build process");
@@ -2442,31 +2438,14 @@ void DerivationGoal::startBuilder()
} }
void DerivationGoal::initEnv() void DerivationGoal::initTmpDir() {
{ /* In a sandbox, for determinism, always use the same temporary
env.clear(); directory. */
#if __linux__
/* Most shells initialise PATH to some default (/bin:/usr/bin:...) when tmpDirInSandbox = useChroot ? settings.sandboxBuildDir : tmpDir;
PATH is not set. We don't want this, so we fill it in with some dummy #else
value. */ tmpDirInSandbox = tmpDir;
env["PATH"] = "/path-not-set"; #endif
/* Set HOME to a non-existing path to prevent certain programs from using
/etc/passwd (or NIS, or whatever) to locate the home directory (for
example, wget looks for ~/.wgetrc). I.e., these tools use /etc/passwd
if HOME is not set, but they will just assume that the settings file
they are looking for does not exist if HOME is set but points to some
non-existing path. */
env["HOME"] = homeDir;
/* Tell the builder where the Nix store is. Usually they
shouldn't care, but this is useful for purity checking (e.g.,
the compiler or linker might only want to accept paths to files
in the store or in the build directory). */
env["NIX_STORE"] = worker.store.storeDir;
/* The maximum number of cores to utilize for parallel building. */
env["NIX_BUILD_CORES"] = (format("%d") % settings.buildCores).str();
/* In non-structured mode, add all bindings specified in the /* In non-structured mode, add all bindings specified in the
derivation via the environment, except those listed in the derivation via the environment, except those listed in the
@@ -2505,6 +2484,35 @@ void DerivationGoal::initEnv()
inode of the current directory doesn't appear in .. (because inode of the current directory doesn't appear in .. (because
getdents returns the inode of the mount point). */ getdents returns the inode of the mount point). */
env["PWD"] = tmpDirInSandbox; env["PWD"] = tmpDirInSandbox;
}
void DerivationGoal::initEnv()
{
env.clear();
/* Most shells initialise PATH to some default (/bin:/usr/bin:...) when
PATH is not set. We don't want this, so we fill it in with some dummy
value. */
env["PATH"] = "/path-not-set";
/* Set HOME to a non-existing path to prevent certain programs from using
/etc/passwd (or NIS, or whatever) to locate the home directory (for
example, wget looks for ~/.wgetrc). I.e., these tools use /etc/passwd
if HOME is not set, but they will just assume that the settings file
they are looking for does not exist if HOME is set but points to some
non-existing path. */
env["HOME"] = homeDir;
/* Tell the builder where the Nix store is. Usually they
shouldn't care, but this is useful for purity checking (e.g.,
the compiler or linker might only want to accept paths to files
in the store or in the build directory). */
env["NIX_STORE"] = worker.store.storeDir;
/* The maximum number of cores to utilize for parallel building. */
env["NIX_BUILD_CORES"] = (format("%d") % settings.buildCores).str();
initTmpDir();
/* Compatibility hack with Nix <= 0.7: if this is a fixed-output /* Compatibility hack with Nix <= 0.7: if this is a fixed-output
derivation, tell the builder, so that for instance `fetchurl' derivation, tell the builder, so that for instance `fetchurl'
@@ -2570,6 +2578,7 @@ void DerivationGoal::writeStructuredAttrs()
} }
writeFile(tmpDir + "/.attrs.json", rewriteStrings(json.dump(), inputRewrites)); writeFile(tmpDir + "/.attrs.json", rewriteStrings(json.dump(), inputRewrites));
chownToBuilder(tmpDir + "/.attrs.json");
/* As a convenience to bash scripts, write a shell file that /* As a convenience to bash scripts, write a shell file that
maps all attributes that are representable in bash - maps all attributes that are representable in bash -
@@ -2638,6 +2647,7 @@ void DerivationGoal::writeStructuredAttrs()
} }
writeFile(tmpDir + "/.attrs.sh", rewriteStrings(jsonSh, inputRewrites)); writeFile(tmpDir + "/.attrs.sh", rewriteStrings(jsonSh, inputRewrites));
chownToBuilder(tmpDir + "/.attrs.sh");
} }

View File

@@ -357,9 +357,10 @@ struct CurlDownloader : public Downloader
} else if (httpStatus == 401 || httpStatus == 403 || httpStatus == 407) { } else if (httpStatus == 401 || httpStatus == 403 || httpStatus == 407) {
// Don't retry on authentication/authorization failures // Don't retry on authentication/authorization failures
err = Forbidden; err = Forbidden;
} else if (httpStatus >= 400 && httpStatus < 500 && httpStatus != 408) { } else if (httpStatus >= 400 && httpStatus < 500 && httpStatus != 408 && httpStatus != 429) {
// Most 4xx errors are client errors and are probably not worth retrying: // Most 4xx errors are client errors and are probably not worth retrying:
// * 408 means the server timed out waiting for us, so we try again // * 408 means the server timed out waiting for us, so we try again
// * 429 means too many requests, so we retry (with a delay)
err = Misc; err = Misc;
} else if (httpStatus == 501 || httpStatus == 505 || httpStatus == 511) { } else if (httpStatus == 501 || httpStatus == 505 || httpStatus == 511) {
// Let's treat most 5xx (server) errors as transient, except for a handful: // Let's treat most 5xx (server) errors as transient, except for a handful:

View File

@@ -91,6 +91,8 @@ class Store;
struct Downloader struct Downloader
{ {
virtual ~Downloader() { }
/* Enqueue a download request, returning a future to the result of /* Enqueue a download request, returning a future to the result of
the download. The future may throw a DownloadError the download. The future may throw a DownloadError
exception. */ exception. */

View File

@@ -19,6 +19,8 @@ public:
uint64_t narOffset = 0; // regular files only uint64_t narOffset = 0; // regular files only
}; };
virtual ~FSAccessor() { }
virtual Stat stat(const Path & path) = 0; virtual Stat stat(const Path & path) = 0;
virtual StringSet readDirectory(const Path & path) = 0; virtual StringSet readDirectory(const Path & path) = 0;

View File

@@ -319,7 +319,7 @@ public:
"A program to run just before a build to set derivation-specific build settings."}; "A program to run just before a build to set derivation-specific build settings."};
Setting<std::string> postBuildHook{this, "", "post-build-hook", Setting<std::string> postBuildHook{this, "", "post-build-hook",
"A program to run just after each succesful build."}; "A program to run just after each successful build."};
Setting<std::string> netrcFile{this, fmt("%s/%s", nixConfDir, "netrc"), "netrc-file", Setting<std::string> netrcFile{this, fmt("%s/%s", nixConfDir, "netrc"), "netrc-file",
"Path to the netrc file used to obtain usernames/passwords for downloads."}; "Path to the netrc file used to obtain usernames/passwords for downloads."};

View File

@@ -70,15 +70,17 @@ LocalStore::LocalStore(const Params & params)
createSymlink(profilesDir, gcRootsDir + "/profiles"); createSymlink(profilesDir, gcRootsDir + "/profiles");
} }
for (auto & perUserDir : {profilesDir + "/per-user", gcRootsDir + "/per-user"}) {
createDirs(perUserDir);
if (chmod(perUserDir.c_str(), 0755) == -1)
throw SysError("could not set permissions on '%s' to 755", perUserDir);
}
createUser(getUserName(), getuid());
/* Optionally, create directories and set permissions for a /* Optionally, create directories and set permissions for a
multi-user install. */ multi-user install. */
if (getuid() == 0 && settings.buildUsersGroup != "") { if (getuid() == 0 && settings.buildUsersGroup != "") {
Path perUserDir = profilesDir + "/per-user";
createDirs(perUserDir);
if (chmod(perUserDir.c_str(), 01777) == -1)
throw SysError(format("could not set permissions on '%1%' to 1777") % perUserDir);
mode_t perm = 01775; mode_t perm = 01775;
struct group * gr = getgrnam(settings.buildUsersGroup.get().c_str()); struct group * gr = getgrnam(settings.buildUsersGroup.get().c_str());
@@ -879,8 +881,8 @@ void LocalStore::querySubstitutablePathInfos(const PathSet & paths,
info->references, info->references,
narInfo ? narInfo->fileSize : 0, narInfo ? narInfo->fileSize : 0,
info->narSize}; info->narSize};
} catch (InvalidPath) { } catch (InvalidPath &) {
} catch (SubstituterDisabled) { } catch (SubstituterDisabled &) {
} catch (Error & e) { } catch (Error & e) {
if (settings.tryFallback) if (settings.tryFallback)
printError(e.what()); printError(e.what());
@@ -1433,4 +1435,19 @@ void LocalStore::signPathInfo(ValidPathInfo & info)
} }
void LocalStore::createUser(const std::string & userName, uid_t userId)
{
for (auto & dir : {
fmt("%s/profiles/per-user/%s", stateDir, userName),
fmt("%s/gcroots/per-user/%s", stateDir, userName)
}) {
createDirs(dir);
if (chmod(dir.c_str(), 0755) == -1)
throw SysError("changing permissions of directory '%s'", dir);
if (chown(dir.c_str(), userId, getgid()) == -1)
throw SysError("changing owner of directory '%s'", dir);
}
}
} }

View File

@@ -293,6 +293,8 @@ private:
Path getRealStoreDir() override { return realStoreDir; } Path getRealStoreDir() override { return realStoreDir; }
void createUser(const std::string & userName, uid_t userId) override;
friend class DerivationGoal; friend class DerivationGoal;
friend class SubstitutionGoal; friend class SubstitutionGoal;
}; };

View File

@@ -39,9 +39,12 @@ libstore_CXXFLAGS = \
-DNIX_LIBEXEC_DIR=\"$(libexecdir)\" \ -DNIX_LIBEXEC_DIR=\"$(libexecdir)\" \
-DNIX_BIN_DIR=\"$(bindir)\" \ -DNIX_BIN_DIR=\"$(bindir)\" \
-DNIX_MAN_DIR=\"$(mandir)\" \ -DNIX_MAN_DIR=\"$(mandir)\" \
-DSANDBOX_SHELL="\"$(sandbox_shell)\"" \
-DLSOF=\"$(lsof)\" -DLSOF=\"$(lsof)\"
ifneq ($(sandbox_shell),)
libstore_CXXFLAGS += -DSANDBOX_SHELL="\"$(sandbox_shell)\""
endif
$(d)/local-store.cc: $(d)/schema.sql.gen.hh $(d)/local-store.cc: $(d)/schema.sql.gen.hh
$(d)/build.cc: $(d)/build.cc:

View File

@@ -151,7 +151,7 @@ void RemoteStore::initConnection(Connection & conn)
conn.to << PROTOCOL_VERSION; conn.to << PROTOCOL_VERSION;
if (GET_PROTOCOL_MINOR(conn.daemonVersion) >= 14) { if (GET_PROTOCOL_MINOR(conn.daemonVersion) >= 14) {
int cpu = settings.lockCPU ? lockToCurrentCPU() : -1; int cpu = sameMachine() && settings.lockCPU ? lockToCurrentCPU() : -1;
if (cpu != -1) if (cpu != -1)
conn.to << 1 << cpu; conn.to << 1 << cpu;
else else
@@ -198,6 +198,7 @@ void RemoteStore::setOptions(Connection & conn)
overrides.erase(settings.maxSilentTime.name); overrides.erase(settings.maxSilentTime.name);
overrides.erase(settings.buildCores.name); overrides.erase(settings.buildCores.name);
overrides.erase(settings.useSubstitutes.name); overrides.erase(settings.useSubstitutes.name);
overrides.erase(settings.showTrace.name);
conn.to << overrides.size(); conn.to << overrides.size();
for (auto & i : overrides) for (auto & i : overrides)
conn.to << i.first << i.second.value; conn.to << i.first << i.second.value;

View File

@@ -29,6 +29,8 @@ public:
const Setting<unsigned int> maxConnectionAge{(Store*) this, std::numeric_limits<unsigned int>::max(), const Setting<unsigned int> maxConnectionAge{(Store*) this, std::numeric_limits<unsigned int>::max(),
"max-connection-age", "number of seconds to reuse a connection"}; "max-connection-age", "number of seconds to reuse a connection"};
virtual bool sameMachine() = 0;
RemoteStore(const Params & params); RemoteStore(const Params & params);
/* Implementations of abstract store API methods. */ /* Implementations of abstract store API methods. */
@@ -146,6 +148,9 @@ public:
std::string getUri() override; std::string getUri() override;
bool sameMachine()
{ return true; }
private: private:
ref<RemoteStore::Connection> openConnection() override; ref<RemoteStore::Connection> openConnection() override;

View File

@@ -35,6 +35,9 @@ public:
return uriScheme + host; return uriScheme + host;
} }
bool sameMachine()
{ return false; }
void narFromPath(const Path & path, Sink & sink) override; void narFromPath(const Path & path, Sink & sink) override;
ref<FSAccessor> getFSAccessor() override; ref<FSAccessor> getFSAccessor() override;

View File

@@ -561,7 +561,7 @@ public:
unsigned long long & downloadSize, unsigned long long & narSize); unsigned long long & downloadSize, unsigned long long & narSize);
/* Sort a set of paths topologically under the references /* Sort a set of paths topologically under the references
relation. If p refers to q, then p preceeds q in this list. */ relation. If p refers to q, then p precedes q in this list. */
Paths topoSortPaths(const PathSet & paths); Paths topoSortPaths(const PathSet & paths);
/* Export multiple paths in the format expected by nix-store /* Export multiple paths in the format expected by nix-store
@@ -628,6 +628,9 @@ public:
return storePath; return storePath;
} }
virtual void createUser(const std::string & userName, uid_t userId)
{ }
protected: protected:
Stats stats; Stats stats;

View File

@@ -475,6 +475,16 @@ Path createTempDir(const Path & tmpRoot, const Path & prefix,
} }
std::string getUserName()
{
auto pw = getpwuid(geteuid());
std::string name = pw ? pw->pw_name : getEnv("USER", "");
if (name.empty())
throw Error("cannot figure out user name");
return name;
}
static Lazy<Path> getHome2([]() { static Lazy<Path> getHome2([]() {
Path homeDir = getEnv("HOME"); Path homeDir = getEnv("HOME");
if (homeDir.empty()) { if (homeDir.empty()) {
@@ -1442,7 +1452,7 @@ static Sync<std::pair<unsigned short, unsigned short>> windowSize{{0, 0}};
static void updateWindowSize() static void updateWindowSize()
{ {
struct winsize ws; struct winsize ws;
if (ioctl(1, TIOCGWINSZ, &ws) == 0) { if (ioctl(2, TIOCGWINSZ, &ws) == 0) {
auto windowSize_(windowSize.lock()); auto windowSize_(windowSize.lock());
windowSize_->first = ws.ws_row; windowSize_->first = ws.ws_row;
windowSize_->second = ws.ws_col; windowSize_->second = ws.ws_col;

View File

@@ -126,6 +126,8 @@ void deletePath(const Path & path, unsigned long long & bytesFreed);
Path createTempDir(const Path & tmpRoot = "", const Path & prefix = "nix", Path createTempDir(const Path & tmpRoot = "", const Path & prefix = "nix",
bool includePid = true, bool useGlobalCounter = true, mode_t mode = 0755); bool includePid = true, bool useGlobalCounter = true, mode_t mode = 0755);
std::string getUserName();
/* Return $HOME or the user's home directory from /etc/passwd. */ /* Return $HOME or the user's home directory from /etc/passwd. */
Path getHome(); Path getHome();

View File

@@ -280,7 +280,7 @@ static void _main(int argc, char * * argv)
auto absolute = i; auto absolute = i;
try { try {
absolute = canonPath(absPath(i), true); absolute = canonPath(absPath(i), true);
} catch (Error e) {}; } catch (Error & e) {};
if (store->isStorePath(absolute) && std::regex_match(absolute, std::regex(".*\\.drv(!.*)?"))) if (store->isStorePath(absolute) && std::regex_match(absolute, std::regex(".*\\.drv(!.*)?")))
drvs.push_back(DrvInfo(*state, store, absolute)); drvs.push_back(DrvInfo(*state, store, absolute));
else else

View File

@@ -159,13 +159,7 @@ static int _main(int argc, char ** argv)
nixDefExpr = home + "/.nix-defexpr"; nixDefExpr = home + "/.nix-defexpr";
// Figure out the name of the channels profile. // Figure out the name of the channels profile.
; profile = fmt("%s/profiles/per-user/%s/channels", settings.nixStateDir, getUserName());
auto pw = getpwuid(geteuid());
std::string name = pw ? pw->pw_name : getEnv("USER", "");
if (name.empty())
throw Error("cannot figure out user name");
profile = settings.nixStateDir + "/profiles/per-user/" + name + "/channels";
createDirs(dirOf(profile));
enum { enum {
cNone, cNone,

View File

@@ -742,7 +742,8 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
} }
static void processConnection(bool trusted) static void processConnection(bool trusted,
const std::string & userName, uid_t userId)
{ {
MonitorFdHup monitor(from.fd); MonitorFdHup monitor(from.fd);
@@ -793,6 +794,8 @@ static void processConnection(bool trusted)
params["path-info-cache-size"] = "0"; params["path-info-cache-size"] = "0";
auto store = openStore(settings.storeUri, params); auto store = openStore(settings.storeUri, params);
store->createUser(userName, userId);
tunnelLogger->stopWork(); tunnelLogger->stopWork();
to.flush(); to.flush();
@@ -1053,7 +1056,7 @@ static void daemonLoop(char * * argv)
/* Handle the connection. */ /* Handle the connection. */
from.fd = remote.get(); from.fd = remote.get();
to.fd = remote.get(); to.fd = remote.get();
processConnection(trusted); processConnection(trusted, user, peer.uid);
exit(0); exit(0);
}, options); }, options);
@@ -1133,7 +1136,7 @@ static int _main(int argc, char * * argv)
} }
} }
} else { } else {
processConnection(true); processConnection(true, "root", 0);
} }
} else { } else {
daemonLoop(argv); daemonLoop(argv);

View File

@@ -193,12 +193,6 @@ static void loadDerivations(EvalState & state, Path nixExprPath,
} }
static Path getDefNixExprPath()
{
return getHome() + "/.nix-defexpr";
}
static long getPriority(EvalState & state, DrvInfo & drv) static long getPriority(EvalState & state, DrvInfo & drv)
{ {
return drv.queryMetaInt("priority", 0); return drv.queryMetaInt("priority", 0);
@@ -1330,9 +1324,22 @@ static int _main(int argc, char * * argv)
Globals globals; Globals globals;
globals.instSource.type = srcUnknown; globals.instSource.type = srcUnknown;
globals.instSource.nixExprPath = getDefNixExprPath(); globals.instSource.nixExprPath = getHome() + "/.nix-defexpr";
globals.instSource.systemFilter = "*"; globals.instSource.systemFilter = "*";
if (!pathExists(globals.instSource.nixExprPath)) {
try {
createDirs(globals.instSource.nixExprPath);
replaceSymlink(
fmt("%s/profiles/per-user/%s/channels", settings.nixStateDir, getUserName()),
globals.instSource.nixExprPath + "/channels");
if (getuid() != 0)
replaceSymlink(
fmt("%s/profiles/per-user/root/channels", settings.nixStateDir),
globals.instSource.nixExprPath + "/channels_root");
} catch (Error &) { }
}
globals.dryRun = false; globals.dryRun = false;
globals.preserveInstalled = false; globals.preserveInstalled = false;
globals.removeAll = false; globals.removeAll = false;
@@ -1425,9 +1432,18 @@ static int _main(int argc, char * * argv)
if (globals.profile == "") { if (globals.profile == "") {
Path profileLink = getHome() + "/.nix-profile"; Path profileLink = getHome() + "/.nix-profile";
globals.profile = pathExists(profileLink) try {
? absPath(readLink(profileLink), dirOf(profileLink)) if (!pathExists(profileLink)) {
: canonPath(settings.nixStateDir + "/profiles/default"); replaceSymlink(
getuid() == 0
? settings.nixStateDir + "/profiles/default"
: fmt("%s/profiles/per-user/%s/profile", settings.nixStateDir, getUserName()),
profileLink);
}
globals.profile = absPath(readLink(profileLink), dirOf(profileLink));
} catch (Error &) {
globals.profile = profileLink;
}
} }
op(globals, opFlags, opArgs); op(globals, opFlags, opArgs);

View File

@@ -55,7 +55,7 @@ struct CmdEdit : InstallableCommand
int lineno; int lineno;
try { try {
lineno = std::stoi(std::string(pos, colon + 1)); lineno = std::stoi(std::string(pos, colon + 1));
} catch (std::invalid_argument e) { } catch (std::invalid_argument & e) {
throw Error("cannot parse line number '%s'", pos); throw Error("cannot parse line number '%s'", pos);
} }

View File

@@ -39,31 +39,32 @@ Value * SourceExprCommand::getSourceExpr(EvalState & state)
auto searchPath = state.getSearchPath(); auto searchPath = state.getSearchPath();
state.mkAttrs(*vSourceExpr, searchPath.size() + 1); state.mkAttrs(*vSourceExpr, 1024);
mkBool(*state.allocAttr(*vSourceExpr, sToplevel), true); mkBool(*state.allocAttr(*vSourceExpr, sToplevel), true);
std::unordered_set<std::string> seen; std::unordered_set<std::string> seen;
for (auto & i : searchPath) { auto addEntry = [&](const std::string & name) {
if (i.first == "") continue; if (name == "") return;
if (seen.count(i.first)) continue; if (!seen.insert(name).second) return;
seen.insert(i.first);
#if 0
auto res = state.resolveSearchPathElem(i);
if (!res.first) continue;
if (!pathExists(res.second)) continue;
mkApp(*state.allocAttr(*vSourceExpr, state.symbols.create(i.first)),
state.getBuiltin("import"),
mkString(*state.allocValue(), res.second));
#endif
Value * v1 = state.allocValue(); Value * v1 = state.allocValue();
mkPrimOpApp(*v1, state.getBuiltin("findFile"), state.getBuiltin("nixPath")); mkPrimOpApp(*v1, state.getBuiltin("findFile"), state.getBuiltin("nixPath"));
Value * v2 = state.allocValue(); Value * v2 = state.allocValue();
mkApp(*v2, *v1, mkString(*state.allocValue(), i.first)); mkApp(*v2, *v1, mkString(*state.allocValue(), name));
mkApp(*state.allocAttr(*vSourceExpr, state.symbols.create(i.first)), mkApp(*state.allocAttr(*vSourceExpr, state.symbols.create(name)),
state.getBuiltin("import"), *v2); state.getBuiltin("import"), *v2);
} };
for (auto & i : searchPath)
/* Hack to handle channels. */
if (i.first.empty() && pathExists(i.second + "/manifest.nix")) {
for (auto & j : readDirectory(i.second))
if (j.name != "manifest.nix"
&& pathExists(fmt("%s/%s/default.nix", i.second, j.name)))
addEntry(j.name);
} else
addEntry(i.first);
vSourceExpr->attrs->sort(); vSourceExpr->attrs->sort();
} }

View File

@@ -15,6 +15,7 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <ifaddrs.h> #include <ifaddrs.h>
#include <netdb.h> #include <netdb.h>
#include <netinet/in.h>
extern std::string chrootHelperName; extern std::string chrootHelperName;

View File

@@ -120,7 +120,7 @@ public:
void log(State & state, Verbosity lvl, const std::string & s) void log(State & state, Verbosity lvl, const std::string & s)
{ {
if (state.active) { if (state.active) {
writeToStderr("\r\e[K" + s + ANSI_NORMAL "\n"); writeToStderr("\r\e[K" + filterANSIEscapes(s, !isTTY) + ANSI_NORMAL "\n");
draw(state); draw(state);
} else { } else {
auto s2 = s + ANSI_NORMAL "\n"; auto s2 = s + ANSI_NORMAL "\n";
@@ -341,7 +341,7 @@ public:
} }
auto width = getWindowSize().second; auto width = getWindowSize().second;
if (width <= 0) std::numeric_limits<decltype(width)>::max(); if (width <= 0) width = std::numeric_limits<decltype(width)>::max();
writeToStderr("\r" + filterANSIEscapes(line, false, width) + "\e[K"); writeToStderr("\r" + filterANSIEscapes(line, false, width) + "\e[K");
} }
@@ -439,7 +439,9 @@ public:
void startProgressBar(bool printBuildLogs) void startProgressBar(bool printBuildLogs)
{ {
logger = new ProgressBar(printBuildLogs, isatty(STDERR_FILENO)); logger = new ProgressBar(
printBuildLogs,
isatty(STDERR_FILENO) && getEnv("TERM", "dumb") != "dumb");
} }
void stopProgressBar() void stopProgressBar()

View File

@@ -80,10 +80,6 @@ struct CmdSearch : SourceExprCommand, MixJSON
Example{ Example{
"To search for git and frontend or gui:", "To search for git and frontend or gui:",
"nix search git 'frontend|gui'" "nix search git 'frontend|gui'"
},
Example{
"To display the description of the found packages:",
"nix search git --verbose"
} }
}; };
} }
@@ -265,6 +261,7 @@ struct CmdSearch : SourceExprCommand, MixJSON
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66145 */ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66145 */
if (!jsonCacheFile) if (!jsonCacheFile)
throw Error("error writing to %s", tmpFile); throw Error("error writing to %s", tmpFile);
throw;
} }
if (writeCache && rename(tmpFile.c_str(), jsonCacheFileName.c_str()) == -1) if (writeCache && rename(tmpFile.c_str(), jsonCacheFileName.c_str()) == -1)

View File

@@ -13,7 +13,7 @@ struct CmdVerify : StorePathsCommand
bool noContents = false; bool noContents = false;
bool noTrust = false; bool noTrust = false;
Strings substituterUris; Strings substituterUris;
size_t sigsNeeded; size_t sigsNeeded = 0;
CmdVerify() CmdVerify()
{ {
@@ -113,7 +113,7 @@ struct CmdVerify : StorePathsCommand
else { else {
StringSet sigsSeen; StringSet sigsSeen;
size_t actualSigsNeeded = sigsNeeded ? sigsNeeded : 1; size_t actualSigsNeeded = std::max(sigsNeeded, (size_t) 1);
size_t validSigs = 0; size_t validSigs = 0;
auto doSigs = [&](StringSet sigs) { auto doSigs = [&](StringSet sigs) {

View File

@@ -8,7 +8,6 @@ expect_trace() {
actual=$( actual=$(
nix-instantiate \ nix-instantiate \
--trace-function-calls \ --trace-function-calls \
-vvvv \
--expr "$expr" 2>&1 \ --expr "$expr" 2>&1 \
| grep "function-trace" \ | grep "function-trace" \
| sed -e 's/ [0-9]*$//' | sed -e 's/ [0-9]*$//'

View File

@@ -0,0 +1 @@
{ __overrides = { bar = "qux"; }; bar = "qux"; foo = "bar"; }

View File

@@ -0,0 +1,4 @@
rec {
"${"foo"}" = "bar";
__overrides = { bar = "qux"; };
}

View File

@@ -1 +1 @@
"{\"a\":123,\"b\":-456,\"c\":\"foo\",\"d\":\"foo\\n\\\"bar\\\"\",\"e\":true,\"f\":false,\"g\":[1,2,3],\"h\":[\"a\",[\"b\",{\"foo\\nbar\":{}}]],\"i\":3,\"j\":1.44}" "{\"a\":123,\"b\":-456,\"c\":\"foo\",\"d\":\"foo\\n\\\"bar\\\"\",\"e\":true,\"f\":false,\"g\":[1,2,3],\"h\":[\"a\",[\"b\",{\"foo\\nbar\":{}}]],\"i\":3,\"j\":1.44,\"k\":\"foo\"}"

View File

@@ -9,4 +9,5 @@ builtins.toJSON
h = [ "a" [ "b" { "foo\nbar" = {}; } ] ]; h = [ "a" [ "b" { "foo\nbar" = {}; } ] ];
i = 1 + 2; i = 1 + 2;
j = 1.44; j = 1.44;
k = { __toString = self: self.a; a = "foo"; };
} }

View File

@@ -36,7 +36,7 @@ grep -q 'item.*attrPath="foo".*name="dependencies"' $TEST_ROOT/meta.xml
# Do an install. # Do an install.
nix-env -i dependencies nix-env -i dependencies
[ -e $TEST_ROOT/var/nix/profiles/default/foobar ] [ -e $TEST_HOME/.nix-profile/foobar ]
clearProfiles clearProfiles
rm -f $TEST_HOME/.nix-channels rm -f $TEST_HOME/.nix-channels
@@ -55,5 +55,5 @@ grep -q 'item.*attrPath="foo".*name="dependencies"' $TEST_ROOT/meta.xml
# Do an install. # Do an install.
nix-env -i dependencies nix-env -i dependencies
[ -e $TEST_ROOT/var/nix/profiles/default/foobar ] [ -e $TEST_HOME/.nix-profile/foobar ]

View File

@@ -7,8 +7,3 @@ rm -rf $TEST_HOME $TEST_ROOT/profile-var
mkdir -p $TEST_HOME mkdir -p $TEST_HOME
USER=$user $SHELL -e -c ". $TEST_ROOT/nix-profile.sh; set" USER=$user $SHELL -e -c ". $TEST_ROOT/nix-profile.sh; set"
USER=$user $SHELL -e -c ". $TEST_ROOT/nix-profile.sh" # test idempotency USER=$user $SHELL -e -c ". $TEST_ROOT/nix-profile.sh" # test idempotency
[ -L $TEST_HOME/.nix-profile ]
[ -e $TEST_HOME/.nix-channels ]
[ -e $TEST_ROOT/profile-var/nix/gcroots/per-user/$user ]
[ -e $TEST_ROOT/profile-var/nix/profiles/per-user/$user ]

View File

@@ -13,3 +13,7 @@ cmp $TEST_ROOT/d1 $TEST_ROOT/d2
nix-store --gc --max-freed 1K nix-store --gc --max-freed 1K
killDaemon killDaemon
user=$(whoami)
[ -e $NIX_STATE_DIR/gcroots/per-user/$user ]
[ -e $NIX_STATE_DIR/profiles/per-user/$user ]

View File

@@ -20,7 +20,7 @@ drvPath10=$(nix-env -f ./user-envs.nix -qa --drv-path --no-name '*' | grep foo-1
# Query descriptions. # Query descriptions.
nix-env -f ./user-envs.nix -qa '*' --description | grep -q silly nix-env -f ./user-envs.nix -qa '*' --description | grep -q silly
rm -f $HOME/.nix-defexpr rm -rf $HOME/.nix-defexpr
ln -s $(pwd)/user-envs.nix $HOME/.nix-defexpr ln -s $(pwd)/user-envs.nix $HOME/.nix-defexpr
nix-env -qa '*' --description | grep -q silly nix-env -qa '*' --description | grep -q silly