diff --git a/.mergify.yml b/.mergify.yml index 021157eb9..e134b0f46 100644 --- a/.mergify.yml +++ b/.mergify.yml @@ -117,3 +117,14 @@ pull_request_rules: labels: - automatic backport - merge-queue + + - name: backport patches to 2.27 + conditions: + - label=backport 2.27-maintenance + actions: + backport: + branches: + - "2.27-maintenance" + labels: + - automatic backport + - merge-queue diff --git a/.version b/.version index f0465234b..9738a24f6 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -2.27.1 +2.28.1 diff --git a/doc/manual/rl-next/curl-cloexec.md b/doc/manual/rl-next/curl-cloexec.md deleted file mode 100644 index 2fcdfb0d1..000000000 --- a/doc/manual/rl-next/curl-cloexec.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -synopsis: Set FD_CLOEXEC on sockets created by curl -issues: [] -prs: [12439] ---- - - -Curl creates sockets without setting FD_CLOEXEC/SOCK_CLOEXEC, this can cause connections to remain open forever when using commands like `nix shell` - -This change sets the FD_CLOEXEC flag using a CURLOPT_SOCKOPTFUNCTION callback. diff --git a/doc/manual/source/SUMMARY.md.in b/doc/manual/source/SUMMARY.md.in index 087c4b93c..e2e2ec48c 100644 --- a/doc/manual/source/SUMMARY.md.in +++ b/doc/manual/source/SUMMARY.md.in @@ -132,5 +132,6 @@ - [Release 3.0.0 (2025-03-04)](release-notes-determinate/rl-3.0.0.md) - [Nix Release Notes](release-notes/index.md) {{#include ./SUMMARY-rl-next.md}} + - [Release 2.28 (2025-04-02)](release-notes/rl-2.28.md) - [Release 2.27 (2025-03-03)](release-notes/rl-2.27.md) - [Release 2.26 (2025-01-22)](release-notes/rl-2.26.md) diff --git a/doc/manual/source/development/testing.md b/doc/manual/source/development/testing.md index d0c3a1c78..c0b130155 100644 --- a/doc/manual/source/development/testing.md +++ b/doc/manual/source/development/testing.md @@ -30,7 +30,7 @@ The unit tests are defined using the [googletest] and [rapidcheck] frameworks. > src > ├── libexpr > │ ├── meson.build -> │ ├── value/context.hh +> │ ├── include/nix/expr/value/context.hh > │ ├── value/context.cc > │ … > │ @@ -46,8 +46,12 @@ The unit tests are defined using the [googletest] and [rapidcheck] frameworks. > │ │ > │ ├── libexpr-test-support > │ │ ├── meson.build +> │ │ ├── include/nix/expr +> │ │ │ ├── meson.build +> │ │ │ └── tests +> │ │ │ ├── value/context.hh +> │ │ │ … > │ │ └── tests -> │ │ ├── value/context.hh > │ │ ├── value/context.cc > │ │ … > │ │ @@ -59,7 +63,7 @@ The unit tests are defined using the [googletest] and [rapidcheck] frameworks. > ``` The tests for each Nix library (`libnixexpr`, `libnixstore`, etc..) live inside a directory `src/${library_name_without-nix}-test`. -Given an interface (header) and implementation pair in the original library, say, `src/libexpr/value/context.{hh,cc}`, we write tests for it in `src/libexpr-tests/value/context.cc`, and (possibly) declare/define additional interfaces for testing purposes in `src/libexpr-test-support/tests/value/context.{hh,cc}`. +Given an interface (header) and implementation pair in the original library, say, `src/libexpr/include/nix/expr/value/context.hh` and `src/libexpr/value/context.cc`, we write tests for it in `src/libexpr-tests/value/context.cc`, and (possibly) declare/define additional interfaces for testing purposes in `src/libexpr-test-support/include/nix/expr/tests/value/context.hh` and `src/libexpr-test-support/tests/value/context.cc`. Data for unit tests is stored in a `data` subdir of the directory for each unit test executable. For example, `libnixstore` code is in `src/libstore`, and its test data is in `src/libstore-tests/data`. @@ -67,7 +71,7 @@ The path to the `src/${library_name_without-nix}-test/data` directory is passed Note that each executable only gets the data for its tests. The unit test libraries are in `src/${library_name_without-nix}-test-support`. -All headers are in a `tests` subdirectory so they are included with `#include "tests/"`. +All headers are in a `tests` subdirectory so they are included with `#include "nix/tests/"`. The use of all these separate directories for the unit tests might seem inconvenient, as for example the tests are not "right next to" the part of the code they are testing. But organizing the tests this way has one big benefit: diff --git a/doc/manual/source/language/advanced-attributes.md b/doc/manual/source/language/advanced-attributes.md index 0722386c4..bf196e0b8 100644 --- a/doc/manual/source/language/advanced-attributes.md +++ b/doc/manual/source/language/advanced-attributes.md @@ -2,6 +2,83 @@ Derivations can declare some infrequently used optional attributes. +## Inputs + + - [`exportReferencesGraph`]{#adv-attr-exportReferencesGraph}\ + This attribute allows builders access to the references graph of + their inputs. The attribute is a list of inputs in the Nix store + whose references graph the builder needs to know. The value of + this attribute should be a list of pairs `[ name1 path1 name2 + path2 ... ]`. The references graph of each *pathN* will be stored + in a text file *nameN* in the temporary build directory. The text + files have the format used by `nix-store --register-validity` + (with the deriver fields left empty). For example, when the + following derivation is built: + + ```nix + derivation { + ... + exportReferencesGraph = [ "libfoo-graph" libfoo ]; + }; + ``` + + the references graph of `libfoo` is placed in the file + `libfoo-graph` in the temporary build directory. + + `exportReferencesGraph` is useful for builders that want to do + something with the closure of a store path. Examples include the + builders in NixOS that generate the initial ramdisk for booting + Linux (a `cpio` archive containing the closure of the boot script) + and the ISO-9660 image for the installation CD (which is populated + with a Nix store containing the closure of a bootable NixOS + configuration). + + - [`passAsFile`]{#adv-attr-passAsFile}\ + A list of names of attributes that should be passed via files rather + than environment variables. For example, if you have + + ```nix + passAsFile = ["big"]; + big = "a very long string"; + ``` + + then when the builder runs, the environment variable `bigPath` + will contain the absolute path to a temporary file containing `a + very long string`. That is, for any attribute *x* listed in + `passAsFile`, Nix will pass an environment variable `xPath` + holding the path of the file containing the value of attribute + *x*. This is useful when you need to pass large strings to a + builder, since most operating systems impose a limit on the size + of the environment (typically, a few hundred kilobyte). + + - [`__structuredAttrs`]{#adv-attr-structuredAttrs}\ + If the special attribute `__structuredAttrs` is set to `true`, the other derivation + attributes are serialised into a file in JSON format. The environment variable + `NIX_ATTRS_JSON_FILE` points to the exact location of that file both in a build + and a [`nix-shell`](../command-ref/nix-shell.md). This obviates the need for + [`passAsFile`](#adv-attr-passAsFile) since JSON files have no size restrictions, + unlike process environments. + + It also makes it possible to tweak derivation settings in a structured way; see + [`outputChecks`](#adv-attr-outputChecks) for example. + + As a convenience to Bash builders, + Nix writes a script that initialises shell variables + corresponding to all attributes that are representable in Bash. The + environment variable `NIX_ATTRS_SH_FILE` points to the exact + location of the script, both in a build and a + [`nix-shell`](../command-ref/nix-shell.md). This includes non-nested + (associative) arrays. For example, the attribute `hardening.format = true` + ends up as the Bash associative array element `${hardening[format]}`. + + > **Warning** + > + > If set to `true`, other advanced attributes such as [`allowedReferences`](#adv-attr-allowedReferences), [`allowedReferences`](#adv-attr-allowedReferences), [`allowedRequisites`](#adv-attr-allowedRequisites), + [`disallowedReferences`](#adv-attr-disallowedReferences) and [`disallowedRequisites`](#adv-attr-disallowedRequisites), maxSize, and maxClosureSize. + will have no effect. + +## Output checks + - [`allowedReferences`]{#adv-attr-allowedReferences}\ The optional attribute `allowedReferences` specifies a list of legal references (dependencies) of the output of the builder. For example, @@ -55,34 +132,89 @@ Derivations can declare some infrequently used optional attributes. dependency on `foobar` or any other derivation depending recursively on `foobar`. - - [`exportReferencesGraph`]{#adv-attr-exportReferencesGraph}\ - This attribute allows builders access to the references graph of - their inputs. The attribute is a list of inputs in the Nix store - whose references graph the builder needs to know. The value of - this attribute should be a list of pairs `[ name1 path1 name2 - path2 ... ]`. The references graph of each *pathN* will be stored - in a text file *nameN* in the temporary build directory. The text - files have the format used by `nix-store --register-validity` - (with the deriver fields left empty). For example, when the - following derivation is built: + - [`outputChecks`]{#adv-attr-outputChecks}\ + When using [structured attributes](#adv-attr-structuredAttrs), the `outputChecks` + attribute allows defining checks per-output. + + In addition to + [`allowedReferences`](#adv-attr-allowedReferences), [`allowedRequisites`](#adv-attr-allowedRequisites), + [`disallowedReferences`](#adv-attr-disallowedReferences) and [`disallowedRequisites`](#adv-attr-disallowedRequisites), + the following attributes are available: + + - `maxSize` defines the maximum size of the resulting [store object](@docroot@/store/store-object.md). + - `maxClosureSize` defines the maximum size of the output's closure. + - `ignoreSelfRefs` controls whether self-references should be considered when + checking for allowed references/requisites. + + Example: ```nix - derivation { - ... - exportReferencesGraph = [ "libfoo-graph" libfoo ]; + __structuredAttrs = true; + + outputChecks.out = { + # The closure of 'out' must not be larger than 256 MiB. + maxClosureSize = 256 * 1024 * 1024; + + # It must not refer to the C compiler or to the 'dev' output. + disallowedRequisites = [ stdenv.cc "dev" ]; + }; + + outputChecks.dev = { + # The 'dev' output must not be larger than 128 KiB. + maxSize = 128 * 1024; }; ``` - the references graph of `libfoo` is placed in the file - `libfoo-graph` in the temporary build directory. +## Other output modifications - `exportReferencesGraph` is useful for builders that want to do - something with the closure of a store path. Examples include the - builders in NixOS that generate the initial ramdisk for booting - Linux (a `cpio` archive containing the closure of the boot script) - and the ISO-9660 image for the installation CD (which is populated - with a Nix store containing the closure of a bootable NixOS - configuration). + - [`unsafeDiscardReferences`]{#adv-attr-unsafeDiscardReferences}\ + + When using [structured attributes](#adv-attr-structuredAttrs), the + attribute `unsafeDiscardReferences` is an attribute set with a boolean value for each output name. + If set to `true`, it disables scanning the output for runtime dependencies. + + Example: + + ```nix + __structuredAttrs = true; + unsafeDiscardReferences.out = true; + ``` + + This is useful, for example, when generating self-contained filesystem images with + their own embedded Nix store: hashes found inside such an image refer + to the embedded store and not to the host's Nix store. + +## Build scheduling + + - [`preferLocalBuild`]{#adv-attr-preferLocalBuild}\ + If this attribute is set to `true` and [distributed building is enabled](@docroot@/command-ref/conf-file.md#conf-builders), then, if possible, the derivation will be built locally instead of being forwarded to a remote machine. + This is useful for derivations that are cheapest to build locally. + + - [`allowSubstitutes`]{#adv-attr-allowSubstitutes}\ + If this attribute is set to `false`, then Nix will always build this derivation (locally or remotely); it will not try to substitute its outputs. + This is useful for derivations that are cheaper to build than to substitute. + + This attribute can be ignored by setting [`always-allow-substitutes`](@docroot@/command-ref/conf-file.md#conf-always-allow-substitutes) to `true`. + + > **Note** + > + > If set to `false`, the [`builder`] should be able to run on the system type specified in the [`system` attribute](./derivations.md#attr-system), since the derivation cannot be substituted. + + [`builder`]: ./derivations.md#attr-builder + +- [`requiredSystemFeatures`]{#adv-attr-requiredSystemFeatures}\ + + If a derivation has the `requiredSystemFeatures` attribute, then Nix will only build it on a machine that has the corresponding features set in its [`system-features` configuration](@docroot@/command-ref/conf-file.md#conf-system-features). + + For example, setting + + ```nix + requiredSystemFeatures = [ "kvm" ]; + ``` + + ensures that the derivation can only be built on a machine with the `kvm` feature. + +# Impure builder configuration - [`impureEnvVars`]{#adv-attr-impureEnvVars}\ This attribute allows you to specify a list of environment variables @@ -119,128 +251,6 @@ Derivations can declare some infrequently used optional attributes. [`impure-env`](@docroot@/command-ref/conf-file.md#conf-impure-env) configuration setting. - - [`passAsFile`]{#adv-attr-passAsFile}\ - A list of names of attributes that should be passed via files rather - than environment variables. For example, if you have - - ```nix - passAsFile = ["big"]; - big = "a very long string"; - ``` - - then when the builder runs, the environment variable `bigPath` - will contain the absolute path to a temporary file containing `a - very long string`. That is, for any attribute *x* listed in - `passAsFile`, Nix will pass an environment variable `xPath` - holding the path of the file containing the value of attribute - *x*. This is useful when you need to pass large strings to a - builder, since most operating systems impose a limit on the size - of the environment (typically, a few hundred kilobyte). - - - [`preferLocalBuild`]{#adv-attr-preferLocalBuild}\ - If this attribute is set to `true` and [distributed building is enabled](@docroot@/command-ref/conf-file.md#conf-builders), then, if possible, the derivation will be built locally instead of being forwarded to a remote machine. - This is useful for derivations that are cheapest to build locally. - - - [`allowSubstitutes`]{#adv-attr-allowSubstitutes}\ - If this attribute is set to `false`, then Nix will always build this derivation (locally or remotely); it will not try to substitute its outputs. - This is useful for derivations that are cheaper to build than to substitute. - - This attribute can be ignored by setting [`always-allow-substitutes`](@docroot@/command-ref/conf-file.md#conf-always-allow-substitutes) to `true`. - - > **Note** - > - > If set to `false`, the [`builder`] should be able to run on the system type specified in the [`system` attribute](./derivations.md#attr-system), since the derivation cannot be substituted. - - [`builder`]: ./derivations.md#attr-builder - - - [`__structuredAttrs`]{#adv-attr-structuredAttrs}\ - If the special attribute `__structuredAttrs` is set to `true`, the other derivation - attributes are serialised into a file in JSON format. The environment variable - `NIX_ATTRS_JSON_FILE` points to the exact location of that file both in a build - and a [`nix-shell`](../command-ref/nix-shell.md). This obviates the need for - [`passAsFile`](#adv-attr-passAsFile) since JSON files have no size restrictions, - unlike process environments. - - It also makes it possible to tweak derivation settings in a structured way; see - [`outputChecks`](#adv-attr-outputChecks) for example. - - As a convenience to Bash builders, - Nix writes a script that initialises shell variables - corresponding to all attributes that are representable in Bash. The - environment variable `NIX_ATTRS_SH_FILE` points to the exact - location of the script, both in a build and a - [`nix-shell`](../command-ref/nix-shell.md). This includes non-nested - (associative) arrays. For example, the attribute `hardening.format = true` - ends up as the Bash associative array element `${hardening[format]}`. - - > **Warning** - > - > If set to `true`, other advanced attributes such as [`allowedReferences`](#adv-attr-allowedReferences), [`allowedReferences`](#adv-attr-allowedReferences), [`allowedRequisites`](#adv-attr-allowedRequisites), - [`disallowedReferences`](#adv-attr-disallowedReferences) and [`disallowedRequisites`](#adv-attr-disallowedRequisites), maxSize, and maxClosureSize. - will have no effect. - - - [`outputChecks`]{#adv-attr-outputChecks}\ - When using [structured attributes](#adv-attr-structuredAttrs), the `outputChecks` - attribute allows defining checks per-output. - - In addition to - [`allowedReferences`](#adv-attr-allowedReferences), [`allowedRequisites`](#adv-attr-allowedRequisites), - [`disallowedReferences`](#adv-attr-disallowedReferences) and [`disallowedRequisites`](#adv-attr-disallowedRequisites), - the following attributes are available: - - - `maxSize` defines the maximum size of the resulting [store object](@docroot@/store/store-object.md). - - `maxClosureSize` defines the maximum size of the output's closure. - - `ignoreSelfRefs` controls whether self-references should be considered when - checking for allowed references/requisites. - - Example: - - ```nix - __structuredAttrs = true; - - outputChecks.out = { - # The closure of 'out' must not be larger than 256 MiB. - maxClosureSize = 256 * 1024 * 1024; - - # It must not refer to the C compiler or to the 'dev' output. - disallowedRequisites = [ stdenv.cc "dev" ]; - }; - - outputChecks.dev = { - # The 'dev' output must not be larger than 128 KiB. - maxSize = 128 * 1024; - }; - ``` - - - [`unsafeDiscardReferences`]{#adv-attr-unsafeDiscardReferences}\ - - When using [structured attributes](#adv-attr-structuredAttrs), the - attribute `unsafeDiscardReferences` is an attribute set with a boolean value for each output name. - If set to `true`, it disables scanning the output for runtime dependencies. - - Example: - - ```nix - __structuredAttrs = true; - unsafeDiscardReferences.out = true; - ``` - - This is useful, for example, when generating self-contained filesystem images with - their own embedded Nix store: hashes found inside such an image refer - to the embedded store and not to the host's Nix store. - -- [`requiredSystemFeatures`]{#adv-attr-requiredSystemFeatures}\ - - If a derivation has the `requiredSystemFeatures` attribute, then Nix will only build it on a machine that has the corresponding features set in its [`system-features` configuration](@docroot@/command-ref/conf-file.md#conf-system-features). - - For example, setting - - ```nix - requiredSystemFeatures = [ "kvm" ]; - ``` - - ensures that the derivation can only be built on a machine with the `kvm` feature. - ## Setting the derivation type As discussed in [Derivation Outputs and Types of Derivations](@docroot@/store/derivation/outputs/index.md), there are multiples kinds of derivations / kinds of derivation outputs. diff --git a/doc/manual/source/language/syntax.md b/doc/manual/source/language/syntax.md index 506afbea1..08a64f684 100644 --- a/doc/manual/source/language/syntax.md +++ b/doc/manual/source/language/syntax.md @@ -443,7 +443,7 @@ three kinds of patterns: This works on any set that contains at least the three named attributes. - It is possible to provide *default values* for attributes, in + - It is possible to provide *default values* for attributes, in which case they are allowed to be missing. A default value is specified by writing `name ? e`, where *e* is an arbitrary expression. For example, @@ -503,6 +503,45 @@ three kinds of patterns: > [ 23 {} ] > ``` + - All bindings introduced by the function are in scope in the entire function expression; not just in the body. + It can therefore be used in default values. + + > **Example** + > + > A parameter (`x`), is used in the default value for another parameter (`y`): + > + > ```nix + > let + > f = { x, y ? [x] }: { inherit y; }; + > in + > f { x = 3; } + > ``` + > + > This evaluates to: + > + > ```nix + > { + > y = [ 3 ]; + > } + > ``` + + > **Example** + > + > The binding of an `@` pattern, `args`, is used in the default value for a parameter, `x`: + > + > ```nix + > let + > f = args@{ x ? args.a, ... }: x; + > in + > f { a = 1; } + > ``` + > + > This evaluates to: + > + > ```nix + > 1 + > ``` + Note that functions do not have names. If you want to give them a name, you can bind them to an attribute, e.g., diff --git a/doc/manual/source/protocols/store-path.md b/doc/manual/source/protocols/store-path.md index 9abd83f4f..5be235501 100644 --- a/doc/manual/source/protocols/store-path.md +++ b/doc/manual/source/protocols/store-path.md @@ -7,7 +7,7 @@ The format of this specification is close to [Extended Backus–Naur form](https Regular users do *not* need to know this information --- store paths can be treated as black boxes computed from the properties of the store objects they refer to. But for those interested in exactly how Nix works, e.g. if they are reimplementing it, this information can be useful. -[store path](@docroot@/store/store-path.md) +[store path]: @docroot@/store/store-path.md ## Store path proper @@ -20,14 +20,17 @@ where - `store-dir` = the [store directory](@docroot@/store/store-path.md#store-directory) -- `digest` = base-32 representation of the first 160 bits of a [SHA-256] hash of `fingerprint` +- `digest` = base-32 representation of the compressed to 160 bits [SHA-256] hash of `fingerprint` - This the hash part of the store name +For the definition of the hash compression algorithm, please refer to the section 5.1 of +the [Nix thesis](https://edolstra.github.io/pubs/phd-thesis.pdf), which also defines the +specifics of base-32 encoding. Note that base-32 encoding processes the hash bytestring from +the end, while base-16 processes in from the beginning. ## Fingerprint - ```ebnf - fingerprint = type ":" sha256 ":" inner-digest ":" store ":" name + fingerprint = type ":sha256:" inner-digest ":" store ":" name ``` Note that it includes the location of the store as well as the name to make sure that changes to either of those are reflected in the hash @@ -70,7 +73,8 @@ where `id` is the name of the output (usually, "out"). For content-addressed store objects, `id`, is always "out". -- `inner-digest` = base-16 representation of a SHA-256 hash of `inner-fingerprint` +- `inner-digest` = base-16 representation of a SHA-256 hash of `inner-fingerprint`. + The base-16 encoding uses lower-cased hex digits. ## Inner fingerprint @@ -82,7 +86,7 @@ where - if `type` = `"source:" ...`: - the hash of the [Nix Archive (NAR)] serialization of the [file system object](@docroot@/store/file-system-object.md) of the store object. + the [Nix Archive (NAR)] serialization of the [file system object](@docroot@/store/file-system-object.md) of the store object. - if `type` = `"output:" id`: diff --git a/doc/manual/source/release-notes/rl-2.28.md b/doc/manual/source/release-notes/rl-2.28.md new file mode 100644 index 000000000..6da09546e --- /dev/null +++ b/doc/manual/source/release-notes/rl-2.28.md @@ -0,0 +1,105 @@ +# Release 2.28.0 (2025-04-02) + +This is an atypical release, and for almost all intents and purposes, it is just a continuation of 2.27; not a feature release. + +We had originally set the goal of making 2.27 the Nixpkgs default for NixOS 25.05, but dependents that link to Nix need certain _interface breaking_ changes in the C++ headers. This is not something we should do in a patch release, so this is why we branched 2.28 right off 2.27 instead of `master`. + +This completes the infrastructure overhaul for the [RFC 132](https://github.com/NixOS/rfcs/blob/master/rfcs/0132-meson-builds-nix.md) switchover to meson as our build system. + +## Major changes + +- Unstable C++ API reworked + [#12836](https://github.com/NixOS/nix/pull/12836) + [#12798](https://github.com/NixOS/nix/pull/12798) + [#12773](https://github.com/NixOS/nix/pull/12773) + + Now the C++ interface confirms to common conventions much better than before: + + - All headers are expected to be included with the initial `nix/`, e.g. as `#include "nix/....hh"` (what Nix's headers now do) or `#include ` (what downstream projects may choose to do). + Likewise, the pkg-config files have `-I${includedir}` not `-I${includedir}/nix` or similar. + + Including without the `nix/` like before sometimes worked because of how for `#include` C pre-process checks the directory containing the current file, not just the lookup path, but this was not reliable. + + - All configuration headers are included explicitly by the (regular) headers that need them. + There is no more need to pass `-include` to force additional files to be included. + + - The public, installed configuration headers no longer contain implementation-specific details that are not relevant to the API. + The vast majority of definitions that were previously in there are now moved to new headers that are not installed, but used during Nix's own compilation only. + The remaining macro definitions are renamed to have `NIX_` as a prefix. + + - The name of the Nix component the header comes from + (e.g. `util`, `store`, `expr`, `flake`, etc.) + is now part of the path to the header, coming after `nix` and before the header name + (or rest of the header path, if it is already in a directory). + + Here is a contrived diff showing a few of these changes at once: + + ```diff + @@ @@ + -#include "derived-path.hh" + +#include "nix/store/derived-path.hh" + @@ @@ + +// Would include for the variables used before. But when other headers + +// need these variables. those will include these config themselves. + +#include "nix/store/config.hh" + +#include "nix/expr/config.hh" + @@ @@ + -#include "config.hh" + +// Additionally renamed to distinguish from components' config headers. + +#include "nix/util/configuration.hh" + @@ @@ + -#if HAVE_ACL_SUPPORT + +#if NIX_SUPPORT_ACL + @@ @@ + -#if HAVE_BOEHMGC + +#if NIX_USE_BOEHMGC + @@ @@ + #endif + #endif + @@ @@ + -const char *s = "hi from " SYSTEM; + +const char *s = "hi from " NIX_LOCAL_SYSTEM; + ``` + +- C API `nix_flake_init_global` removed [#5638](https://github.com/NixOS/nix/issues/5638) [#12759](https://github.com/NixOS/nix/pull/12759) + + In order to improve the modularity of the code base, we are removing a use of global state, and therefore the `nix_flake_init_global` function. + + Instead, use `nix_flake_settings_add_to_eval_state_builder`. + For example: + + ```diff + - nix_flake_init_global(ctx, settings); + - HANDLE_ERROR(ctx); + - + nix_eval_state_builder * builder = nix_eval_state_builder_new(ctx, store); + HANDLE_ERROR(ctx); + + + nix_flake_settings_add_to_eval_state_builder(ctx, settings, builder); + + HANDLE_ERROR(ctx); + ``` + + Although this change is not as critical, we figured it would be good to do this API change at the same time, also. + Also note that we try to keep the C API compatible, but we decided to break this function because it was young and likely not in widespread use yet. This frees up time to make important progress on the rest of the C API. + +# Contributors + +This earlier-than-usual release was made possible by the following 16 contributors: + +- Farid Zakaria [**(@fzakaria)**](https://github.com/fzakaria) +- Jörg Thalheim [**(@Mic92)**](https://github.com/Mic92) +- Eelco Dolstra [**(@edolstra)**](https://github.com/edolstra) +- Graham Christensen [**(@grahamc)**](https://github.com/grahamc) +- Thomas Miedema [**(@thomie)**](https://github.com/thomie) +- Brian McKenna [**(@puffnfresh)**](https://github.com/puffnfresh) +- Sergei Trofimovich [**(@trofi)**](https://github.com/trofi) +- Dmitry Bogatov [**(@KAction)**](https://github.com/KAction) +- Erik Nygren [**(@Kirens)**](https://github.com/Kirens) +- John Ericson [**(@Ericson2314)**](https://github.com/Ericson2314) +- Sergei Zimmerman [**(@xokdvium)**](https://github.com/xokdvium) +- Ruby Rose [**(@oldshensheep)**](https://github.com/oldshensheep) +- Robert Hensing [**(@roberth)**](https://github.com/roberth) +- jade [**(@lf-)**](https://github.com/lf-) +- Félix [**(@picnoir)**](https://github.com/picnoir) +- Valentin Gagarin [**(@fricklerhandwerk)**](https://github.com/fricklerhandwerk) +- Dmitry Bogatov diff --git a/doc/manual/source/store/derivation/outputs/index.md b/doc/manual/source/store/derivation/outputs/index.md index 15070a18f..b02e6eca0 100644 --- a/doc/manual/source/store/derivation/outputs/index.md +++ b/doc/manual/source/store/derivation/outputs/index.md @@ -1,7 +1,7 @@ # Derivation Outputs and Types of Derivations As stated on the [main pages on derivations](../index.md#store-derivation), -a derivation produces [store objects], which are known as the *outputs* of the derivation. +a derivation produces [store objects](@docroot@/store/store-object.md), which are known as the *outputs* of the derivation. Indeed, the entire point of derivations is to produce these outputs, and to reliably and reproducably produce these derivations each time the derivation is run. One of the parts of a derivation is its *outputs specification*, which specifies certain information about the outputs the derivation produces when run. @@ -9,7 +9,7 @@ The outputs specification is a map, from names to specifications for individual ## Output Names {#outputs} -Output names can be any string which is also a valid [store path] name. +Output names can be any string which is also a valid [store path](@docroot@/store/store-path.md) name. The name mapped to each output specification is not actually the name of the output. In the general case, the output store object has name `derivationName + "-" + outputSpecName`, not any other metadata about it. However, an output spec named "out" describes and output store object whose name is just the derivation name. @@ -24,11 +24,11 @@ However, an output spec named "out" describes and output store object whose name > > - The store path of `dev` will be: `/nix/store/-hello-dev`. -The outputs are the derivations are the [store objects][store object] it is obligated to produce. +The outputs are the derivations are the [store objects](@docroot@/store/store-object.md) it is obligated to produce. > **Note** > -> The formal terminology here is somewhat at adds with everyday communication in the Nix community today. +> The formal terminology here is somewhat at odds with everyday communication in the Nix community today. > "output" in casual usage tends to refer to either to the actual output store object, or the notional output spec, depending on context. > > For example "hello's `dev` output" means the store object referred to by the store path `/nix/store/-hello-dev`. @@ -64,7 +64,7 @@ The rules for this are fairly concise: (This is an arbitrary restriction that could be lifted.) -- The output is either *fixed* or *floating*, indicating whether the its store path is known prior to building it. +- The output is either *fixed* or *floating*, indicating whether the store path is known prior to building it. - With fixed content-addressing it is fixed. diff --git a/doc/manual/source/store/file-system-object/content-address.md b/doc/manual/source/store/file-system-object/content-address.md index 72b087fe9..04a1021f1 100644 --- a/doc/manual/source/store/file-system-object/content-address.md +++ b/doc/manual/source/store/file-system-object/content-address.md @@ -46,7 +46,7 @@ be many different serialisations. For these reasons, Nix has its very own archive format—the Nix Archive (NAR) format, which is carefully designed to avoid the problems described above. -The exact specification of the Nix Archive format is in `protocols/nix-archive.md` +The exact specification of the Nix Archive format is in [specified here](../../protocols/nix-archive.md). ## Content addressing File System Objects beyond a single serialisation pass @@ -80,6 +80,7 @@ Thus, Git can encode some, but not all of Nix's "File System Objects", and this In the future, we may support a Git-like hash for such file system objects, or we may adopt another Merkle DAG format which is capable of representing all Nix file system objects. + [file system object]: ../file-system-object.md [store object]: ../store-object.md [xp-feature-git-hashing]: @docroot@/development/experimental-features.md#xp-feature-git-hashing diff --git a/doc/manual/source/store/store-object/content-address.md b/doc/manual/source/store/store-object/content-address.md index ff77dd4b6..5742b9fe1 100644 --- a/doc/manual/source/store/store-object/content-address.md +++ b/doc/manual/source/store/store-object/content-address.md @@ -50,7 +50,7 @@ The hashes of these modified input streams are used instead. When validating the content address of a store object after the fact, the above process works as written. However, when first creating the store object we don't know the store object's store path, as explained just above. -We therefore, strictly speaking, do not know what value we will be replacing with the sentinental value in the inputs to hash functions. +We therefore, strictly speaking, do not know what value we will be replacing with the sentinel value in the inputs to hash functions. What instead happens is that the provisional store object --- the data from which we wish to create a store object --- is paired with a provisional "scratch" store path (that presumably was chosen when the data was created). That provisional store path is instead what is replaced with the sentinel value, rather than the final store object which we do not yet know. diff --git a/flake.nix b/flake.nix index 54cf1a36d..03c25204e 100644 --- a/flake.nix +++ b/flake.nix @@ -155,6 +155,7 @@ inherit officialRelease; pkgs = final; src = self; + maintainers = [ ]; }; }; @@ -228,24 +229,28 @@ This shouldn't build anything significant; just check that things (including derivations) are _set up_ correctly. */ - packaging-overriding = - let - pkgs = nixpkgsFor.${system}.native; - nix = self.packages.${system}.nix; - in - assert (nix.appendPatches [ pkgs.emptyFile ]).libs.nix-util.src.patches == [ pkgs.emptyFile ]; - if pkgs.stdenv.buildPlatform.isDarwin then - lib.warn "packaging-overriding check currently disabled because of a permissions issue on macOS" pkgs.emptyFile - else - # If this fails, something might be wrong with how we've wired the scope, - # or something could be broken in Nixpkgs. - pkgs.testers.testEqualContents { - assertion = "trivial patch does not change source contents"; - expected = "${./.}"; - actual = - # Same for all components; nix-util is an arbitrary pick - (nix.appendPatches [ pkgs.emptyFile ]).libs.nix-util.src; - }; + # Disabled due to a bug in `testEqualContents` (see + # https://github.com/NixOS/nix/issues/12690). + /* + packaging-overriding = + let + pkgs = nixpkgsFor.${system}.native; + nix = self.packages.${system}.nix; + in + assert (nix.appendPatches [ pkgs.emptyFile ]).libs.nix-util.src.patches == [ pkgs.emptyFile ]; + if pkgs.stdenv.buildPlatform.isDarwin then + lib.warn "packaging-overriding check currently disabled because of a permissions issue on macOS" pkgs.emptyFile + else + # If this fails, something might be wrong with how we've wired the scope, + # or something could be broken in Nixpkgs. + pkgs.testers.testEqualContents { + assertion = "trivial patch does not change source contents"; + expected = "${./.}"; + actual = + # Same for all components; nix-util is an arbitrary pick + (nix.appendPatches [ pkgs.emptyFile ]).libs.nix-util.src; + }; + */ } // (lib.optionalAttrs (builtins.elem system linux64BitSystems)) { dockerImage = self.hydraJobs.dockerImage.${system}; @@ -261,18 +266,46 @@ flatMapAttrs ( { - "" = nixpkgsFor.${system}.native; + # Run all tests with UBSAN enabled. Running both with ubsan and + # without doesn't seem to have much immediate benefit for doubling + # the GHA CI workaround. + # + # TODO: Work toward enabling "address,undefined" if it seems feasible. + # This would maybe require dropping Boost coroutines and ignoring intentional + # memory leaks with detect_leaks=0. + "" = rec { + nixpkgs = nixpkgsFor.${system}.native; + nixComponents = nixpkgs.nixComponents.overrideScope ( + nixCompFinal: nixCompPrev: { + mesonComponentOverrides = _finalAttrs: prevAttrs: { + mesonFlags = + (prevAttrs.mesonFlags or [ ]) + # TODO: Macos builds instrumented with ubsan take very long + # to run functional tests. + ++ lib.optionals (!nixpkgs.stdenv.hostPlatform.isDarwin) [ + (lib.mesonOption "b_sanitize" "undefined") + ]; + }; + } + ); + }; } // lib.optionalAttrs (!nixpkgsFor.${system}.native.stdenv.hostPlatform.isDarwin) { # TODO: enable static builds for darwin, blocked on: # https://github.com/NixOS/nixpkgs/issues/320448 # TODO: disabled to speed up GHA CI. - #"static-" = nixpkgsFor.${system}.native.pkgsStatic; + # "static-" = { + # nixpkgs = nixpkgsFor.${system}.native.pkgsStatic; + # }; } ) ( - nixpkgsPrefix: nixpkgs: - flatMapAttrs nixpkgs.nixComponents ( + nixpkgsPrefix: + { + nixpkgs, + nixComponents ? nixpkgs.nixComponents, + }: + flatMapAttrs nixComponents ( pkgName: pkg: flatMapAttrs pkg.tests or { } ( testName: test: { @@ -281,7 +314,7 @@ ) ) // lib.optionalAttrs (nixpkgs.stdenv.hostPlatform == nixpkgs.stdenv.buildPlatform) { - "${nixpkgsPrefix}nix-functional-tests" = nixpkgs.nixComponents.nix-functional-tests; + "${nixpkgsPrefix}nix-functional-tests" = nixComponents.nix-functional-tests; } ) // devFlake.checks.${system} or { } diff --git a/maintainers/data/release-credits-email-to-handle.json b/maintainers/data/release-credits-email-to-handle.json index 8f5031474..977555278 100644 --- a/maintainers/data/release-credits-email-to-handle.json +++ b/maintainers/data/release-credits-email-to-handle.json @@ -145,5 +145,12 @@ "thebenmachine+git@gmail.com": "bmillwood", "leandro@kip93.net": "kip93", "hello@briancamacho.me": "b-camacho", - "bcamacho@anduril.com": "bcamacho2" + "bcamacho@anduril.com": "bcamacho2", + "oldshensheep@gmail.com": "oldshensheep", + "thomasmiedema@gmail.com": "thomie", + "xokdvium@proton.me": "xokdvium", + "kaction@disroot.org": "KAction", + "serenity@kaction.cc": null, + "dev@erik.work": "Kirens", + "felix@alternativebit.fr": "picnoir" } \ No newline at end of file diff --git a/maintainers/data/release-credits-handle-to-name.json b/maintainers/data/release-credits-handle-to-name.json index 7149149c0..a03a811d4 100644 --- a/maintainers/data/release-credits-handle-to-name.json +++ b/maintainers/data/release-credits-handle-to-name.json @@ -129,5 +129,9 @@ "SomeoneSerge": "Someone", "b-camacho": "Brian Camacho", "MaxHearnden": null, - "kip93": "Leandro Emmanuel Reina Kiperman" + "kip93": "Leandro Emmanuel Reina Kiperman", + "oldshensheep": "Ruby Rose", + "KAction": "Dmitry Bogatov", + "thomie": "Thomas Miedema", + "Kirens": "Erik Nygren" } \ No newline at end of file diff --git a/maintainers/flake-module.nix b/maintainers/flake-module.nix index 4c75df246..a8c52eb46 100644 --- a/maintainers/flake-module.nix +++ b/maintainers/flake-module.nix @@ -84,340 +84,340 @@ ''^precompiled-headers\.h$'' ''^src/build-remote/build-remote\.cc$'' ''^src/libcmd/built-path\.cc$'' - ''^src/libcmd/built-path\.hh$'' + ''^src/libcmd/include/nix/cmd/built-path\.hh$'' ''^src/libcmd/common-eval-args\.cc$'' - ''^src/libcmd/common-eval-args\.hh$'' + ''^src/libcmd/include/nix/cmd/common-eval-args\.hh$'' ''^src/libcmd/editor-for\.cc$'' ''^src/libcmd/installable-attr-path\.cc$'' - ''^src/libcmd/installable-attr-path\.hh$'' + ''^src/libcmd/include/nix/cmd/installable-attr-path\.hh$'' ''^src/libcmd/installable-derived-path\.cc$'' - ''^src/libcmd/installable-derived-path\.hh$'' + ''^src/libcmd/include/nix/cmd/installable-derived-path\.hh$'' ''^src/libcmd/installable-flake\.cc$'' - ''^src/libcmd/installable-flake\.hh$'' + ''^src/libcmd/include/nix/cmd/installable-flake\.hh$'' ''^src/libcmd/installable-value\.cc$'' - ''^src/libcmd/installable-value\.hh$'' + ''^src/libcmd/include/nix/cmd/installable-value\.hh$'' ''^src/libcmd/installables\.cc$'' - ''^src/libcmd/installables\.hh$'' - ''^src/libcmd/legacy\.hh$'' + ''^src/libcmd/include/nix/cmd/installables\.hh$'' + ''^src/libcmd/include/nix/cmd/legacy\.hh$'' ''^src/libcmd/markdown\.cc$'' ''^src/libcmd/misc-store-flags\.cc$'' ''^src/libcmd/repl-interacter\.cc$'' - ''^src/libcmd/repl-interacter\.hh$'' + ''^src/libcmd/include/nix/cmd/repl-interacter\.hh$'' ''^src/libcmd/repl\.cc$'' - ''^src/libcmd/repl\.hh$'' + ''^src/libcmd/include/nix/cmd/repl\.hh$'' ''^src/libexpr-c/nix_api_expr\.cc$'' ''^src/libexpr-c/nix_api_external\.cc$'' ''^src/libexpr/attr-path\.cc$'' - ''^src/libexpr/attr-path\.hh$'' + ''^src/libexpr/include/nix/expr/attr-path\.hh$'' ''^src/libexpr/attr-set\.cc$'' - ''^src/libexpr/attr-set\.hh$'' + ''^src/libexpr/include/nix/expr/attr-set\.hh$'' ''^src/libexpr/eval-cache\.cc$'' - ''^src/libexpr/eval-cache\.hh$'' + ''^src/libexpr/include/nix/expr/eval-cache\.hh$'' ''^src/libexpr/eval-error\.cc$'' - ''^src/libexpr/eval-inline\.hh$'' + ''^src/libexpr/include/nix/expr/eval-inline\.hh$'' ''^src/libexpr/eval-settings\.cc$'' - ''^src/libexpr/eval-settings\.hh$'' + ''^src/libexpr/include/nix/expr/eval-settings\.hh$'' ''^src/libexpr/eval\.cc$'' - ''^src/libexpr/eval\.hh$'' + ''^src/libexpr/include/nix/expr/eval\.hh$'' ''^src/libexpr/function-trace\.cc$'' - ''^src/libexpr/gc-small-vector\.hh$'' + ''^src/libexpr/include/nix/expr/gc-small-vector\.hh$'' ''^src/libexpr/get-drvs\.cc$'' - ''^src/libexpr/get-drvs\.hh$'' + ''^src/libexpr/include/nix/expr/get-drvs\.hh$'' ''^src/libexpr/json-to-value\.cc$'' ''^src/libexpr/nixexpr\.cc$'' - ''^src/libexpr/nixexpr\.hh$'' - ''^src/libexpr/parser-state\.hh$'' + ''^src/libexpr/include/nix/expr/nixexpr\.hh$'' + ''^src/libexpr/include/nix/expr/parser-state\.hh$'' ''^src/libexpr/primops\.cc$'' - ''^src/libexpr/primops\.hh$'' + ''^src/libexpr/include/nix/expr/primops\.hh$'' ''^src/libexpr/primops/context\.cc$'' ''^src/libexpr/primops/fetchClosure\.cc$'' ''^src/libexpr/primops/fetchMercurial\.cc$'' ''^src/libexpr/primops/fetchTree\.cc$'' ''^src/libexpr/primops/fromTOML\.cc$'' ''^src/libexpr/print-ambiguous\.cc$'' - ''^src/libexpr/print-ambiguous\.hh$'' - ''^src/libexpr/print-options\.hh$'' + ''^src/libexpr/include/nix/expr/print-ambiguous\.hh$'' + ''^src/libexpr/include/nix/expr/print-options\.hh$'' ''^src/libexpr/print\.cc$'' - ''^src/libexpr/print\.hh$'' + ''^src/libexpr/include/nix/expr/print\.hh$'' ''^src/libexpr/search-path\.cc$'' - ''^src/libexpr/symbol-table\.hh$'' + ''^src/libexpr/include/nix/expr/symbol-table\.hh$'' ''^src/libexpr/value-to-json\.cc$'' - ''^src/libexpr/value-to-json\.hh$'' + ''^src/libexpr/include/nix/expr/value-to-json\.hh$'' ''^src/libexpr/value-to-xml\.cc$'' - ''^src/libexpr/value-to-xml\.hh$'' - ''^src/libexpr/value\.hh$'' + ''^src/libexpr/include/nix/expr/value-to-xml\.hh$'' + ''^src/libexpr/include/nix/expr/value\.hh$'' ''^src/libexpr/value/context\.cc$'' - ''^src/libexpr/value/context\.hh$'' + ''^src/libexpr/include/nix/expr/value/context\.hh$'' ''^src/libfetchers/attrs\.cc$'' ''^src/libfetchers/cache\.cc$'' - ''^src/libfetchers/cache\.hh$'' + ''^src/libfetchers/include/nix/fetchers/cache\.hh$'' ''^src/libfetchers/fetch-settings\.cc$'' - ''^src/libfetchers/fetch-settings\.hh$'' + ''^src/libfetchers/include/nix/fetchers/fetch-settings\.hh$'' ''^src/libfetchers/fetch-to-store\.cc$'' ''^src/libfetchers/fetchers\.cc$'' - ''^src/libfetchers/fetchers\.hh$'' + ''^src/libfetchers/include/nix/fetchers/fetchers\.hh$'' ''^src/libfetchers/filtering-source-accessor\.cc$'' - ''^src/libfetchers/filtering-source-accessor\.hh$'' + ''^src/libfetchers/include/nix/fetchers/filtering-source-accessor\.hh$'' ''^src/libfetchers/fs-source-accessor\.cc$'' - ''^src/libfetchers/fs-source-accessor\.hh$'' + ''^src/libfetchers/include/nix/fs-source-accessor\.hh$'' ''^src/libfetchers/git-utils\.cc$'' - ''^src/libfetchers/git-utils\.hh$'' + ''^src/libfetchers/include/nix/fetchers/git-utils\.hh$'' ''^src/libfetchers/github\.cc$'' ''^src/libfetchers/indirect\.cc$'' ''^src/libfetchers/memory-source-accessor\.cc$'' ''^src/libfetchers/path\.cc$'' ''^src/libfetchers/registry\.cc$'' - ''^src/libfetchers/registry\.hh$'' + ''^src/libfetchers/include/nix/fetchers/registry\.hh$'' ''^src/libfetchers/tarball\.cc$'' - ''^src/libfetchers/tarball\.hh$'' + ''^src/libfetchers/include/nix/fetchers/tarball\.hh$'' ''^src/libfetchers/git\.cc$'' ''^src/libfetchers/mercurial\.cc$'' ''^src/libflake/flake/config\.cc$'' ''^src/libflake/flake/flake\.cc$'' - ''^src/libflake/flake/flake\.hh$'' + ''^src/libflake/include/nix/flake/flake\.hh$'' ''^src/libflake/flake/flakeref\.cc$'' - ''^src/libflake/flake/flakeref\.hh$'' + ''^src/libflake/include/nix/flake/flakeref\.hh$'' ''^src/libflake/flake/lockfile\.cc$'' - ''^src/libflake/flake/lockfile\.hh$'' + ''^src/libflake/include/nix/flake/lockfile\.hh$'' ''^src/libflake/flake/url-name\.cc$'' ''^src/libmain/common-args\.cc$'' - ''^src/libmain/common-args\.hh$'' + ''^src/libmain/include/nix/main/common-args\.hh$'' ''^src/libmain/loggers\.cc$'' - ''^src/libmain/loggers\.hh$'' + ''^src/libmain/include/nix/main/loggers\.hh$'' ''^src/libmain/progress-bar\.cc$'' ''^src/libmain/shared\.cc$'' - ''^src/libmain/shared\.hh$'' + ''^src/libmain/include/nix/main/shared\.hh$'' ''^src/libmain/unix/stack\.cc$'' ''^src/libstore/binary-cache-store\.cc$'' - ''^src/libstore/binary-cache-store\.hh$'' - ''^src/libstore/build-result\.hh$'' - ''^src/libstore/builtins\.hh$'' + ''^src/libstore/include/nix/store/binary-cache-store\.hh$'' + ''^src/libstore/include/nix/store/build-result\.hh$'' + ''^src/libstore/include/nix/store/builtins\.hh$'' ''^src/libstore/builtins/buildenv\.cc$'' - ''^src/libstore/builtins/buildenv\.hh$'' - ''^src/libstore/common-protocol-impl\.hh$'' + ''^src/libstore/include/nix/store/builtins/buildenv\.hh$'' + ''^src/libstore/include/nix/store/common-protocol-impl\.hh$'' ''^src/libstore/common-protocol\.cc$'' - ''^src/libstore/common-protocol\.hh$'' - ''^src/libstore/common-ssh-store-config\.hh$'' + ''^src/libstore/include/nix/store/common-protocol\.hh$'' + ''^src/libstore/include/nix/store/common-ssh-store-config\.hh$'' ''^src/libstore/content-address\.cc$'' - ''^src/libstore/content-address\.hh$'' + ''^src/libstore/include/nix/store/content-address\.hh$'' ''^src/libstore/daemon\.cc$'' - ''^src/libstore/daemon\.hh$'' + ''^src/libstore/include/nix/store/daemon\.hh$'' ''^src/libstore/derivations\.cc$'' - ''^src/libstore/derivations\.hh$'' + ''^src/libstore/include/nix/store/derivations\.hh$'' ''^src/libstore/derived-path-map\.cc$'' - ''^src/libstore/derived-path-map\.hh$'' + ''^src/libstore/include/nix/store/derived-path-map\.hh$'' ''^src/libstore/derived-path\.cc$'' - ''^src/libstore/derived-path\.hh$'' + ''^src/libstore/include/nix/store/derived-path\.hh$'' ''^src/libstore/downstream-placeholder\.cc$'' - ''^src/libstore/downstream-placeholder\.hh$'' + ''^src/libstore/include/nix/store/downstream-placeholder\.hh$'' ''^src/libstore/dummy-store\.cc$'' ''^src/libstore/export-import\.cc$'' ''^src/libstore/filetransfer\.cc$'' - ''^src/libstore/filetransfer\.hh$'' - ''^src/libstore/gc-store\.hh$'' + ''^src/libstore/include/nix/store/filetransfer\.hh$'' + ''^src/libstore/include/nix/store/gc-store\.hh$'' ''^src/libstore/globals\.cc$'' - ''^src/libstore/globals\.hh$'' + ''^src/libstore/include/nix/store/globals\.hh$'' ''^src/libstore/http-binary-cache-store\.cc$'' ''^src/libstore/legacy-ssh-store\.cc$'' - ''^src/libstore/legacy-ssh-store\.hh$'' - ''^src/libstore/length-prefixed-protocol-helper\.hh$'' + ''^src/libstore/include/nix/store/legacy-ssh-store\.hh$'' + ''^src/libstore/include/nix/store/length-prefixed-protocol-helper\.hh$'' ''^src/libstore/linux/personality\.cc$'' - ''^src/libstore/linux/personality\.hh$'' + ''^src/libstore/linux/include/nix/store/personality\.hh$'' ''^src/libstore/local-binary-cache-store\.cc$'' ''^src/libstore/local-fs-store\.cc$'' - ''^src/libstore/local-fs-store\.hh$'' + ''^src/libstore/include/nix/store/local-fs-store\.hh$'' ''^src/libstore/log-store\.cc$'' - ''^src/libstore/log-store\.hh$'' + ''^src/libstore/include/nix/store/log-store\.hh$'' ''^src/libstore/machines\.cc$'' - ''^src/libstore/machines\.hh$'' + ''^src/libstore/include/nix/store/machines\.hh$'' ''^src/libstore/make-content-addressed\.cc$'' - ''^src/libstore/make-content-addressed\.hh$'' + ''^src/libstore/include/nix/store/make-content-addressed\.hh$'' ''^src/libstore/misc\.cc$'' ''^src/libstore/names\.cc$'' - ''^src/libstore/names\.hh$'' + ''^src/libstore/include/nix/store/names\.hh$'' ''^src/libstore/nar-accessor\.cc$'' - ''^src/libstore/nar-accessor\.hh$'' + ''^src/libstore/include/nix/store/nar-accessor\.hh$'' ''^src/libstore/nar-info-disk-cache\.cc$'' - ''^src/libstore/nar-info-disk-cache\.hh$'' + ''^src/libstore/include/nix/store/nar-info-disk-cache\.hh$'' ''^src/libstore/nar-info\.cc$'' - ''^src/libstore/nar-info\.hh$'' + ''^src/libstore/include/nix/store/nar-info\.hh$'' ''^src/libstore/outputs-spec\.cc$'' - ''^src/libstore/outputs-spec\.hh$'' + ''^src/libstore/include/nix/store/outputs-spec\.hh$'' ''^src/libstore/parsed-derivations\.cc$'' ''^src/libstore/path-info\.cc$'' - ''^src/libstore/path-info\.hh$'' + ''^src/libstore/include/nix/store/path-info\.hh$'' ''^src/libstore/path-references\.cc$'' - ''^src/libstore/path-regex\.hh$'' + ''^src/libstore/include/nix/store/path-regex\.hh$'' ''^src/libstore/path-with-outputs\.cc$'' ''^src/libstore/path\.cc$'' - ''^src/libstore/path\.hh$'' + ''^src/libstore/include/nix/store/path\.hh$'' ''^src/libstore/pathlocks\.cc$'' - ''^src/libstore/pathlocks\.hh$'' + ''^src/libstore/include/nix/store/pathlocks\.hh$'' ''^src/libstore/profiles\.cc$'' - ''^src/libstore/profiles\.hh$'' + ''^src/libstore/include/nix/store/profiles\.hh$'' ''^src/libstore/realisation\.cc$'' - ''^src/libstore/realisation\.hh$'' + ''^src/libstore/include/nix/store/realisation\.hh$'' ''^src/libstore/remote-fs-accessor\.cc$'' - ''^src/libstore/remote-fs-accessor\.hh$'' - ''^src/libstore/remote-store-connection\.hh$'' + ''^src/libstore/include/nix/store/remote-fs-accessor\.hh$'' + ''^src/libstore/include/nix/store/remote-store-connection\.hh$'' ''^src/libstore/remote-store\.cc$'' - ''^src/libstore/remote-store\.hh$'' + ''^src/libstore/include/nix/store/remote-store\.hh$'' ''^src/libstore/s3-binary-cache-store\.cc$'' - ''^src/libstore/s3\.hh$'' + ''^src/libstore/include/nix/store/s3\.hh$'' ''^src/libstore/serve-protocol-impl\.cc$'' - ''^src/libstore/serve-protocol-impl\.hh$'' + ''^src/libstore/include/nix/store/serve-protocol-impl\.hh$'' ''^src/libstore/serve-protocol\.cc$'' - ''^src/libstore/serve-protocol\.hh$'' + ''^src/libstore/include/nix/store/serve-protocol\.hh$'' ''^src/libstore/sqlite\.cc$'' - ''^src/libstore/sqlite\.hh$'' + ''^src/libstore/include/nix/store/sqlite\.hh$'' ''^src/libstore/ssh-store\.cc$'' ''^src/libstore/ssh\.cc$'' - ''^src/libstore/ssh\.hh$'' + ''^src/libstore/include/nix/store/ssh\.hh$'' ''^src/libstore/store-api\.cc$'' - ''^src/libstore/store-api\.hh$'' - ''^src/libstore/store-dir-config\.hh$'' + ''^src/libstore/include/nix/store/store-api\.hh$'' + ''^src/libstore/include/nix/store/store-dir-config\.hh$'' ''^src/libstore/build/derivation-goal\.cc$'' - ''^src/libstore/build/derivation-goal\.hh$'' + ''^src/libstore/include/nix/store/build/derivation-goal\.hh$'' ''^src/libstore/build/drv-output-substitution-goal\.cc$'' - ''^src/libstore/build/drv-output-substitution-goal\.hh$'' + ''^src/libstore/include/nix/store/build/drv-output-substitution-goal\.hh$'' ''^src/libstore/build/entry-points\.cc$'' ''^src/libstore/build/goal\.cc$'' - ''^src/libstore/build/goal\.hh$'' + ''^src/libstore/include/nix/store/build/goal\.hh$'' ''^src/libstore/unix/build/hook-instance\.cc$'' ''^src/libstore/unix/build/local-derivation-goal\.cc$'' - ''^src/libstore/unix/build/local-derivation-goal\.hh$'' + ''^src/libstore/unix/include/nix/store/build/local-derivation-goal\.hh$'' ''^src/libstore/build/substitution-goal\.cc$'' - ''^src/libstore/build/substitution-goal\.hh$'' + ''^src/libstore/include/nix/store/build/substitution-goal\.hh$'' ''^src/libstore/build/worker\.cc$'' - ''^src/libstore/build/worker\.hh$'' + ''^src/libstore/include/nix/store/build/worker\.hh$'' ''^src/libstore/builtins/fetchurl\.cc$'' ''^src/libstore/builtins/unpack-channel\.cc$'' ''^src/libstore/gc\.cc$'' ''^src/libstore/local-overlay-store\.cc$'' - ''^src/libstore/local-overlay-store\.hh$'' + ''^src/libstore/include/nix/store/local-overlay-store\.hh$'' ''^src/libstore/local-store\.cc$'' - ''^src/libstore/local-store\.hh$'' + ''^src/libstore/include/nix/store/local-store\.hh$'' ''^src/libstore/unix/user-lock\.cc$'' - ''^src/libstore/unix/user-lock\.hh$'' + ''^src/libstore/unix/include/nix/store/user-lock\.hh$'' ''^src/libstore/optimise-store\.cc$'' ''^src/libstore/unix/pathlocks\.cc$'' ''^src/libstore/posix-fs-canonicalise\.cc$'' - ''^src/libstore/posix-fs-canonicalise\.hh$'' + ''^src/libstore/include/nix/store/posix-fs-canonicalise\.hh$'' ''^src/libstore/uds-remote-store\.cc$'' - ''^src/libstore/uds-remote-store\.hh$'' + ''^src/libstore/include/nix/store/uds-remote-store\.hh$'' ''^src/libstore/windows/build\.cc$'' - ''^src/libstore/worker-protocol-impl\.hh$'' + ''^src/libstore/include/nix/store/worker-protocol-impl\.hh$'' ''^src/libstore/worker-protocol\.cc$'' - ''^src/libstore/worker-protocol\.hh$'' + ''^src/libstore/include/nix/store/worker-protocol\.hh$'' ''^src/libutil-c/nix_api_util_internal\.h$'' ''^src/libutil/archive\.cc$'' - ''^src/libutil/archive\.hh$'' + ''^src/libutil/include/nix/util/archive\.hh$'' ''^src/libutil/args\.cc$'' - ''^src/libutil/args\.hh$'' - ''^src/libutil/args/root\.hh$'' - ''^src/libutil/callback\.hh$'' + ''^src/libutil/include/nix/util/args\.hh$'' + ''^src/libutil/include/nix/util/args/root\.hh$'' + ''^src/libutil/include/nix/util/callback\.hh$'' ''^src/libutil/canon-path\.cc$'' - ''^src/libutil/canon-path\.hh$'' - ''^src/libutil/chunked-vector\.hh$'' - ''^src/libutil/closure\.hh$'' - ''^src/libutil/comparator\.hh$'' + ''^src/libutil/include/nix/util/canon-path\.hh$'' + ''^src/libutil/include/nix/util/chunked-vector\.hh$'' + ''^src/libutil/include/nix/util/closure\.hh$'' + ''^src/libutil/include/nix/util/comparator\.hh$'' ''^src/libutil/compute-levels\.cc$'' - ''^src/libutil/config-impl\.hh$'' - ''^src/libutil/config\.cc$'' - ''^src/libutil/config\.hh$'' + ''^src/libutil/include/nix/util/config-impl\.hh$'' + ''^src/libutil/configuration\.cc$'' + ''^src/libutil/include/nix/util/configuration\.hh$'' ''^src/libutil/current-process\.cc$'' - ''^src/libutil/current-process\.hh$'' + ''^src/libutil/include/nix/util/current-process\.hh$'' ''^src/libutil/english\.cc$'' - ''^src/libutil/english\.hh$'' + ''^src/libutil/include/nix/util/english\.hh$'' ''^src/libutil/error\.cc$'' - ''^src/libutil/error\.hh$'' - ''^src/libutil/exit\.hh$'' + ''^src/libutil/include/nix/util/error\.hh$'' + ''^src/libutil/include/nix/util/exit\.hh$'' ''^src/libutil/experimental-features\.cc$'' - ''^src/libutil/experimental-features\.hh$'' + ''^src/libutil/include/nix/util/experimental-features\.hh$'' ''^src/libutil/file-content-address\.cc$'' - ''^src/libutil/file-content-address\.hh$'' + ''^src/libutil/include/nix/util/file-content-address\.hh$'' ''^src/libutil/file-descriptor\.cc$'' - ''^src/libutil/file-descriptor\.hh$'' - ''^src/libutil/file-path-impl\.hh$'' - ''^src/libutil/file-path\.hh$'' + ''^src/libutil/include/nix/util/file-descriptor\.hh$'' + ''^src/libutil/include/nix/util/file-path-impl\.hh$'' + ''^src/libutil/include/nix/util/file-path\.hh$'' ''^src/libutil/file-system\.cc$'' - ''^src/libutil/file-system\.hh$'' - ''^src/libutil/finally\.hh$'' - ''^src/libutil/fmt\.hh$'' + ''^src/libutil/include/nix/util/file-system\.hh$'' + ''^src/libutil/include/nix/util/finally\.hh$'' + ''^src/libutil/include/nix/util/fmt\.hh$'' ''^src/libutil/fs-sink\.cc$'' - ''^src/libutil/fs-sink\.hh$'' + ''^src/libutil/include/nix/util/fs-sink\.hh$'' ''^src/libutil/git\.cc$'' - ''^src/libutil/git\.hh$'' + ''^src/libutil/include/nix/util/git\.hh$'' ''^src/libutil/hash\.cc$'' - ''^src/libutil/hash\.hh$'' + ''^src/libutil/include/nix/util/hash\.hh$'' ''^src/libutil/hilite\.cc$'' - ''^src/libutil/hilite\.hh$'' + ''^src/libutil/include/nix/util/hilite\.hh$'' ''^src/libutil/source-accessor\.hh$'' - ''^src/libutil/json-impls\.hh$'' + ''^src/libutil/include/nix/util/json-impls\.hh$'' ''^src/libutil/json-utils\.cc$'' - ''^src/libutil/json-utils\.hh$'' + ''^src/libutil/include/nix/util/json-utils\.hh$'' ''^src/libutil/linux/cgroup\.cc$'' ''^src/libutil/linux/namespaces\.cc$'' ''^src/libutil/logging\.cc$'' - ''^src/libutil/logging\.hh$'' - ''^src/libutil/lru-cache\.hh$'' + ''^src/libutil/include/nix/util/logging\.hh$'' + ''^src/libutil/include/nix/util/lru-cache\.hh$'' ''^src/libutil/memory-source-accessor\.cc$'' - ''^src/libutil/memory-source-accessor\.hh$'' - ''^src/libutil/pool\.hh$'' + ''^src/libutil/include/nix/util/memory-source-accessor\.hh$'' + ''^src/libutil/include/nix/util/pool\.hh$'' ''^src/libutil/position\.cc$'' - ''^src/libutil/position\.hh$'' + ''^src/libutil/include/nix/util/position\.hh$'' ''^src/libutil/posix-source-accessor\.cc$'' - ''^src/libutil/posix-source-accessor\.hh$'' - ''^src/libutil/processes\.hh$'' - ''^src/libutil/ref\.hh$'' + ''^src/libutil/include/nix/util/posix-source-accessor\.hh$'' + ''^src/libutil/include/nix/util/processes\.hh$'' + ''^src/libutil/include/nix/util/ref\.hh$'' ''^src/libutil/references\.cc$'' - ''^src/libutil/references\.hh$'' + ''^src/libutil/include/nix/util/references\.hh$'' ''^src/libutil/regex-combinators\.hh$'' ''^src/libutil/serialise\.cc$'' - ''^src/libutil/serialise\.hh$'' - ''^src/libutil/signals\.hh$'' + ''^src/libutil/include/nix/util/serialise\.hh$'' + ''^src/libutil/include/nix/util/signals\.hh$'' ''^src/libutil/signature/local-keys\.cc$'' - ''^src/libutil/signature/local-keys\.hh$'' + ''^src/libutil/include/nix/util/signature/local-keys\.hh$'' ''^src/libutil/signature/signer\.cc$'' - ''^src/libutil/signature/signer\.hh$'' + ''^src/libutil/include/nix/util/signature/signer\.hh$'' ''^src/libutil/source-accessor\.cc$'' - ''^src/libutil/source-accessor\.hh$'' + ''^src/libutil/include/nix/util/source-accessor\.hh$'' ''^src/libutil/source-path\.cc$'' - ''^src/libutil/source-path\.hh$'' - ''^src/libutil/split\.hh$'' + ''^src/libutil/include/nix/util/source-path\.hh$'' + ''^src/libutil/include/nix/util/split\.hh$'' ''^src/libutil/suggestions\.cc$'' - ''^src/libutil/suggestions\.hh$'' - ''^src/libutil/sync\.hh$'' + ''^src/libutil/include/nix/util/suggestions\.hh$'' + ''^src/libutil/include/nix/util/sync\.hh$'' ''^src/libutil/terminal\.cc$'' - ''^src/libutil/terminal\.hh$'' + ''^src/libutil/include/nix/util/terminal\.hh$'' ''^src/libutil/thread-pool\.cc$'' - ''^src/libutil/thread-pool\.hh$'' - ''^src/libutil/topo-sort\.hh$'' - ''^src/libutil/types\.hh$'' + ''^src/libutil/include/nix/util/thread-pool\.hh$'' + ''^src/libutil/include/nix/util/topo-sort\.hh$'' + ''^src/libutil/include/nix/util/types\.hh$'' ''^src/libutil/unix/file-descriptor\.cc$'' ''^src/libutil/unix/file-path\.cc$'' ''^src/libutil/unix/processes\.cc$'' - ''^src/libutil/unix/signals-impl\.hh$'' + ''^src/libutil/unix/include/nix/util/signals-impl\.hh$'' ''^src/libutil/unix/signals\.cc$'' ''^src/libutil/unix-domain-socket\.cc$'' ''^src/libutil/unix/users\.cc$'' - ''^src/libutil/url-parts\.hh$'' + ''^src/libutil/include/nix/util/url-parts\.hh$'' ''^src/libutil/url\.cc$'' - ''^src/libutil/url\.hh$'' + ''^src/libutil/include/nix/util/url\.hh$'' ''^src/libutil/users\.cc$'' - ''^src/libutil/users\.hh$'' + ''^src/libutil/include/nix/util/users\.hh$'' ''^src/libutil/util\.cc$'' - ''^src/libutil/util\.hh$'' - ''^src/libutil/variant-wrapper\.hh$'' + ''^src/libutil/include/nix/util/util\.hh$'' + ''^src/libutil/include/nix/util/variant-wrapper\.hh$'' ''^src/libutil/widecharwidth/widechar_width\.h$'' # vendored source ''^src/libutil/windows/file-descriptor\.cc$'' ''^src/libutil/windows/file-path\.cc$'' ''^src/libutil/windows/processes\.cc$'' ''^src/libutil/windows/users\.cc$'' ''^src/libutil/windows/windows-error\.cc$'' - ''^src/libutil/windows/windows-error\.hh$'' + ''^src/libutil/windows/include/nix/util/windows-error\.hh$'' ''^src/libutil/xml-writer\.cc$'' - ''^src/libutil/xml-writer\.hh$'' + ''^src/libutil/include/nix/util/xml-writer\.hh$'' ''^src/nix-build/nix-build\.cc$'' ''^src/nix-channel/nix-channel\.cc$'' ''^src/nix-collect-garbage/nix-collect-garbage\.cc$'' @@ -481,9 +481,9 @@ ''^tests/nixos/ca-fd-leak/sender\.c'' ''^tests/nixos/ca-fd-leak/smuggler\.c'' ''^tests/nixos/user-sandboxing/attacker\.c'' - ''^src/libexpr-test-support/tests/libexpr\.hh'' + ''^src/libexpr-test-support/include/nix/expr/tests/libexpr\.hh'' ''^src/libexpr-test-support/tests/value/context\.cc'' - ''^src/libexpr-test-support/tests/value/context\.hh'' + ''^src/libexpr-test-support/include/nix/expr/tests/value/context\.hh'' ''^src/libexpr-tests/derived-path\.cc'' ''^src/libexpr-tests/error_traces\.cc'' ''^src/libexpr-tests/eval\.cc'' @@ -498,13 +498,13 @@ ''^src/libflake-tests/flakeref\.cc'' ''^src/libflake-tests/url-name\.cc'' ''^src/libstore-test-support/tests/derived-path\.cc'' - ''^src/libstore-test-support/tests/derived-path\.hh'' - ''^src/libstore-test-support/tests/nix_api_store\.hh'' + ''^src/libstore-test-support/include/nix/store/tests/derived-path\.hh'' + ''^src/libstore-test-support/include/nix/store/tests/nix_api_store\.hh'' ''^src/libstore-test-support/tests/outputs-spec\.cc'' - ''^src/libstore-test-support/tests/outputs-spec\.hh'' - ''^src/libstore-test-support/tests/path\.cc'' - ''^src/libstore-test-support/tests/path\.hh'' - ''^src/libstore-test-support/tests/protocol\.hh'' + ''^src/libstore-test-support/include/nix/store/tests/outputs-spec\.hh'' + ''^src/libstore-test-support/path\.cc'' + ''^src/libstore-test-support/include/nix/store/tests/path\.hh'' + ''^src/libstore-test-support/include/nix/store/tests/protocol\.hh'' ''^src/libstore-tests/common-protocol\.cc'' ''^src/libstore-tests/content-address\.cc'' ''^src/libstore-tests/derivation\.cc'' @@ -518,9 +518,9 @@ ''^src/libstore-tests/path\.cc'' ''^src/libstore-tests/serve-protocol\.cc'' ''^src/libstore-tests/worker-protocol\.cc'' - ''^src/libutil-test-support/tests/characterization\.hh'' - ''^src/libutil-test-support/tests/hash\.cc'' - ''^src/libutil-test-support/tests/hash\.hh'' + ''^src/libutil-test-support/include/nix/util/tests/characterization\.hh'' + ''^src/libutil-test-support/hash\.cc'' + ''^src/libutil-test-support/include/nix/util/tests/hash\.hh'' ''^src/libutil-tests/args\.cc'' ''^src/libutil-tests/canon-path\.cc'' ''^src/libutil-tests/chunked-vector\.cc'' diff --git a/maintainers/link-headers b/maintainers/link-headers new file mode 100755 index 000000000..2457a2dc8 --- /dev/null +++ b/maintainers/link-headers @@ -0,0 +1,83 @@ +#!/usr/bin/env python3 + +# This script must be run from the root of the Nix repository. +# +# For include path hygiene, we need to put headers in a separate +# directory than sources. But during development, it is nice to paths +# that are similar for headers and source files, e.g. +# `foo/bar/baz.{cc,hh}`, e.g. for less typing when opening one file, and +# then opening the other file. +# +# This script symlinks the headers next to the source files to +# facilitate such a development workflows. It also updates +# `.git/info/exclude` so that the symlinks are not accidentally committed +# by mistake. + +from pathlib import Path +import subprocess +import os + + +def main() -> None: + # Path to the source directory + GIT_TOPLEVEL = Path( + subprocess.run( + ["git", "rev-parse", "--show-toplevel"], + text=True, + stdout=subprocess.PIPE, + check=True, + ).stdout.strip() + ) + + # Get header files from git + result = subprocess.run( + ["git", "-C", str(GIT_TOPLEVEL), "ls-files", "*/include/nix/**.hh"], + text=True, + stdout=subprocess.PIPE, + check=True, + ) + header_files = result.stdout.strip().split("\n") + header_files.sort() + + links = [] + for file_str in header_files: + project_str, header_str = file_str.split("/include/nix/", 1) + project = Path(project_str) + header = Path(header_str) + + # Reconstruct the full path (relative to SRC_DIR) to the header file. + file = project / "include" / "nix" / header + + # The symlink should be created at "project/header", i.e. next to the project's sources. + link = project / header + + # Compute a relative path from the symlink's parent directory to the actual header file. + relative_source = os.path.relpath( + GIT_TOPLEVEL / file, GIT_TOPLEVEL / link.parent + ) + + # Create the symbolic link. + full_link_path = GIT_TOPLEVEL / link + full_link_path.parent.mkdir(parents=True, exist_ok=True) + if full_link_path.is_symlink(): + full_link_path.unlink() + full_link_path.symlink_to(relative_source) + links.append(link) + + # Generate .gitignore file + gitignore_path = GIT_TOPLEVEL / ".git" / "info" / "exclude" + gitignore_path.parent.mkdir(parents=True, exist_ok=True) + with gitignore_path.open("w") as gitignore: + gitignore.write("# DO NOT EDIT! Autogenerated\n") + gitignore.write( + "# Symlinks for headers to be next to sources for development\n" + ) + gitignore.write('# Run "maintainers/link-headers" to regenerate\n\n') + gitignore.write('# Run "maintainers/link-headers" to regenerate\n\n') + + for link in links: + gitignore.write(f"/{link}\n") + + +if __name__ == "__main__": + main() diff --git a/maintainers/release-credits b/maintainers/release-credits index 7a5c87d7d..10ffd48b5 100755 --- a/maintainers/release-credits +++ b/maintainers/release-credits @@ -109,15 +109,15 @@ for sample in samples: s = samples[sample] email = s["email"] if not email in email_to_handle_cache.values: - print(f"Querying GitHub API for {s['hash']}, to get handle for {s['email']}") + print(f"Querying GitHub API for {s['hash']}, to get handle for {s['email']}", file=sys.stderr) ghc = get_github_commit(samples[sample]) gha = ghc["author"] if gha and gha["login"]: handle = gha["login"] - print(f"Handle: {handle}") + print(f"Handle: {handle}", file=sys.stderr) email_to_handle_cache.values[email] = handle else: - print(f"Found no handle for {s['email']}") + print(f"Found no handle for {s['email']}", file=sys.stderr) email_to_handle_cache.values[email] = None handle = email_to_handle_cache.values[email] if handle is not None: diff --git a/nix-meson-build-support/common/meson.build b/nix-meson-build-support/common/meson.build index 67b6658f5..9d77831b3 100644 --- a/nix-meson-build-support/common/meson.build +++ b/nix-meson-build-support/common/meson.build @@ -10,6 +10,7 @@ add_project_arguments( '-Werror=suggest-override', '-Werror=switch', '-Werror=switch-enum', + '-Werror=undef', '-Werror=unused-result', '-Wignored-qualifiers', '-Wimplicit-fallthrough', diff --git a/nix-meson-build-support/export/meson.build b/nix-meson-build-support/export/meson.build index 9f5950572..b2409de85 100644 --- a/nix-meson-build-support/export/meson.build +++ b/nix-meson-build-support/export/meson.build @@ -16,7 +16,6 @@ import('pkgconfig').generate( filebase : meson.project_name(), name : 'Nix', description : 'Nix Package Manager', - subdirs : ['nix'], extra_cflags : ['-std=c++2a'], requires : requires_public, requires_private : requires_private, diff --git a/packaging/components.nix b/packaging/components.nix index 04b143bfe..c9886aa41 100644 --- a/packaging/components.nix +++ b/packaging/components.nix @@ -3,6 +3,7 @@ pkgs, src, officialRelease, + maintainers, }: scope: @@ -101,7 +102,7 @@ let let n = lib.length finalScope.patches; in - if n == 0 then finalAttrs.version else finalAttrs.version + "+${toString n}"; + if n == 0 then prevAttrs.version else prevAttrs.version + "+${toString n}"; # Clear what `derivation` can't/shouldn't serialize; see prevAttrs.workDir. fileset = null; @@ -171,9 +172,24 @@ let mesonFlags = [ (lib.mesonBool "b_asneeded" false) ] ++ prevAttrs.mesonFlags or [ ]; }; - miscGoodPractice = finalAttrs: prevAttrs: { + nixDefaultsLayer = finalAttrs: prevAttrs: { strictDeps = prevAttrs.strictDeps or true; enableParallelBuilding = true; + pos = builtins.unsafeGetAttrPos "pname" prevAttrs; + meta = prevAttrs.meta or { } // { + homepage = prevAttrs.meta.homepage or "https://nixos.org/nix"; + longDescription = + prevAttrs.longDescription or '' + Nix is a powerful package manager for mainly Linux and other Unix systems that + makes package management reliable and reproducible. It provides atomic + upgrades and rollbacks, side-by-side installation of multiple versions of + a package, multi-user package management and easy setup of build + environments. + ''; + license = prevAttrs.meta.license or lib.licenses.lgpl21Plus; + maintainers = prevAttrs.meta.maintainers or [ ] ++ scope.maintainers; + platforms = prevAttrs.meta.platforms or (lib.platforms.unix ++ lib.platforms.windows); + }; }; /** @@ -193,6 +209,7 @@ in { version = baseVersion + versionSuffix; inherit versionSuffix; + inherit maintainers; inherit filesetToSource; @@ -228,6 +245,10 @@ in but it does make the build non-granular; all components will use a complete source. Packaging expressions will be ignored. + + Single argument: the source to use. + + See also `appendPatches` */ overrideSource = src: @@ -256,6 +277,7 @@ in } ); resolvePath = p: finalScope.patchedSrc + "/${resolveRelPath p}"; + filesetToSource = { root, fileset }: finalScope.resolvePath root; appendPatches = appendPatches finalScope; } ); @@ -272,14 +294,14 @@ in (scope.overrideSource "${./..}").appendPatches patches; mkMesonDerivation = mkPackageBuilder [ - miscGoodPractice + nixDefaultsLayer scope.sourceLayer setVersionLayer mesonLayer scope.mesonComponentOverrides ]; mkMesonExecutable = mkPackageBuilder [ - miscGoodPractice + nixDefaultsLayer bsdNoLinkAsNeeded scope.sourceLayer setVersionLayer @@ -288,7 +310,7 @@ in scope.mesonComponentOverrides ]; mkMesonLibrary = mkPackageBuilder [ - miscGoodPractice + nixDefaultsLayer bsdNoLinkAsNeeded scope.sourceLayer mesonLayer @@ -338,7 +360,7 @@ in nix-perl-bindings = callPackage ../src/perl/package.nix { }; nix-everything = callPackage ../packaging/everything.nix { } // { - # Note: no `passthru.overrideAllMesonComponents` + # Note: no `passthru.overrideAllMesonComponents` etc # This would propagate into `nix.overrideAttrs f`, but then discard # `f` when `.overrideAllMesonComponents` is used. # Both "methods" should be views on the same fixpoint overriding mechanism @@ -346,6 +368,8 @@ in # two-fixpoint solution. /** Apply an extension function (i.e. overlay-shaped) to all component derivations, and return the nix package. + + Single argument: the extension function to apply (finalAttrs: prevAttrs: { ... }) */ overrideAllMesonComponents = f: (scope.overrideAllMesonComponents f).nix-everything; @@ -354,6 +378,10 @@ in This affects all components. Changes to the packaging expressions will be ignored. + + Single argument: list of patches to apply + + See also `overrideSource` */ appendPatches = ps: (scope.appendPatches ps).nix-everything; @@ -362,8 +390,26 @@ in but it does make the build non-granular; all components will use a complete source. Packaging expressions will be ignored. + + Filesets in the packaging expressions will be ignored. + + Single argument: the source to use. + + See also `appendPatches` */ overrideSource = src: (scope.overrideSource src).nix-everything; + /** + Override any internals of the Nix package set. + + Single argument: the extension function to apply to the package set (finalScope: prevScope: { ... }) + + Example: + ``` + overrideScope (finalScope: prevScope: { aws-sdk-cpp = null; }) + ``` + */ + overrideScope = f: (scope.overrideScope f).nix-everything; + }; } diff --git a/packaging/dependencies.nix b/packaging/dependencies.nix index 535b3ff37..ed05843c7 100644 --- a/packaging/dependencies.nix +++ b/packaging/dependencies.nix @@ -26,6 +26,9 @@ let # Despite the use of the 10.13 deployment target here, the aligned # allocation function Clang uses with this setting actually works # all the way back to 10.6. + # NOTE: this is not just a version constraint, but a request to make Darwin + # provide this version level of support. Removing this minimum version + # request will regress the above error. darwinStdenv = pkgs.overrideSDK prevStdenv { darwinMinVersion = "10.13"; }; in @@ -65,39 +68,37 @@ scope: { installPhase = lib.replaceStrings [ "--without-python" ] [ "" ] old.installPhase; }); - libgit2 = pkgs.libgit2.overrideAttrs ( - attrs: - { - cmakeFlags = attrs.cmakeFlags or [ ] ++ [ "-DUSE_SSH=exec" ]; - } - # libgit2: Nixpkgs 24.11 has < 1.9.0, which needs our patches - // lib.optionalAttrs (!lib.versionAtLeast pkgs.libgit2.version "1.9.0") { - nativeBuildInputs = - attrs.nativeBuildInputs or [ ] - # gitMinimal does not build on Windows. See packbuilder patch. - ++ lib.optionals (!stdenv.hostPlatform.isWindows) [ - # Needed for `git apply`; see `prePatch` - pkgs.buildPackages.gitMinimal - ]; - # Only `git apply` can handle git binary patches - prePatch = - attrs.prePatch or "" - + lib.optionalString (!stdenv.hostPlatform.isWindows) '' - patch() { - git apply - } - ''; - patches = - attrs.patches or [ ] - ++ [ - ./patches/libgit2-mempack-thin-packfile.patch - ] - # gitMinimal does not build on Windows, but fortunately this patch only - # impacts interruptibility - ++ lib.optionals (!stdenv.hostPlatform.isWindows) [ - # binary patch; see `prePatch` - ./patches/libgit2-packbuilder-callback-interruptible.patch - ]; - } - ); + libgit2 = + if lib.versionAtLeast pkgs.libgit2.version "1.9.0" then + pkgs.libgit2 + else + pkgs.libgit2.overrideAttrs (attrs: { + # libgit2: Nixpkgs 24.11 has < 1.9.0, which needs our patches + nativeBuildInputs = + attrs.nativeBuildInputs or [ ] + # gitMinimal does not build on Windows. See packbuilder patch. + ++ lib.optionals (!stdenv.hostPlatform.isWindows) [ + # Needed for `git apply`; see `prePatch` + pkgs.buildPackages.gitMinimal + ]; + # Only `git apply` can handle git binary patches + prePatch = + attrs.prePatch or "" + + lib.optionalString (!stdenv.hostPlatform.isWindows) '' + patch() { + git apply + } + ''; + patches = + attrs.patches or [ ] + ++ [ + ./patches/libgit2-mempack-thin-packfile.patch + ] + # gitMinimal does not build on Windows, but fortunately this patch only + # impacts interruptibility + ++ lib.optionals (!stdenv.hostPlatform.isWindows) [ + # binary patch; see `prePatch` + ./patches/libgit2-packbuilder-callback-interruptible.patch + ]; + }); } diff --git a/packaging/dev-shell.nix b/packaging/dev-shell.nix index 6f06bc2d8..21b2b4723 100644 --- a/packaging/dev-shell.nix +++ b/packaging/dev-shell.nix @@ -72,10 +72,6 @@ pkgs.nixComponents.nix-util.overrideAttrs ( src = null; env = { - # Needed for Meson to find Boost. - # https://github.com/NixOS/nixpkgs/issues/86131. - BOOST_INCLUDEDIR = "${lib.getDev pkgs.nixDependencies.boost}/include"; - BOOST_LIBRARYDIR = "${lib.getLib pkgs.nixDependencies.boost}/lib"; # For `make format`, to work without installing pre-commit _NIX_PRE_COMMIT_HOOKS_CONFIG = "${(pkgs.formats.yaml { }).generate "pre-commit-config.yaml" modular.pre-commit.settings.rawConfig diff --git a/packaging/everything.nix b/packaging/everything.nix index 8dab8c67c..f11b29163 100644 --- a/packaging/everything.nix +++ b/packaging/everything.nix @@ -4,6 +4,8 @@ lndir, buildEnv, + maintainers, + nix-util, nix-util-c, nix-util-tests, @@ -39,6 +41,8 @@ nix-perl-bindings, testers, + + patchedSrc ? null, }: let @@ -68,50 +72,8 @@ let ; }; - dev = stdenv.mkDerivation (finalAttrs: { - name = "determinate-nix-${nix-cli.version}-dev"; - pname = "nix"; - version = nix-cli.version; - dontUnpack = true; - dontBuild = true; - libs = map lib.getDev (lib.attrValues libs); - installPhase = '' - mkdir -p $out/nix-support - echo $libs >> $out/nix-support/propagated-build-inputs - ''; - passthru = { - tests = { - pkg-config = testers.hasPkgConfigModules { - package = finalAttrs.finalPackage; - }; - }; - - # If we were to fully emulate output selection here, we'd confuse the Nix CLIs, - # because they rely on `drvPath`. - dev = finalAttrs.finalPackage.out; - - libs = throw "`nix.dev.libs` is not meant to be used; use `nix.libs` instead."; - }; - meta = { - mainProgram = "nix"; - pkgConfigModules = [ - "nix-cmd" - "nix-expr" - "nix-expr-c" - "nix-fetchers" - "nix-flake" - "nix-flake-c" - "nix-main" - "nix-main-c" - "nix-store" - "nix-store-c" - "nix-util" - "nix-util-c" - ]; - }; - }); devdoc = buildEnv { - name = "nix-${nix-cli.version}-devdoc"; + name = "determinate-nix-${nix-cli.version}-devdoc"; paths = [ nix-internal-api-docs nix-external-api-docs @@ -192,10 +154,15 @@ stdenv.mkDerivation (finalAttrs: { devPaths = lib.mapAttrsToList (_k: lib.getDev) finalAttrs.finalPackage.libs; in '' - mkdir -p $out $dev + mkdir -p $out $dev/nix-support + + # Custom files + echo $libs >> $dev/nix-support/propagated-build-inputs + echo ${nix-cli} ${lib.escapeShellArgs devPaths} >> $dev/nix-support/propagated-build-inputs # Merged outputs lndir ${nix-cli} $out + for lib in ${lib.escapeShellArgs devPaths}; do lndir $lib $dev done @@ -207,6 +174,7 @@ stdenv.mkDerivation (finalAttrs: { passthru = { inherit (nix-cli) version; + src = patchedSrc; /** These are the libraries that are part of the Nix project. They are used @@ -248,7 +216,29 @@ stdenv.mkDerivation (finalAttrs: { meta = { mainProgram = "nix"; description = "The Nix package manager"; - pkgConfigModules = dev.meta.pkgConfigModules; + longDescription = nix-cli.meta.longDescription; + homepage = nix-cli.meta.homepage; + license = nix-cli.meta.license; + maintainers = maintainers; + platforms = nix-cli.meta.platforms; + outputsToInstall = [ + "out" + "man" + ]; + pkgConfigModules = [ + "nix-cmd" + "nix-expr" + "nix-expr-c" + "nix-fetchers" + "nix-flake" + "nix-flake-c" + "nix-main" + "nix-main-c" + "nix-store" + "nix-store-c" + "nix-util" + "nix-util-c" + ]; }; }) diff --git a/packaging/hydra.nix b/packaging/hydra.nix index 243e61165..141c8af04 100644 --- a/packaging/hydra.nix +++ b/packaging/hydra.nix @@ -29,32 +29,86 @@ let # Technically we could just return `pkgs.nixComponents`, but for Hydra it's # convention to transpose it, and to transpose it efficiently, we need to # enumerate them manually, so that we don't evaluate unnecessary package sets. - forAllPackages = lib.genAttrs [ - "nix-everything" - "nix-util" - "nix-util-c" - "nix-util-test-support" - "nix-util-tests" - "nix-store" - "nix-store-c" - "nix-store-test-support" - "nix-store-tests" - "nix-fetchers" - "nix-fetchers-tests" - "nix-expr" - "nix-expr-c" - "nix-expr-test-support" - "nix-expr-tests" - "nix-flake" - "nix-flake-tests" - "nix-main" - "nix-main-c" - "nix-cmd" - "nix-cli" - "nix-functional-tests" - ]; + # See listingIsComplete below. + forAllPackages = forAllPackages' { }; + forAllPackages' = + { + enableBindings ? false, + enableDocs ? false, # already have separate attrs for these + }: + lib.genAttrs ( + [ + "nix-everything" + "nix-util" + "nix-util-c" + "nix-util-test-support" + "nix-util-tests" + "nix-store" + "nix-store-c" + "nix-store-test-support" + "nix-store-tests" + "nix-fetchers" + "nix-fetchers-tests" + "nix-expr" + "nix-expr-c" + "nix-expr-test-support" + "nix-expr-tests" + "nix-flake" + "nix-flake-c" + "nix-flake-tests" + "nix-main" + "nix-main-c" + "nix-cmd" + "nix-cli" + "nix-functional-tests" + ] + ++ lib.optionals enableBindings [ + "nix-perl-bindings" + ] + ++ lib.optionals enableDocs [ + "nix-manual" + "nix-internal-api-docs" + "nix-external-api-docs" + ] + ); in { + /** + An internal check to make sure our package listing is complete. + */ + listingIsComplete = + let + arbitrarySystem = "x86_64-linux"; + listedPkgs = forAllPackages' { + enableBindings = true; + enableDocs = true; + } (_: null); + actualPkgs = lib.concatMapAttrs ( + k: v: if lib.strings.hasPrefix "nix-" k then { ${k} = null; } else { } + ) nixpkgsFor.${arbitrarySystem}.native.nixComponents; + diff = lib.concatStringsSep "\n" ( + lib.concatLists ( + lib.mapAttrsToList ( + k: _: + if (listedPkgs ? ${k}) && !(actualPkgs ? ${k}) then + [ "- ${k}: redundant?" ] + else if !(listedPkgs ? ${k}) && (actualPkgs ? ${k}) then + [ "- ${k}: missing?" ] + else + [ ] + ) (listedPkgs // actualPkgs) + ) + ); + in + if listedPkgs == actualPkgs then + { } + else + throw '' + Please update the components list in hydra.nix (or fix this check) + Differences: + ${diff} + ''; + # Binary package for various platforms. build = forAllPackages ( pkgName: forAllSystems (system: nixpkgsFor.${system}.native.nixComponents.${pkgName}) diff --git a/scripts/nix-profile-daemon.sh.in b/scripts/nix-profile-daemon.sh.in index 59c00d491..ed74c242a 100644 --- a/scripts/nix-profile-daemon.sh.in +++ b/scripts/nix-profile-daemon.sh.in @@ -1,7 +1,7 @@ # Only execute this file once per shell. # This file is tested by tests/installer/default.nix. if [ -n "${__ETC_PROFILE_NIX_SOURCED:-}" ]; then return; fi -__ETC_PROFILE_NIX_SOURCED=1 +export __ETC_PROFILE_NIX_SOURCED=1 NIX_LINK=$HOME/.nix-profile if [ -n "${XDG_STATE_HOME-}" ]; then diff --git a/src/build-remote/build-remote.cc b/src/build-remote/build-remote.cc index 88b704288..60247b735 100644 --- a/src/build-remote/build-remote.cc +++ b/src/build-remote/build-remote.cc @@ -5,23 +5,23 @@ #include #include #include -#if __APPLE__ +#ifdef __APPLE__ #include #endif -#include "machines.hh" -#include "shared.hh" -#include "plugin.hh" -#include "pathlocks.hh" -#include "globals.hh" -#include "serialise.hh" -#include "build-result.hh" -#include "store-api.hh" -#include "strings.hh" -#include "derivations.hh" -#include "local-store.hh" -#include "legacy.hh" -#include "experimental-features.hh" +#include "nix/store/machines.hh" +#include "nix/main/shared.hh" +#include "nix/main/plugin.hh" +#include "nix/store/pathlocks.hh" +#include "nix/store/globals.hh" +#include "nix/util/serialise.hh" +#include "nix/store/build-result.hh" +#include "nix/store/store-api.hh" +#include "nix/util/strings.hh" +#include "nix/store/derivations.hh" +#include "nix/store/local-store.hh" +#include "nix/cmd/legacy.hh" +#include "nix/util/experimental-features.hh" using namespace nix; using std::cin; @@ -225,7 +225,7 @@ static int main_build_remote(int argc, char * * argv) break; } -#if __APPLE__ +#ifdef __APPLE__ futimes(bestSlotLock.get(), NULL); #else futimens(bestSlotLock.get(), NULL); diff --git a/src/libcmd/built-path.cc b/src/libcmd/built-path.cc index 905e70f32..1238f9422 100644 --- a/src/libcmd/built-path.cc +++ b/src/libcmd/built-path.cc @@ -1,7 +1,7 @@ -#include "built-path.hh" -#include "derivations.hh" -#include "store-api.hh" -#include "comparator.hh" +#include "nix/cmd/built-path.hh" +#include "nix/store/derivations.hh" +#include "nix/store/store-api.hh" +#include "nix/util/comparator.hh" #include diff --git a/src/libcmd/command-installable-value.cc b/src/libcmd/command-installable-value.cc index 7e0c15eb8..0884f17e9 100644 --- a/src/libcmd/command-installable-value.cc +++ b/src/libcmd/command-installable-value.cc @@ -1,4 +1,4 @@ -#include "command-installable-value.hh" +#include "nix/cmd/command-installable-value.hh" namespace nix { diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc index 86d13fab7..565f424dd 100644 --- a/src/libcmd/command.cc +++ b/src/libcmd/command.cc @@ -1,16 +1,16 @@ #include #include -#include "command.hh" -#include "markdown.hh" -#include "store-api.hh" -#include "local-fs-store.hh" -#include "derivations.hh" -#include "nixexpr.hh" -#include "profiles.hh" -#include "repl.hh" -#include "strings.hh" -#include "environment-variables.hh" +#include "nix/cmd/command.hh" +#include "nix/cmd/markdown.hh" +#include "nix/store/store-api.hh" +#include "nix/store/local-fs-store.hh" +#include "nix/store/derivations.hh" +#include "nix/expr/nixexpr.hh" +#include "nix/store/profiles.hh" +#include "nix/cmd/repl.hh" +#include "nix/util/strings.hh" +#include "nix/util/environment-variables.hh" namespace nix { diff --git a/src/libcmd/common-eval-args.cc b/src/libcmd/common-eval-args.cc index da460c49b..bd8e3945b 100644 --- a/src/libcmd/common-eval-args.cc +++ b/src/libcmd/common-eval-args.cc @@ -1,20 +1,20 @@ -#include "fetch-settings.hh" -#include "eval-settings.hh" -#include "common-eval-args.hh" -#include "shared.hh" -#include "config-global.hh" -#include "filetransfer.hh" -#include "eval.hh" -#include "fetchers.hh" -#include "registry.hh" -#include "flake/flakeref.hh" -#include "flake/settings.hh" -#include "store-api.hh" -#include "command.hh" -#include "tarball.hh" -#include "fetch-to-store.hh" -#include "compatibility-settings.hh" -#include "eval-settings.hh" +#include "nix/fetchers/fetch-settings.hh" +#include "nix/expr/eval-settings.hh" +#include "nix/cmd/common-eval-args.hh" +#include "nix/main/shared.hh" +#include "nix/util/config-global.hh" +#include "nix/store/filetransfer.hh" +#include "nix/expr/eval.hh" +#include "nix/fetchers/fetchers.hh" +#include "nix/fetchers/registry.hh" +#include "nix/flake/flakeref.hh" +#include "nix/flake/settings.hh" +#include "nix/store/store-api.hh" +#include "nix/cmd/command.hh" +#include "nix/fetchers/tarball.hh" +#include "nix/fetchers/fetch-to-store.hh" +#include "nix/cmd/compatibility-settings.hh" +#include "nix/expr/eval-settings.hh" namespace nix { diff --git a/src/libcmd/editor-for.cc b/src/libcmd/editor-for.cc index 6bf36bd64..a5d635859 100644 --- a/src/libcmd/editor-for.cc +++ b/src/libcmd/editor-for.cc @@ -1,6 +1,6 @@ -#include "editor-for.hh" -#include "environment-variables.hh" -#include "source-path.hh" +#include "nix/cmd/editor-for.hh" +#include "nix/util/environment-variables.hh" +#include "nix/util/source-path.hh" namespace nix { diff --git a/src/libcmd/built-path.hh b/src/libcmd/include/nix/cmd/built-path.hh similarity index 97% rename from src/libcmd/built-path.hh rename to src/libcmd/include/nix/cmd/built-path.hh index dc78d3e59..c885876a7 100644 --- a/src/libcmd/built-path.hh +++ b/src/libcmd/include/nix/cmd/built-path.hh @@ -1,8 +1,8 @@ #pragma once ///@file -#include "derived-path.hh" -#include "realisation.hh" +#include "nix/store/derived-path.hh" +#include "nix/store/realisation.hh" namespace nix { diff --git a/src/libcmd/command-installable-value.hh b/src/libcmd/include/nix/cmd/command-installable-value.hh similarity index 85% rename from src/libcmd/command-installable-value.hh rename to src/libcmd/include/nix/cmd/command-installable-value.hh index 7880d4119..b171d9f73 100644 --- a/src/libcmd/command-installable-value.hh +++ b/src/libcmd/include/nix/cmd/command-installable-value.hh @@ -1,8 +1,8 @@ #pragma once ///@file -#include "installable-value.hh" -#include "command.hh" +#include "nix/cmd/installable-value.hh" +#include "nix/cmd/command.hh" namespace nix { diff --git a/src/libcmd/command.hh b/src/libcmd/include/nix/cmd/command.hh similarity index 98% rename from src/libcmd/command.hh rename to src/libcmd/include/nix/cmd/command.hh index 9570ce3e7..6b6418f51 100644 --- a/src/libcmd/command.hh +++ b/src/libcmd/include/nix/cmd/command.hh @@ -1,11 +1,11 @@ #pragma once ///@file -#include "installable-value.hh" -#include "args.hh" -#include "common-eval-args.hh" -#include "path.hh" -#include "flake/lockfile.hh" +#include "nix/cmd/installable-value.hh" +#include "nix/util/args.hh" +#include "nix/cmd/common-eval-args.hh" +#include "nix/store/path.hh" +#include "nix/flake/lockfile.hh" #include diff --git a/src/libcmd/common-eval-args.hh b/src/libcmd/include/nix/cmd/common-eval-args.hh similarity index 91% rename from src/libcmd/common-eval-args.hh rename to src/libcmd/include/nix/cmd/common-eval-args.hh index c62365b32..6f3367e58 100644 --- a/src/libcmd/common-eval-args.hh +++ b/src/libcmd/include/nix/cmd/common-eval-args.hh @@ -1,10 +1,10 @@ #pragma once ///@file -#include "args.hh" -#include "canon-path.hh" -#include "common-args.hh" -#include "search-path.hh" +#include "nix/util/args.hh" +#include "nix/util/canon-path.hh" +#include "nix/main/common-args.hh" +#include "nix/expr/search-path.hh" #include diff --git a/src/libcmd/compatibility-settings.hh b/src/libcmd/include/nix/cmd/compatibility-settings.hh similarity index 97% rename from src/libcmd/compatibility-settings.hh rename to src/libcmd/include/nix/cmd/compatibility-settings.hh index a129a957a..c7061a0a1 100644 --- a/src/libcmd/compatibility-settings.hh +++ b/src/libcmd/include/nix/cmd/compatibility-settings.hh @@ -1,5 +1,5 @@ #pragma once -#include "config.hh" +#include "nix/util/configuration.hh" namespace nix { struct CompatibilitySettings : public Config diff --git a/src/libcmd/editor-for.hh b/src/libcmd/include/nix/cmd/editor-for.hh similarity index 74% rename from src/libcmd/editor-for.hh rename to src/libcmd/include/nix/cmd/editor-for.hh index 8acd7011e..11414e823 100644 --- a/src/libcmd/editor-for.hh +++ b/src/libcmd/include/nix/cmd/editor-for.hh @@ -1,8 +1,8 @@ #pragma once ///@file -#include "types.hh" -#include "source-path.hh" +#include "nix/util/types.hh" +#include "nix/util/source-path.hh" namespace nix { diff --git a/src/libcmd/installable-attr-path.hh b/src/libcmd/include/nix/cmd/installable-attr-path.hh similarity index 61% rename from src/libcmd/installable-attr-path.hh rename to src/libcmd/include/nix/cmd/installable-attr-path.hh index 86c2f8219..5a0dc993c 100644 --- a/src/libcmd/installable-attr-path.hh +++ b/src/libcmd/include/nix/cmd/installable-attr-path.hh @@ -1,22 +1,22 @@ #pragma once ///@file -#include "globals.hh" -#include "installable-value.hh" -#include "outputs-spec.hh" -#include "command.hh" -#include "attr-path.hh" -#include "common-eval-args.hh" -#include "derivations.hh" -#include "eval-inline.hh" -#include "eval.hh" -#include "get-drvs.hh" -#include "store-api.hh" -#include "shared.hh" -#include "eval-cache.hh" -#include "url.hh" -#include "registry.hh" -#include "build-result.hh" +#include "nix/store/globals.hh" +#include "nix/cmd/installable-value.hh" +#include "nix/store/outputs-spec.hh" +#include "nix/cmd/command.hh" +#include "nix/expr/attr-path.hh" +#include "nix/cmd/common-eval-args.hh" +#include "nix/store/derivations.hh" +#include "nix/expr/eval-inline.hh" +#include "nix/expr/eval.hh" +#include "nix/expr/get-drvs.hh" +#include "nix/store/store-api.hh" +#include "nix/main/shared.hh" +#include "nix/expr/eval-cache.hh" +#include "nix/util/url.hh" +#include "nix/fetchers/registry.hh" +#include "nix/store/build-result.hh" #include #include diff --git a/src/libcmd/installable-derived-path.hh b/src/libcmd/include/nix/cmd/installable-derived-path.hh similarity index 94% rename from src/libcmd/installable-derived-path.hh rename to src/libcmd/include/nix/cmd/installable-derived-path.hh index e0b4f18b3..daa6ba868 100644 --- a/src/libcmd/installable-derived-path.hh +++ b/src/libcmd/include/nix/cmd/installable-derived-path.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "installables.hh" +#include "nix/cmd/installables.hh" namespace nix { diff --git a/src/libcmd/installable-flake.hh b/src/libcmd/include/nix/cmd/installable-flake.hh similarity index 96% rename from src/libcmd/installable-flake.hh rename to src/libcmd/include/nix/cmd/installable-flake.hh index 212403dd4..8699031b5 100644 --- a/src/libcmd/installable-flake.hh +++ b/src/libcmd/include/nix/cmd/installable-flake.hh @@ -1,8 +1,8 @@ #pragma once ///@file -#include "common-eval-args.hh" -#include "installable-value.hh" +#include "nix/cmd/common-eval-args.hh" +#include "nix/cmd/installable-value.hh" namespace nix { diff --git a/src/libcmd/installable-value.hh b/src/libcmd/include/nix/cmd/installable-value.hh similarity index 98% rename from src/libcmd/installable-value.hh rename to src/libcmd/include/nix/cmd/installable-value.hh index 4b6dbd306..9c8f1a9fb 100644 --- a/src/libcmd/installable-value.hh +++ b/src/libcmd/include/nix/cmd/installable-value.hh @@ -1,8 +1,8 @@ #pragma once ///@file -#include "installables.hh" -#include "flake/flake.hh" +#include "nix/cmd/installables.hh" +#include "nix/flake/flake.hh" namespace nix { diff --git a/src/libcmd/installables.hh b/src/libcmd/include/nix/cmd/installables.hh similarity index 95% rename from src/libcmd/installables.hh rename to src/libcmd/include/nix/cmd/installables.hh index c995c3019..84941278a 100644 --- a/src/libcmd/installables.hh +++ b/src/libcmd/include/nix/cmd/installables.hh @@ -1,12 +1,12 @@ #pragma once ///@file -#include "path.hh" -#include "outputs-spec.hh" -#include "derived-path.hh" -#include "built-path.hh" -#include "store-api.hh" -#include "build-result.hh" +#include "nix/store/path.hh" +#include "nix/store/outputs-spec.hh" +#include "nix/store/derived-path.hh" +#include "nix/cmd/built-path.hh" +#include "nix/store/store-api.hh" +#include "nix/store/build-result.hh" #include diff --git a/src/libcmd/legacy.hh b/src/libcmd/include/nix/cmd/legacy.hh similarity index 100% rename from src/libcmd/legacy.hh rename to src/libcmd/include/nix/cmd/legacy.hh diff --git a/src/libcmd/markdown.hh b/src/libcmd/include/nix/cmd/markdown.hh similarity index 100% rename from src/libcmd/markdown.hh rename to src/libcmd/include/nix/cmd/markdown.hh diff --git a/src/libcmd/include/nix/cmd/meson.build b/src/libcmd/include/nix/cmd/meson.build new file mode 100644 index 000000000..368edb28e --- /dev/null +++ b/src/libcmd/include/nix/cmd/meson.build @@ -0,0 +1,23 @@ +# Public headers directory + +include_dirs = [include_directories('../..')] + +headers = files( + 'built-path.hh', + 'command-installable-value.hh', + 'command.hh', + 'common-eval-args.hh', + 'compatibility-settings.hh', + 'editor-for.hh', + 'installable-attr-path.hh', + 'installable-derived-path.hh', + 'installable-flake.hh', + 'installable-value.hh', + 'installables.hh', + 'legacy.hh', + 'markdown.hh', + 'misc-store-flags.hh', + 'network-proxy.hh', + 'repl-interacter.hh', + 'repl.hh', +) diff --git a/src/libcmd/misc-store-flags.hh b/src/libcmd/include/nix/cmd/misc-store-flags.hh similarity index 90% rename from src/libcmd/misc-store-flags.hh rename to src/libcmd/include/nix/cmd/misc-store-flags.hh index 124372af7..c9467ad8e 100644 --- a/src/libcmd/misc-store-flags.hh +++ b/src/libcmd/include/nix/cmd/misc-store-flags.hh @@ -1,5 +1,5 @@ -#include "args.hh" -#include "content-address.hh" +#include "nix/util/args.hh" +#include "nix/store/content-address.hh" namespace nix::flag { diff --git a/src/libcmd/network-proxy.hh b/src/libcmd/include/nix/cmd/network-proxy.hh similarity index 93% rename from src/libcmd/network-proxy.hh rename to src/libcmd/include/nix/cmd/network-proxy.hh index 0b6856acb..255597a61 100644 --- a/src/libcmd/network-proxy.hh +++ b/src/libcmd/include/nix/cmd/network-proxy.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "types.hh" +#include "nix/util/types.hh" namespace nix { diff --git a/src/libcmd/repl-interacter.hh b/src/libcmd/include/nix/cmd/repl-interacter.hh similarity index 94% rename from src/libcmd/repl-interacter.hh rename to src/libcmd/include/nix/cmd/repl-interacter.hh index cc70efd07..eb58563b2 100644 --- a/src/libcmd/repl-interacter.hh +++ b/src/libcmd/include/nix/cmd/repl-interacter.hh @@ -1,8 +1,8 @@ #pragma once /// @file -#include "finally.hh" -#include "types.hh" +#include "nix/util/finally.hh" +#include "nix/util/types.hh" #include #include diff --git a/src/libcmd/repl.hh b/src/libcmd/include/nix/cmd/repl.hh similarity index 97% rename from src/libcmd/repl.hh rename to src/libcmd/include/nix/cmd/repl.hh index 11d1820f5..83e39727f 100644 --- a/src/libcmd/repl.hh +++ b/src/libcmd/include/nix/cmd/repl.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "eval.hh" +#include "nix/expr/eval.hh" namespace nix { diff --git a/src/libcmd/installable-attr-path.cc b/src/libcmd/installable-attr-path.cc index 8917e7a01..fcbfe1482 100644 --- a/src/libcmd/installable-attr-path.cc +++ b/src/libcmd/installable-attr-path.cc @@ -1,21 +1,21 @@ -#include "globals.hh" -#include "installable-attr-path.hh" -#include "outputs-spec.hh" -#include "util.hh" -#include "command.hh" -#include "attr-path.hh" -#include "common-eval-args.hh" -#include "derivations.hh" -#include "eval-inline.hh" -#include "eval.hh" -#include "get-drvs.hh" -#include "store-api.hh" -#include "shared.hh" -#include "flake/flake.hh" -#include "eval-cache.hh" -#include "url.hh" -#include "registry.hh" -#include "build-result.hh" +#include "nix/store/globals.hh" +#include "nix/cmd/installable-attr-path.hh" +#include "nix/store/outputs-spec.hh" +#include "nix/util/util.hh" +#include "nix/cmd/command.hh" +#include "nix/expr/attr-path.hh" +#include "nix/cmd/common-eval-args.hh" +#include "nix/store/derivations.hh" +#include "nix/expr/eval-inline.hh" +#include "nix/expr/eval.hh" +#include "nix/expr/get-drvs.hh" +#include "nix/store/store-api.hh" +#include "nix/main/shared.hh" +#include "nix/flake/flake.hh" +#include "nix/expr/eval-cache.hh" +#include "nix/util/url.hh" +#include "nix/fetchers/registry.hh" +#include "nix/store/build-result.hh" #include #include diff --git a/src/libcmd/installable-derived-path.cc b/src/libcmd/installable-derived-path.cc index abacd7350..5a92f81c7 100644 --- a/src/libcmd/installable-derived-path.cc +++ b/src/libcmd/installable-derived-path.cc @@ -1,5 +1,5 @@ -#include "installable-derived-path.hh" -#include "derivations.hh" +#include "nix/cmd/installable-derived-path.hh" +#include "nix/store/derivations.hh" namespace nix { diff --git a/src/libcmd/installable-flake.cc b/src/libcmd/installable-flake.cc index 6c9ee6748..83285b739 100644 --- a/src/libcmd/installable-flake.cc +++ b/src/libcmd/installable-flake.cc @@ -1,22 +1,22 @@ -#include "globals.hh" -#include "installable-flake.hh" -#include "installable-derived-path.hh" -#include "outputs-spec.hh" -#include "util.hh" -#include "command.hh" -#include "attr-path.hh" -#include "common-eval-args.hh" -#include "derivations.hh" -#include "eval-inline.hh" -#include "eval.hh" -#include "get-drvs.hh" -#include "store-api.hh" -#include "shared.hh" -#include "flake/flake.hh" -#include "eval-cache.hh" -#include "url.hh" -#include "registry.hh" -#include "build-result.hh" +#include "nix/store/globals.hh" +#include "nix/cmd/installable-flake.hh" +#include "nix/cmd/installable-derived-path.hh" +#include "nix/store/outputs-spec.hh" +#include "nix/util/util.hh" +#include "nix/cmd/command.hh" +#include "nix/expr/attr-path.hh" +#include "nix/cmd/common-eval-args.hh" +#include "nix/store/derivations.hh" +#include "nix/expr/eval-inline.hh" +#include "nix/expr/eval.hh" +#include "nix/expr/get-drvs.hh" +#include "nix/store/store-api.hh" +#include "nix/main/shared.hh" +#include "nix/flake/flake.hh" +#include "nix/expr/eval-cache.hh" +#include "nix/util/url.hh" +#include "nix/fetchers/registry.hh" +#include "nix/store/build-result.hh" #include #include diff --git a/src/libcmd/installable-value.cc b/src/libcmd/installable-value.cc index 1aa2e65c1..d9ac3a29e 100644 --- a/src/libcmd/installable-value.cc +++ b/src/libcmd/installable-value.cc @@ -1,6 +1,6 @@ -#include "installable-value.hh" -#include "eval-cache.hh" -#include "fetch-to-store.hh" +#include "nix/cmd/installable-value.hh" +#include "nix/expr/eval-cache.hh" +#include "nix/fetchers/fetch-to-store.hh" namespace nix { diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index e8ecd4432..2fde59e8b 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -1,33 +1,33 @@ -#include "globals.hh" -#include "installables.hh" -#include "installable-derived-path.hh" -#include "installable-attr-path.hh" -#include "installable-flake.hh" -#include "outputs-spec.hh" -#include "users.hh" -#include "util.hh" -#include "command.hh" -#include "attr-path.hh" -#include "common-eval-args.hh" -#include "derivations.hh" -#include "eval-inline.hh" -#include "eval.hh" -#include "eval-settings.hh" -#include "get-drvs.hh" -#include "store-api.hh" -#include "shared.hh" -#include "flake/flake.hh" -#include "eval-cache.hh" -#include "url.hh" -#include "registry.hh" -#include "build-result.hh" +#include "nix/store/globals.hh" +#include "nix/cmd/installables.hh" +#include "nix/cmd/installable-derived-path.hh" +#include "nix/cmd/installable-attr-path.hh" +#include "nix/cmd/installable-flake.hh" +#include "nix/store/outputs-spec.hh" +#include "nix/util/users.hh" +#include "nix/util/util.hh" +#include "nix/cmd/command.hh" +#include "nix/expr/attr-path.hh" +#include "nix/cmd/common-eval-args.hh" +#include "nix/store/derivations.hh" +#include "nix/expr/eval-inline.hh" +#include "nix/expr/eval.hh" +#include "nix/expr/eval-settings.hh" +#include "nix/expr/get-drvs.hh" +#include "nix/store/store-api.hh" +#include "nix/main/shared.hh" +#include "nix/flake/flake.hh" +#include "nix/expr/eval-cache.hh" +#include "nix/util/url.hh" +#include "nix/fetchers/registry.hh" +#include "nix/store/build-result.hh" #include #include #include -#include "strings-inline.hh" +#include "nix/util/strings-inline.hh" namespace nix { diff --git a/src/libcmd/legacy.cc b/src/libcmd/legacy.cc index 6df09ee37..69b066831 100644 --- a/src/libcmd/legacy.cc +++ b/src/libcmd/legacy.cc @@ -1,4 +1,4 @@ -#include "legacy.hh" +#include "nix/cmd/legacy.hh" namespace nix { diff --git a/src/libcmd/markdown.cc b/src/libcmd/markdown.cc index 4566e6ba6..41da73c7a 100644 --- a/src/libcmd/markdown.cc +++ b/src/libcmd/markdown.cc @@ -1,8 +1,10 @@ -#include "markdown.hh" -#include "environment-variables.hh" -#include "error.hh" -#include "finally.hh" -#include "terminal.hh" +#include "nix/cmd/markdown.hh" +#include "nix/util/environment-variables.hh" +#include "nix/util/error.hh" +#include "nix/util/finally.hh" +#include "nix/util/terminal.hh" + +#include "cmd-config-private.hh" #if HAVE_LOWDOWN # include diff --git a/src/libcmd/meson.build b/src/libcmd/meson.build index 4145f408a..32f44697d 100644 --- a/src/libcmd/meson.build +++ b/src/libcmd/meson.build @@ -44,30 +44,18 @@ if readline_flavor == 'editline' elif readline_flavor == 'readline' readline = dependency('readline') deps_private += readline - configdata.set( - 'USE_READLINE', - 1, - description: 'Use readline instead of editline', - ) else error('illegal editline flavor', readline_flavor) endif - -config_h = configure_file( - configuration : configdata, - output : 'config-cmd.hh', +configdata.set( + 'USE_READLINE', + (readline_flavor == 'readline').to_int(), + description: 'Use readline instead of editline', ) -add_project_arguments( - # TODO(Qyriad): Yes this is how the autoconf+Make system did it. - # It would be nice for our headers to be idempotent instead. - '-include', 'config-util.hh', - '-include', 'config-store.hh', - # '-include', 'config-fetchers.h', - '-include', 'config-expr.hh', - '-include', 'config-main.hh', - '-include', 'config-cmd.hh', - language : 'cpp', +config_priv_h = configure_file( + configuration : configdata, + output : 'cmd-config-private.hh', ) subdir('nix-meson-build-support/common') @@ -91,37 +79,23 @@ sources = files( 'repl.cc', ) -include_dirs = [include_directories('.')] +subdir('include/nix/cmd') -headers = [config_h] + files( - 'built-path.hh', - 'command-installable-value.hh', - 'command.hh', - 'common-eval-args.hh', - 'compatibility-settings.hh', - 'editor-for.hh', - 'installable-attr-path.hh', - 'installable-derived-path.hh', - 'installable-flake.hh', - 'installable-value.hh', - 'installables.hh', - 'legacy.hh', - 'markdown.hh', - 'misc-store-flags.hh', - 'network-proxy.hh', - 'repl-interacter.hh', - 'repl.hh', -) +subdir('nix-meson-build-support/export-all-symbols') +subdir('nix-meson-build-support/windows-version') this_library = library( 'nixcmd', sources, + config_priv_h, dependencies : deps_public + deps_private + deps_other, + include_directories : include_dirs, + link_args: linker_export_flags, prelink : true, # For C++ static initializers install : true, ) -install_headers(headers, subdir : 'nix', preserve_path : true) +install_headers(headers, subdir : 'nix/cmd', preserve_path : true) libraries_private = [] diff --git a/src/libcmd/misc-store-flags.cc b/src/libcmd/misc-store-flags.cc index 4e29e8981..a57ad35ff 100644 --- a/src/libcmd/misc-store-flags.cc +++ b/src/libcmd/misc-store-flags.cc @@ -1,4 +1,4 @@ -#include "misc-store-flags.hh" +#include "nix/cmd/misc-store-flags.hh" namespace nix::flag { diff --git a/src/libcmd/network-proxy.cc b/src/libcmd/network-proxy.cc index 738bf6147..a4a89685c 100644 --- a/src/libcmd/network-proxy.cc +++ b/src/libcmd/network-proxy.cc @@ -1,8 +1,8 @@ -#include "network-proxy.hh" +#include "nix/cmd/network-proxy.hh" #include -#include "environment-variables.hh" +#include "nix/util/environment-variables.hh" namespace nix { diff --git a/src/libcmd/package.nix b/src/libcmd/package.nix index 5150de249..5c9040e8b 100644 --- a/src/libcmd/package.nix +++ b/src/libcmd/package.nix @@ -46,6 +46,7 @@ mkMesonLibrary (finalAttrs: { ./.version ./meson.build ./meson.options + ./include/nix/cmd/meson.build (fileset.fileFilter (file: file.hasExt "cc") ./.) (fileset.fileFilter (file: file.hasExt "hh") ./.) ]; diff --git a/src/libcmd/repl-interacter.cc b/src/libcmd/repl-interacter.cc index 187af46ea..0da2cc615 100644 --- a/src/libcmd/repl-interacter.cc +++ b/src/libcmd/repl-interacter.cc @@ -1,6 +1,8 @@ +#include "cmd-config-private.hh" + #include -#ifdef USE_READLINE +#if USE_READLINE #include #include #else @@ -14,12 +16,12 @@ extern "C" { } #endif -#include "signals.hh" -#include "finally.hh" -#include "repl-interacter.hh" -#include "file-system.hh" -#include "repl.hh" -#include "environment-variables.hh" +#include "nix/util/signals.hh" +#include "nix/util/finally.hh" +#include "nix/cmd/repl-interacter.hh" +#include "nix/util/file-system.hh" +#include "nix/cmd/repl.hh" +#include "nix/util/environment-variables.hh" namespace nix { @@ -35,7 +37,7 @@ void sigintHandler(int signo) static detail::ReplCompleterMixin * curRepl; // ugly -#ifndef USE_READLINE +#if !USE_READLINE static char * completionCallback(char * s, int * match) { auto possible = curRepl->completePrefix(s); @@ -113,14 +115,14 @@ ReadlineLikeInteracter::Guard ReadlineLikeInteracter::init(detail::ReplCompleter } catch (SystemError & e) { logWarning(e.info()); } -#ifndef USE_READLINE +#if !USE_READLINE el_hist_size = 1000; #endif read_history(historyFile.c_str()); auto oldRepl = curRepl; curRepl = repl; Guard restoreRepl([oldRepl] { curRepl = oldRepl; }); -#ifndef USE_READLINE +#if !USE_READLINE rl_set_complete_func(completionCallback); rl_set_list_possib_func(listPossibleCallback); #endif @@ -183,7 +185,7 @@ bool ReadlineLikeInteracter::getLine(std::string & input, ReplPromptType promptT // quite useful for reading the test output, so we add it here. if (auto e = getEnv("_NIX_TEST_REPL_ECHO"); s && e && *e == "1") { -#ifndef USE_READLINE +#if !USE_READLINE // This is probably not right for multi-line input, but we don't use that // in the characterisation tests, so it's fine. std::cout << promptForType(promptType) << s << std::endl; diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc index 281e1f6f0..c5a95268b 100644 --- a/src/libcmd/repl.cc +++ b/src/libcmd/repl.cc @@ -2,34 +2,34 @@ #include #include -#include "error.hh" -#include "repl-interacter.hh" -#include "repl.hh" +#include "nix/util/error.hh" +#include "nix/cmd/repl-interacter.hh" +#include "nix/cmd/repl.hh" -#include "ansicolor.hh" -#include "shared.hh" -#include "eval.hh" -#include "eval-settings.hh" -#include "attr-path.hh" -#include "signals.hh" -#include "store-api.hh" -#include "log-store.hh" -#include "common-eval-args.hh" -#include "get-drvs.hh" -#include "derivations.hh" -#include "globals.hh" -#include "flake/flake.hh" -#include "flake/lockfile.hh" -#include "users.hh" -#include "editor-for.hh" -#include "finally.hh" -#include "markdown.hh" -#include "local-fs-store.hh" -#include "print.hh" -#include "ref.hh" -#include "value.hh" +#include "nix/util/ansicolor.hh" +#include "nix/main/shared.hh" +#include "nix/expr/eval.hh" +#include "nix/expr/eval-settings.hh" +#include "nix/expr/attr-path.hh" +#include "nix/util/signals.hh" +#include "nix/store/store-api.hh" +#include "nix/store/log-store.hh" +#include "nix/cmd/common-eval-args.hh" +#include "nix/expr/get-drvs.hh" +#include "nix/store/derivations.hh" +#include "nix/store/globals.hh" +#include "nix/flake/flake.hh" +#include "nix/flake/lockfile.hh" +#include "nix/util/users.hh" +#include "nix/cmd/editor-for.hh" +#include "nix/util/finally.hh" +#include "nix/cmd/markdown.hh" +#include "nix/store/local-fs-store.hh" +#include "nix/expr/print.hh" +#include "nix/util/ref.hh" +#include "nix/expr/value.hh" -#include "strings.hh" +#include "nix/util/strings.hh" namespace nix { @@ -124,7 +124,7 @@ std::string removeWhitespace(std::string s) NixRepl::NixRepl(const LookupPath & lookupPath, nix::ref store, ref state, - std::function getValues, RunNix * runNix = nullptr) + std::function getValues, RunNix * runNix) : AbstractNixRepl(state) , debugTraceIndex(0) , getValues(getValues) @@ -839,9 +839,10 @@ std::unique_ptr AbstractNixRepl::create( { return std::make_unique( lookupPath, - openStore(), + std::move(store), state, - getValues + getValues, + runNix ); } @@ -859,7 +860,8 @@ ReplExitStatus AbstractNixRepl::runSimple( lookupPath, openStore(), evalState, - getValues + getValues, + /*runNix=*/nullptr ); repl->initEnv(); diff --git a/src/libexpr-c/meson.build b/src/libexpr-c/meson.build index 9487132cf..7c11ca9cb 100644 --- a/src/libexpr-c/meson.build +++ b/src/libexpr-c/meson.build @@ -14,8 +14,6 @@ cxx = meson.get_compiler('cpp') subdir('nix-meson-build-support/deps-lists') -configdata = configuration_data() - deps_private_maybe_subproject = [ dependency('nix-util'), dependency('nix-store'), @@ -27,30 +25,6 @@ deps_public_maybe_subproject = [ ] subdir('nix-meson-build-support/subprojects') -# TODO rename, because it will conflict with downstream projects -configdata.set_quoted('PACKAGE_VERSION', meson.project_version()) - -config_h = configure_file( - configuration : configdata, - output : 'config-expr.h', -) - -add_project_arguments( - # TODO(Qyriad): Yes this is how the autoconf+Make system did it. - # It would be nice for our headers to be idempotent instead. - - # From C++ libraries, only for internals - '-include', 'config-util.hh', - '-include', 'config-store.hh', - '-include', 'config-expr.hh', - - # From C libraries, for our public, installed headers too - '-include', 'config-util.h', - '-include', 'config-store.h', - '-include', 'config-expr.h', - language : 'cpp', -) - subdir('nix-meson-build-support/common') sources = files( @@ -61,7 +35,7 @@ sources = files( include_dirs = [include_directories('.')] -headers = [config_h] + files( +headers = files( 'nix_api_expr.h', 'nix_api_external.h', 'nix_api_value.h', @@ -83,7 +57,7 @@ this_library = library( install : true, ) -install_headers(headers, subdir : 'nix', preserve_path : true) +install_headers(headers, preserve_path : true) libraries_private = [] diff --git a/src/libexpr-c/nix_api_expr.cc b/src/libexpr-c/nix_api_expr.cc index a024248cd..f34b1b77f 100644 --- a/src/libexpr-c/nix_api_expr.cc +++ b/src/libexpr-c/nix_api_expr.cc @@ -2,11 +2,11 @@ #include #include -#include "eval.hh" -#include "eval-gc.hh" -#include "globals.hh" -#include "eval-settings.hh" -#include "ref.hh" +#include "nix/expr/eval.hh" +#include "nix/expr/eval-gc.hh" +#include "nix/store/globals.hh" +#include "nix/expr/eval-settings.hh" +#include "nix/util/ref.hh" #include "nix_api_expr.h" #include "nix_api_expr_internal.h" @@ -15,7 +15,7 @@ #include "nix_api_util.h" #include "nix_api_util_internal.h" -#if HAVE_BOEHMGC +#if NIX_USE_BOEHMGC # include #endif @@ -207,7 +207,7 @@ void nix_state_free(EvalState * state) delete state; } -#if HAVE_BOEHMGC +#if NIX_USE_BOEHMGC std::unordered_map< const void *, unsigned int, @@ -283,7 +283,7 @@ nix_err nix_value_decref(nix_c_context * context, nix_value *x) void nix_gc_register_finalizer(void * obj, void * cd, void (*finalizer)(void * obj, void * cd)) { -#if HAVE_BOEHMGC +#if NIX_USE_BOEHMGC GC_REGISTER_FINALIZER(obj, finalizer, cd, 0, 0); #endif } diff --git a/src/libexpr-c/nix_api_expr_internal.h b/src/libexpr-c/nix_api_expr_internal.h index f59664011..a26595cec 100644 --- a/src/libexpr-c/nix_api_expr_internal.h +++ b/src/libexpr-c/nix_api_expr_internal.h @@ -1,12 +1,12 @@ #ifndef NIX_API_EXPR_INTERNAL_H #define NIX_API_EXPR_INTERNAL_H -#include "fetch-settings.hh" -#include "eval.hh" -#include "eval-settings.hh" -#include "attr-set.hh" +#include "nix/fetchers/fetch-settings.hh" +#include "nix/expr/eval.hh" +#include "nix/expr/eval-settings.hh" +#include "nix/expr/attr-set.hh" #include "nix_api_value.h" -#include "search-path.hh" +#include "nix/expr/search-path.hh" struct nix_eval_state_builder { diff --git a/src/libexpr-c/nix_api_external.cc b/src/libexpr-c/nix_api_external.cc index d673bcb0b..04d2e52b5 100644 --- a/src/libexpr-c/nix_api_external.cc +++ b/src/libexpr-c/nix_api_external.cc @@ -1,8 +1,8 @@ -#include "attr-set.hh" -#include "config.hh" -#include "eval.hh" -#include "globals.hh" -#include "value.hh" +#include "nix/expr/attr-set.hh" +#include "nix/util/configuration.hh" +#include "nix/expr/eval.hh" +#include "nix/store/globals.hh" +#include "nix/expr/value.hh" #include "nix_api_expr.h" #include "nix_api_expr_internal.h" @@ -10,7 +10,7 @@ #include "nix_api_util.h" #include "nix_api_util_internal.h" #include "nix_api_value.h" -#include "value/context.hh" +#include "nix/expr/value/context.hh" #include @@ -168,7 +168,7 @@ ExternalValue * nix_create_external_value(nix_c_context * context, NixCExternalV context->last_err_code = NIX_OK; try { auto ret = new -#if HAVE_BOEHMGC +#if NIX_USE_BOEHMGC (GC) #endif NixCExternalValue(*desc, v); diff --git a/src/libexpr-c/nix_api_external.h b/src/libexpr-c/nix_api_external.h index 6c524b975..f4a327281 100644 --- a/src/libexpr-c/nix_api_external.h +++ b/src/libexpr-c/nix_api_external.h @@ -12,9 +12,10 @@ #include "nix_api_expr.h" #include "nix_api_util.h" #include "nix_api_value.h" -#include "stdbool.h" -#include "stddef.h" -#include "stdint.h" + +#include +#include +#include #ifdef __cplusplus extern "C" { diff --git a/src/libexpr-c/nix_api_value.cc b/src/libexpr-c/nix_api_value.cc index 448f4a58a..298d94845 100644 --- a/src/libexpr-c/nix_api_value.cc +++ b/src/libexpr-c/nix_api_value.cc @@ -1,10 +1,10 @@ -#include "attr-set.hh" -#include "config.hh" -#include "eval.hh" -#include "globals.hh" -#include "path.hh" -#include "primops.hh" -#include "value.hh" +#include "nix/expr/attr-set.hh" +#include "nix/util/configuration.hh" +#include "nix/expr/eval.hh" +#include "nix/store/globals.hh" +#include "nix/store/path.hh" +#include "nix/expr/primops.hh" +#include "nix/expr/value.hh" #include "nix_api_expr.h" #include "nix_api_expr_internal.h" @@ -12,7 +12,7 @@ #include "nix_api_util_internal.h" #include "nix_api_store_internal.h" #include "nix_api_value.h" -#include "value/context.hh" +#include "nix/expr/value/context.hh" // Internal helper functions to check [in] and [out] `Value *` parameters static const nix::Value & check_value_not_null(const nix_value * value) @@ -125,7 +125,7 @@ PrimOp * nix_alloc_primop( try { using namespace std::placeholders; auto p = new -#if HAVE_BOEHMGC +#if NIX_USE_BOEHMGC (GC) #endif nix::PrimOp{ @@ -497,7 +497,7 @@ ListBuilder * nix_make_list_builder(nix_c_context * context, EvalState * state, try { auto builder = state->state.buildList(capacity); return new -#if HAVE_BOEHMGC +#if NIX_USE_BOEHMGC (NoGC) #endif ListBuilder{std::move(builder)}; @@ -519,7 +519,7 @@ nix_list_builder_insert(nix_c_context * context, ListBuilder * list_builder, uns void nix_list_builder_free(ListBuilder * list_builder) { -#if HAVE_BOEHMGC +#if NIX_USE_BOEHMGC GC_FREE(list_builder); #else delete list_builder; @@ -578,7 +578,7 @@ BindingsBuilder * nix_make_bindings_builder(nix_c_context * context, EvalState * try { auto bb = state->state.buildBindings(capacity); return new -#if HAVE_BOEHMGC +#if NIX_USE_BOEHMGC (NoGC) #endif BindingsBuilder{std::move(bb)}; @@ -600,7 +600,7 @@ nix_err nix_bindings_builder_insert(nix_c_context * context, BindingsBuilder * b void nix_bindings_builder_free(BindingsBuilder * bb) { -#if HAVE_BOEHMGC +#if NIX_USE_BOEHMGC GC_FREE((nix::BindingsBuilder *) bb); #else delete (nix::BindingsBuilder *) bb; diff --git a/src/libexpr-c/nix_api_value.h b/src/libexpr-c/nix_api_value.h index 711b0adbc..7cd6ad180 100644 --- a/src/libexpr-c/nix_api_value.h +++ b/src/libexpr-c/nix_api_value.h @@ -10,9 +10,10 @@ #include "nix_api_util.h" #include "nix_api_store.h" -#include "stdbool.h" -#include "stddef.h" -#include "stdint.h" + +#include +#include +#include #ifdef __cplusplus extern "C" { diff --git a/src/libexpr-test-support/tests/libexpr.hh b/src/libexpr-test-support/include/nix/expr/tests/libexpr.hh similarity index 93% rename from src/libexpr-test-support/tests/libexpr.hh rename to src/libexpr-test-support/include/nix/expr/tests/libexpr.hh index 095ea1d0e..48c96ae2c 100644 --- a/src/libexpr-test-support/tests/libexpr.hh +++ b/src/libexpr-test-support/include/nix/expr/tests/libexpr.hh @@ -4,16 +4,16 @@ #include #include -#include "fetch-settings.hh" -#include "value.hh" -#include "nixexpr.hh" -#include "nixexpr.hh" -#include "eval.hh" -#include "eval-gc.hh" -#include "eval-inline.hh" -#include "eval-settings.hh" +#include "nix/fetchers/fetch-settings.hh" +#include "nix/expr/value.hh" +#include "nix/expr/nixexpr.hh" +#include "nix/expr/nixexpr.hh" +#include "nix/expr/eval.hh" +#include "nix/expr/eval-gc.hh" +#include "nix/expr/eval-inline.hh" +#include "nix/expr/eval-settings.hh" -#include "tests/libstore.hh" +#include "nix/store/tests/libstore.hh" namespace nix { class LibExprTest : public LibStoreTest { diff --git a/src/libexpr-test-support/include/nix/expr/tests/meson.build b/src/libexpr-test-support/include/nix/expr/tests/meson.build new file mode 100644 index 000000000..710bd8d4e --- /dev/null +++ b/src/libexpr-test-support/include/nix/expr/tests/meson.build @@ -0,0 +1,9 @@ +# Public headers directory + +include_dirs = [include_directories('../../..')] + +headers = files( + 'libexpr.hh', + 'nix_api_expr.hh', + 'value/context.hh', +) diff --git a/src/libexpr-test-support/tests/nix_api_expr.hh b/src/libexpr-test-support/include/nix/expr/tests/nix_api_expr.hh similarity index 92% rename from src/libexpr-test-support/tests/nix_api_expr.hh rename to src/libexpr-test-support/include/nix/expr/tests/nix_api_expr.hh index 6ddca0d14..3e5aec313 100644 --- a/src/libexpr-test-support/tests/nix_api_expr.hh +++ b/src/libexpr-test-support/include/nix/expr/tests/nix_api_expr.hh @@ -2,7 +2,7 @@ ///@file #include "nix_api_expr.h" #include "nix_api_value.h" -#include "tests/nix_api_store.hh" +#include "nix/store/tests/nix_api_store.hh" #include diff --git a/src/libexpr-test-support/tests/value/context.hh b/src/libexpr-test-support/include/nix/expr/tests/value/context.hh similarity index 93% rename from src/libexpr-test-support/tests/value/context.hh rename to src/libexpr-test-support/include/nix/expr/tests/value/context.hh index 8c68c78bb..a6a851d3a 100644 --- a/src/libexpr-test-support/tests/value/context.hh +++ b/src/libexpr-test-support/include/nix/expr/tests/value/context.hh @@ -3,7 +3,7 @@ #include -#include "value/context.hh" +#include "nix/expr/value/context.hh" namespace rc { using namespace nix; diff --git a/src/libexpr-test-support/meson.build b/src/libexpr-test-support/meson.build index 56e814cd1..b97f94362 100644 --- a/src/libexpr-test-support/meson.build +++ b/src/libexpr-test-support/meson.build @@ -29,28 +29,13 @@ subdir('nix-meson-build-support/subprojects') rapidcheck = dependency('rapidcheck') deps_public += rapidcheck -add_project_arguments( - # TODO(Qyriad): Yes this is how the autoconf+Make system did it. - # It would be nice for our headers to be idempotent instead. - '-include', 'config-util.hh', - '-include', 'config-store.hh', - '-include', 'config-expr.hh', - language : 'cpp', -) - subdir('nix-meson-build-support/common') sources = files( 'tests/value/context.cc', ) -include_dirs = [include_directories('.')] - -headers = files( - 'tests/libexpr.hh', - 'tests/nix_api_expr.hh', - 'tests/value/context.hh', -) +subdir('include/nix/expr/tests') subdir('nix-meson-build-support/export-all-symbols') subdir('nix-meson-build-support/windows-version') @@ -67,7 +52,7 @@ this_library = library( install : true, ) -install_headers(headers, subdir : 'nix', preserve_path : true) +install_headers(headers, subdir : 'nix/expr/tests', preserve_path : true) libraries_private = [] diff --git a/src/libexpr-test-support/package.nix b/src/libexpr-test-support/package.nix index dbf515370..1879a5716 100644 --- a/src/libexpr-test-support/package.nix +++ b/src/libexpr-test-support/package.nix @@ -29,6 +29,7 @@ mkMesonLibrary (finalAttrs: { ./.version ./meson.build # ./meson.options + ./include/nix/expr/tests/meson.build (fileset.fileFilter (file: file.hasExt "cc") ./.) (fileset.fileFilter (file: file.hasExt "hh") ./.) ]; diff --git a/src/libexpr-test-support/tests/value/context.cc b/src/libexpr-test-support/tests/value/context.cc index 8658bdaef..51ff1b2ae 100644 --- a/src/libexpr-test-support/tests/value/context.cc +++ b/src/libexpr-test-support/tests/value/context.cc @@ -1,30 +1,39 @@ #include -#include "tests/path.hh" -#include "tests/value/context.hh" +#include "nix/store/tests/path.hh" +#include "nix/expr/tests/value/context.hh" namespace rc { using namespace nix; Gen Arbitrary::arbitrary() { - return gen::just(NixStringContextElem::DrvDeep { - .drvPath = *gen::arbitrary(), + return gen::map(gen::arbitrary(), [](StorePath drvPath) { + return NixStringContextElem::DrvDeep{ + .drvPath = drvPath, + }; }); } Gen Arbitrary::arbitrary() { - switch (*gen::inRange(0, std::variant_size_v)) { - case 0: - return gen::just(*gen::arbitrary()); - case 1: - return gen::just(*gen::arbitrary()); - case 2: - return gen::just(*gen::arbitrary()); - default: - assert(false); - } + return gen::mapcat( + gen::inRange(0, std::variant_size_v), + [](uint8_t n) -> Gen { + switch (n) { + case 0: + return gen::map( + gen::arbitrary(), [](NixStringContextElem a) { return a; }); + case 1: + return gen::map( + gen::arbitrary(), [](NixStringContextElem a) { return a; }); + case 2: + return gen::map( + gen::arbitrary(), [](NixStringContextElem a) { return a; }); + default: + assert(false); + } + }); } } diff --git a/src/libexpr-tests/derived-path.cc b/src/libexpr-tests/derived-path.cc index d5fc6f201..9cc5d5371 100644 --- a/src/libexpr-tests/derived-path.cc +++ b/src/libexpr-tests/derived-path.cc @@ -2,8 +2,8 @@ #include #include -#include "tests/derived-path.hh" -#include "tests/libexpr.hh" +#include "nix/store/tests/derived-path.hh" +#include "nix/expr/tests/libexpr.hh" namespace nix { @@ -44,11 +44,11 @@ RC_GTEST_FIXTURE_PROP( * to worry about race conditions if the tests run concurrently. */ ExperimentalFeatureSettings mockXpSettings; - mockXpSettings.set("experimental-features", "ca-derivations"); + mockXpSettings.set("experimental-features", "ca-derivations dynamic-derivations"); auto * v = state.allocValue(); state.mkOutputString(*v, b, std::nullopt, mockXpSettings); - auto [d, _] = state.coerceToSingleDerivedPathUnchecked(noPos, *v, ""); + auto [d, _] = state.coerceToSingleDerivedPathUnchecked(noPos, *v, "", mockXpSettings); RC_ASSERT(SingleDerivedPath { b } == d); } @@ -57,9 +57,12 @@ RC_GTEST_FIXTURE_PROP( prop_derived_path_built_out_path_round_trip, (const SingleDerivedPath::Built & b, const StorePath & outPath)) { + ExperimentalFeatureSettings mockXpSettings; + mockXpSettings.set("experimental-features", "dynamic-derivations"); + auto * v = state.allocValue(); - state.mkOutputString(*v, b, outPath); - auto [d, _] = state.coerceToSingleDerivedPathUnchecked(noPos, *v, ""); + state.mkOutputString(*v, b, outPath, mockXpSettings); + auto [d, _] = state.coerceToSingleDerivedPathUnchecked(noPos, *v, "", mockXpSettings); RC_ASSERT(SingleDerivedPath { b } == d); } diff --git a/src/libexpr-tests/error_traces.cc b/src/libexpr-tests/error_traces.cc index 53013a34a..d0ccd970a 100644 --- a/src/libexpr-tests/error_traces.cc +++ b/src/libexpr-tests/error_traces.cc @@ -1,7 +1,7 @@ #include #include -#include "tests/libexpr.hh" +#include "nix/expr/tests/libexpr.hh" namespace nix { diff --git a/src/libexpr-tests/eval.cc b/src/libexpr-tests/eval.cc index 61f6be0db..e9664dc58 100644 --- a/src/libexpr-tests/eval.cc +++ b/src/libexpr-tests/eval.cc @@ -1,8 +1,8 @@ #include #include -#include "eval.hh" -#include "tests/libexpr.hh" +#include "nix/expr/eval.hh" +#include "nix/expr/tests/libexpr.hh" namespace nix { diff --git a/src/libexpr-tests/json.cc b/src/libexpr-tests/json.cc index f4cc118d6..11f31d058 100644 --- a/src/libexpr-tests/json.cc +++ b/src/libexpr-tests/json.cc @@ -1,5 +1,5 @@ -#include "tests/libexpr.hh" -#include "value-to-json.hh" +#include "nix/expr/tests/libexpr.hh" +#include "nix/expr/value-to-json.hh" namespace nix { // Testing the conversion to JSON diff --git a/src/libexpr-tests/main.cc b/src/libexpr-tests/main.cc index e3412d9ef..52cca53c4 100644 --- a/src/libexpr-tests/main.cc +++ b/src/libexpr-tests/main.cc @@ -1,7 +1,7 @@ #include #include -#include "globals.hh" -#include "logging.hh" +#include "nix/store/globals.hh" +#include "nix/util/logging.hh" using namespace nix; @@ -14,7 +14,7 @@ int main (int argc, char **argv) { // Disable build hook. We won't be testing remote builds in these unit tests. If we do, fix the above build hook. settings.buildHook = {}; - #if __linux__ // should match the conditional around sandboxBuildDir declaration. + #ifdef __linux__ // should match the conditional around sandboxBuildDir declaration. // When building and testing nix within the host's Nix sandbox, our store dir will be located in the host's sandboxBuildDir, e.g.: // Host @@ -27,7 +27,7 @@ int main (int argc, char **argv) { settings.sandboxBuildDir = "/test-build-dir-instead-of-usual-build-dir"; #endif - #if __APPLE__ + #ifdef __APPLE__ // Avoid this error, when already running in a sandbox: // sandbox-exec: sandbox_apply: Operation not permitted settings.sandboxMode = smDisabled; diff --git a/src/libexpr-tests/meson.build b/src/libexpr-tests/meson.build index 667a0d7b7..f7822edfd 100644 --- a/src/libexpr-tests/meson.build +++ b/src/libexpr-tests/meson.build @@ -35,16 +35,12 @@ deps_private += gtest gtest = dependency('gmock') deps_private += gtest -add_project_arguments( - # TODO(Qyriad): Yes this is how the autoconf+Make system did it. - # It would be nice for our headers to be idempotent instead. - '-include', 'config-util.hh', - '-include', 'config-store.hh', - '-include', 'config-expr.hh', - '-include', 'config-util.h', - '-include', 'config-store.h', - '-include', 'config-expr.h', - language : 'cpp', +configdata = configuration_data() +configdata.set_quoted('PACKAGE_VERSION', meson.project_version()) + +config_priv_h = configure_file( + configuration : configdata, + output : 'expr-tests-config.hh', ) subdir('nix-meson-build-support/common') @@ -72,6 +68,7 @@ include_dirs = [include_directories('.')] this_exe = executable( meson.project_name(), sources, + config_priv_h, dependencies : deps_private_subproject + deps_private + deps_other, include_directories : include_dirs, # TODO: -lrapidcheck, see ../libutil-support/build.meson diff --git a/src/libexpr-tests/nix_api_expr.cc b/src/libexpr-tests/nix_api_expr.cc index 633224ae6..e2eeace6c 100644 --- a/src/libexpr-tests/nix_api_expr.cc +++ b/src/libexpr-tests/nix_api_expr.cc @@ -5,13 +5,15 @@ #include "nix_api_expr.h" #include "nix_api_value.h" -#include "tests/nix_api_expr.hh" -#include "tests/string_callback.hh" -#include "file-system.hh" +#include "nix/expr/tests/nix_api_expr.hh" +#include "nix/util/tests/string_callback.hh" +#include "nix/util/file-system.hh" #include #include +#include "expr-tests-config.hh" + namespace nixC { TEST_F(nix_api_store_test, nix_eval_state_lookup_path) diff --git a/src/libexpr-tests/nix_api_external.cc b/src/libexpr-tests/nix_api_external.cc index 81ff285a4..b32326f9e 100644 --- a/src/libexpr-tests/nix_api_external.cc +++ b/src/libexpr-tests/nix_api_external.cc @@ -7,8 +7,8 @@ #include "nix_api_value.h" #include "nix_api_external.h" -#include "tests/nix_api_expr.hh" -#include "tests/string_callback.hh" +#include "nix/expr/tests/nix_api_expr.hh" +#include "nix/util/tests/string_callback.hh" #include diff --git a/src/libexpr-tests/nix_api_value.cc b/src/libexpr-tests/nix_api_value.cc index 7fc8b4f64..14f8bd0b0 100644 --- a/src/libexpr-tests/nix_api_value.cc +++ b/src/libexpr-tests/nix_api_value.cc @@ -6,10 +6,10 @@ #include "nix_api_value.h" #include "nix_api_expr_internal.h" -#include "tests/nix_api_expr.hh" -#include "tests/string_callback.hh" +#include "nix/expr/tests/nix_api_expr.hh" +#include "nix/util/tests/string_callback.hh" -#include "gmock/gmock.h" +#include #include #include #include diff --git a/src/libexpr-tests/primops.cc b/src/libexpr-tests/primops.cc index 2bf726477..66850d78b 100644 --- a/src/libexpr-tests/primops.cc +++ b/src/libexpr-tests/primops.cc @@ -1,10 +1,10 @@ #include #include -#include "eval-settings.hh" -#include "memory-source-accessor.hh" +#include "nix/expr/eval-settings.hh" +#include "nix/util/memory-source-accessor.hh" -#include "tests/libexpr.hh" +#include "nix/expr/tests/libexpr.hh" namespace nix { class CaptureLogger : public Logger diff --git a/src/libexpr-tests/search-path.cc b/src/libexpr-tests/search-path.cc index 080679355..792bb0812 100644 --- a/src/libexpr-tests/search-path.cc +++ b/src/libexpr-tests/search-path.cc @@ -1,7 +1,7 @@ #include #include -#include "search-path.hh" +#include "nix/expr/search-path.hh" namespace nix { diff --git a/src/libexpr-tests/trivial.cc b/src/libexpr-tests/trivial.cc index d77b4d53b..50a8f29f8 100644 --- a/src/libexpr-tests/trivial.cc +++ b/src/libexpr-tests/trivial.cc @@ -1,4 +1,4 @@ -#include "tests/libexpr.hh" +#include "nix/expr/tests/libexpr.hh" namespace nix { // Testing of trivial expressions diff --git a/src/libexpr-tests/value/context.cc b/src/libexpr-tests/value/context.cc index 761286dbd..97cd50f75 100644 --- a/src/libexpr-tests/value/context.cc +++ b/src/libexpr-tests/value/context.cc @@ -2,9 +2,9 @@ #include #include -#include "tests/path.hh" -#include "tests/libexpr.hh" -#include "tests/value/context.hh" +#include "nix/store/tests/path.hh" +#include "nix/expr/tests/libexpr.hh" +#include "nix/expr/tests/value/context.hh" namespace nix { @@ -124,7 +124,9 @@ RC_GTEST_PROP( prop_round_rip, (const NixStringContextElem & o)) { - RC_ASSERT(o == NixStringContextElem::parse(o.to_string())); + ExperimentalFeatureSettings xpSettings; + xpSettings.set("experimental-features", "dynamic-derivations"); + RC_ASSERT(o == NixStringContextElem::parse(o.to_string(), xpSettings)); } #endif diff --git a/src/libexpr-tests/value/print.cc b/src/libexpr-tests/value/print.cc index 43b545035..d337a29a3 100644 --- a/src/libexpr-tests/value/print.cc +++ b/src/libexpr-tests/value/print.cc @@ -1,7 +1,7 @@ -#include "tests/libexpr.hh" +#include "nix/expr/tests/libexpr.hh" -#include "value.hh" -#include "print.hh" +#include "nix/expr/value.hh" +#include "nix/expr/print.hh" namespace nix { diff --git a/src/libexpr-tests/value/value.cc b/src/libexpr-tests/value/value.cc index 5762d5891..63501dd49 100644 --- a/src/libexpr-tests/value/value.cc +++ b/src/libexpr-tests/value/value.cc @@ -1,6 +1,6 @@ -#include "value.hh" +#include "nix/expr/value.hh" -#include "tests/libstore.hh" +#include "nix/store/tests/libstore.hh" namespace nix { diff --git a/src/libexpr/attr-path.cc b/src/libexpr/attr-path.cc index 822ec7620..cee805d14 100644 --- a/src/libexpr/attr-path.cc +++ b/src/libexpr/attr-path.cc @@ -1,5 +1,5 @@ -#include "attr-path.hh" -#include "eval-inline.hh" +#include "nix/expr/attr-path.hh" +#include "nix/expr/eval-inline.hh" namespace nix { diff --git a/src/libexpr/attr-set.cc b/src/libexpr/attr-set.cc index 866ef817a..06e245aea 100644 --- a/src/libexpr/attr-set.cc +++ b/src/libexpr/attr-set.cc @@ -1,5 +1,5 @@ -#include "attr-set.hh" -#include "eval-inline.hh" +#include "nix/expr/attr-set.hh" +#include "nix/expr/eval-inline.hh" #include diff --git a/src/libexpr/eval-cache.cc b/src/libexpr/eval-cache.cc index ea3319f99..30aa6076a 100644 --- a/src/libexpr/eval-cache.cc +++ b/src/libexpr/eval-cache.cc @@ -1,11 +1,11 @@ -#include "users.hh" -#include "eval-cache.hh" -#include "sqlite.hh" -#include "eval.hh" -#include "eval-inline.hh" -#include "store-api.hh" +#include "nix/util/users.hh" +#include "nix/expr/eval-cache.hh" +#include "nix/store/sqlite.hh" +#include "nix/expr/eval.hh" +#include "nix/expr/eval-inline.hh" +#include "nix/store/store-api.hh" // Need specialization involving `SymbolStr` just in this one module. -#include "strings-inline.hh" +#include "nix/util/strings-inline.hh" namespace nix::eval_cache { @@ -418,6 +418,14 @@ Value & AttrCursor::getValue() return **_value; } +void AttrCursor::fetchCachedValue() +{ + if (!cachedValue) + cachedValue = root->db->getAttr(getKey()); + if (cachedValue && std::get_if(&cachedValue->second) && parent) + throw CachedEvalError(parent->first, parent->second); +} + std::vector AttrCursor::getAttrPath() const { if (parent) { @@ -494,14 +502,13 @@ Suggestions AttrCursor::getSuggestionsForAttr(Symbol name) std::shared_ptr AttrCursor::maybeGetAttr(Symbol name) { if (root->db) { - if (!cachedValue) - cachedValue = root->db->getAttr(getKey()); + fetchCachedValue(); if (cachedValue) { if (auto attrs = std::get_if>(&cachedValue->second)) { for (auto & attr : *attrs) if (attr == name) - return std::make_shared(root, std::make_pair(shared_from_this(), attr)); + return std::make_shared(root, std::make_pair(ref(shared_from_this()), attr)); return nullptr; } else if (std::get_if(&cachedValue->second)) { auto attr = root->db->getAttr({cachedValue->first, name}); @@ -512,7 +519,7 @@ std::shared_ptr AttrCursor::maybeGetAttr(Symbol name) throw CachedEvalError(ref(shared_from_this()), name); else return std::make_shared(root, - std::make_pair(shared_from_this(), name), nullptr, std::move(attr)); + std::make_pair(ref(shared_from_this()), name), nullptr, std::move(attr)); } // Incomplete attrset, so need to fall thru and // evaluate to see whether 'name' exists @@ -547,7 +554,7 @@ std::shared_ptr AttrCursor::maybeGetAttr(Symbol name) } return make_ref( - root, std::make_pair(shared_from_this(), name), attr->value, std::move(cachedValue2)); + root, std::make_pair(ref(shared_from_this()), name), attr->value, std::move(cachedValue2)); } std::shared_ptr AttrCursor::maybeGetAttr(std::string_view name) @@ -585,8 +592,7 @@ OrSuggestions> AttrCursor::findAlongAttrPath(const std::vectordb) { - if (!cachedValue) - cachedValue = root->db->getAttr(getKey()); + fetchCachedValue(); if (cachedValue && !std::get_if(&cachedValue->second)) { if (auto s = std::get_if(&cachedValue->second)) { debug("using cached string attribute '%s'", getAttrPathStr()); @@ -607,8 +613,7 @@ std::string AttrCursor::getString() string_t AttrCursor::getStringWithContext() { if (root->db) { - if (!cachedValue) - cachedValue = root->db->getAttr(getKey()); + fetchCachedValue(); if (cachedValue && !std::get_if(&cachedValue->second)) { if (auto s = std::get_if(&cachedValue->second)) { bool valid = true; @@ -654,8 +659,7 @@ string_t AttrCursor::getStringWithContext() bool AttrCursor::getBool() { if (root->db) { - if (!cachedValue) - cachedValue = root->db->getAttr(getKey()); + fetchCachedValue(); if (cachedValue && !std::get_if(&cachedValue->second)) { if (auto b = std::get_if(&cachedValue->second)) { debug("using cached Boolean attribute '%s'", getAttrPathStr()); @@ -676,8 +680,7 @@ bool AttrCursor::getBool() NixInt AttrCursor::getInt() { if (root->db) { - if (!cachedValue) - cachedValue = root->db->getAttr(getKey()); + fetchCachedValue(); if (cachedValue && !std::get_if(&cachedValue->second)) { if (auto i = std::get_if(&cachedValue->second)) { debug("using cached integer attribute '%s'", getAttrPathStr()); @@ -698,8 +701,7 @@ NixInt AttrCursor::getInt() std::vector AttrCursor::getListOfStrings() { if (root->db) { - if (!cachedValue) - cachedValue = root->db->getAttr(getKey()); + fetchCachedValue(); if (cachedValue && !std::get_if(&cachedValue->second)) { if (auto l = std::get_if>(&cachedValue->second)) { debug("using cached list of strings attribute '%s'", getAttrPathStr()); @@ -731,8 +733,7 @@ std::vector AttrCursor::getListOfStrings() std::vector AttrCursor::getAttrs() { if (root->db) { - if (!cachedValue) - cachedValue = root->db->getAttr(getKey()); + fetchCachedValue(); if (cachedValue && !std::get_if(&cachedValue->second)) { if (auto attrs = std::get_if>(&cachedValue->second)) { debug("using cached attrset attribute '%s'", getAttrPathStr()); diff --git a/src/libexpr/eval-error.cc b/src/libexpr/eval-error.cc index b9742d3ea..2c8b6e325 100644 --- a/src/libexpr/eval-error.cc +++ b/src/libexpr/eval-error.cc @@ -1,6 +1,6 @@ -#include "eval-error.hh" -#include "eval.hh" -#include "value.hh" +#include "nix/expr/eval-error.hh" +#include "nix/expr/eval.hh" +#include "nix/expr/value.hh" namespace nix { diff --git a/src/libexpr/eval-gc.cc b/src/libexpr/eval-gc.cc index 07ce05a2c..bec668001 100644 --- a/src/libexpr/eval-gc.cc +++ b/src/libexpr/eval-gc.cc @@ -1,14 +1,16 @@ -#include "error.hh" -#include "environment-variables.hh" -#include "eval-settings.hh" -#include "config-global.hh" -#include "serialise.hh" -#include "eval-gc.hh" +#include "nix/util/error.hh" +#include "nix/util/environment-variables.hh" +#include "nix/expr/eval-settings.hh" +#include "nix/util/config-global.hh" +#include "nix/util/serialise.hh" +#include "nix/expr/eval-gc.hh" -#if HAVE_BOEHMGC +#include "expr-config-private.hh" + +#if NIX_USE_BOEHMGC # include -# if __FreeBSD__ +# ifdef __FreeBSD__ # include # endif @@ -24,7 +26,7 @@ namespace nix { -#if HAVE_BOEHMGC +#if NIX_USE_BOEHMGC /* Called when the Boehm GC runs out of memory. */ static void * oomHandler(size_t requested) { @@ -94,7 +96,7 @@ void initGC() if (gcInitialised) return; -#if HAVE_BOEHMGC +#if NIX_USE_BOEHMGC initGCReal(); gcCyclesAfterInit = GC_get_gc_no(); diff --git a/src/libexpr/eval-settings.cc b/src/libexpr/eval-settings.cc index ade0abf9a..659c01a9e 100644 --- a/src/libexpr/eval-settings.cc +++ b/src/libexpr/eval-settings.cc @@ -1,8 +1,8 @@ -#include "users.hh" -#include "globals.hh" -#include "profiles.hh" -#include "eval.hh" -#include "eval-settings.hh" +#include "nix/util/users.hh" +#include "nix/store/globals.hh" +#include "nix/store/profiles.hh" +#include "nix/expr/eval.hh" +#include "nix/expr/eval-settings.hh" namespace nix { @@ -103,4 +103,4 @@ Path getNixDefExpr() : getHome() + "/.nix-defexpr"; } -} +} // namespace nix \ No newline at end of file diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 9b9aabf7e..f095b393b 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -1,25 +1,26 @@ -#include "eval.hh" -#include "eval-settings.hh" -#include "primops.hh" -#include "print-options.hh" -#include "exit.hh" -#include "types.hh" -#include "util.hh" -#include "store-api.hh" -#include "derivations.hh" -#include "downstream-placeholder.hh" -#include "eval-inline.hh" -#include "filetransfer.hh" -#include "function-trace.hh" -#include "profiles.hh" -#include "print.hh" -#include "filtering-source-accessor.hh" -#include "memory-source-accessor.hh" -#include "mounted-source-accessor.hh" -#include "gc-small-vector.hh" -#include "url.hh" -#include "fetch-to-store.hh" -#include "tarball.hh" +#include "nix/expr/eval.hh" +#include "nix/expr/eval-settings.hh" +#include "nix/expr/primops.hh" +#include "nix/expr/print-options.hh" +#include "nix/util/exit.hh" +#include "nix/util/types.hh" +#include "nix/util/util.hh" +#include "nix/store/store-api.hh" +#include "nix/store/derivations.hh" +#include "nix/store/downstream-placeholder.hh" +#include "nix/expr/eval-inline.hh" +#include "nix/store/filetransfer.hh" +#include "nix/expr/function-trace.hh" +#include "nix/store/profiles.hh" +#include "nix/expr/print.hh" +#include "nix/fetchers/filtering-source-accessor.hh" +#include "nix/util/memory-source-accessor.hh" +#include "nix/util/mounted-source-accessor.hh" +#include "nix/expr/gc-small-vector.hh" +#include "nix/util/url.hh" +#include "nix/fetchers/fetch-to-store.hh" +#include "nix/fetchers/tarball.hh" + #include "parser-tab.hh" #include @@ -39,7 +40,7 @@ # include #endif -#include "strings-inline.hh" +#include "nix/util/strings-inline.hh" using json = nlohmann::json; @@ -290,17 +291,13 @@ EvalState::EvalState( CanonPath("derivation-internal.nix"), #include "primops/derivation.nix.gen.hh" )} - , callFlakeInternal{internalFS->addFile( - CanonPath("call-flake.nix"), - #include "call-flake.nix.gen.hh" - )} , store(store) , buildStore(buildStore ? buildStore : store) , debugRepl(nullptr) , debugStop(false) , trylevel(0) , regexCache(makeRegexCache()) -#if HAVE_BOEHMGC +#if NIX_USE_BOEHMGC , valueAllocCache(std::allocate_shared(traceable_allocator(), nullptr)) , env1AllocCache(std::allocate_shared(traceable_allocator(), nullptr)) , baseEnvP(std::allocate_shared(traceable_allocator(), &allocEnv(BASE_ENV_SIZE))) @@ -355,7 +352,7 @@ EvalState::EvalState( #include "fetchurl.nix.gen.hh" ); - createBaseEnv(); + createBaseEnv(settings); } @@ -2251,18 +2248,18 @@ std::string_view EvalState::forceString(Value & v, const PosIdx pos, std::string } -void copyContext(const Value & v, NixStringContext & context) +void copyContext(const Value & v, NixStringContext & context, const ExperimentalFeatureSettings & xpSettings) { if (v.payload.string.context) for (const char * * p = v.payload.string.context; *p; ++p) - context.insert(NixStringContextElem::parse(*p)); + context.insert(NixStringContextElem::parse(*p, xpSettings)); } -std::string_view EvalState::forceString(Value & v, NixStringContext & context, const PosIdx pos, std::string_view errorCtx) +std::string_view EvalState::forceString(Value & v, NixStringContext & context, const PosIdx pos, std::string_view errorCtx, const ExperimentalFeatureSettings & xpSettings) { auto s = forceString(v, pos, errorCtx); - copyContext(v, context); + copyContext(v, context, xpSettings); return s; } @@ -2468,10 +2465,10 @@ StorePath EvalState::coerceToStorePath(const PosIdx pos, Value & v, NixStringCon } -std::pair EvalState::coerceToSingleDerivedPathUnchecked(const PosIdx pos, Value & v, std::string_view errorCtx) +std::pair EvalState::coerceToSingleDerivedPathUnchecked(const PosIdx pos, Value & v, std::string_view errorCtx, const ExperimentalFeatureSettings & xpSettings) { NixStringContext context; - auto s = forceString(v, context, pos, errorCtx); + auto s = forceString(v, context, pos, errorCtx, xpSettings); auto csize = context.size(); if (csize != 1) error( @@ -2817,7 +2814,7 @@ bool EvalState::eqValues(Value & v1, Value & v2, const PosIdx pos, std::string_v } bool EvalState::fullGC() { -#if HAVE_BOEHMGC +#if NIX_USE_BOEHMGC GC_gcollect(); // Check that it ran. We might replace this with a version that uses more // of the boehm API to get this reliably, at a maintenance cost. @@ -2836,7 +2833,7 @@ void EvalState::maybePrintStats() if (showStats) { // Make the final heap size more deterministic. -#if HAVE_BOEHMGC +#if NIX_USE_BOEHMGC if (!fullGC()) { warn("failed to perform a full GC before reporting stats"); } @@ -2858,7 +2855,7 @@ void EvalState::printStatistics() uint64_t bValues = nrValues * sizeof(Value); uint64_t bAttrsets = nrAttrsets * sizeof(Bindings) + nrAttrsInAttrsets * sizeof(Attr); -#if HAVE_BOEHMGC +#if NIX_USE_BOEHMGC GC_word heapSize, totalBytes; GC_get_heap_usage_safe(&heapSize, 0, 0, 0, &totalBytes); double gcFullOnlyTime = ({ @@ -2880,7 +2877,7 @@ void EvalState::printStatistics() #ifndef _WIN32 // TODO implement {"cpu", cpuTime}, #endif -#if HAVE_BOEHMGC +#if NIX_USE_BOEHMGC {GC_is_incremental_mode() ? "gcNonIncremental" : "gc", gcFullOnlyTime}, #ifndef _WIN32 // TODO implement {GC_is_incremental_mode() ? "gcNonIncrementalFraction" : "gcFraction", gcFullOnlyTime / cpuTime}, @@ -2924,7 +2921,7 @@ void EvalState::printStatistics() topObj["nrLookups"] = nrLookups; topObj["nrPrimOpCalls"] = nrPrimOpCalls; topObj["nrFunctionCalls"] = nrFunctionCalls; -#if HAVE_BOEHMGC +#if NIX_USE_BOEHMGC topObj["gc"] = { {"heapSize", heapSize}, {"totalBytes", totalBytes}, diff --git a/src/libexpr/function-trace.cc b/src/libexpr/function-trace.cc index c6057b384..1dce51726 100644 --- a/src/libexpr/function-trace.cc +++ b/src/libexpr/function-trace.cc @@ -1,5 +1,5 @@ -#include "function-trace.hh" -#include "logging.hh" +#include "nix/expr/function-trace.hh" +#include "nix/util/logging.hh" namespace nix { diff --git a/src/libexpr/get-drvs.cc b/src/libexpr/get-drvs.cc index 1ac13fcd2..f15ad4d73 100644 --- a/src/libexpr/get-drvs.cc +++ b/src/libexpr/get-drvs.cc @@ -1,8 +1,8 @@ -#include "get-drvs.hh" -#include "eval-inline.hh" -#include "derivations.hh" -#include "store-api.hh" -#include "path-with-outputs.hh" +#include "nix/expr/get-drvs.hh" +#include "nix/expr/eval-inline.hh" +#include "nix/store/derivations.hh" +#include "nix/store/store-api.hh" +#include "nix/store/path-with-outputs.hh" #include #include diff --git a/src/libexpr/attr-path.hh b/src/libexpr/include/nix/expr/attr-path.hh similarity index 95% rename from src/libexpr/attr-path.hh rename to src/libexpr/include/nix/expr/attr-path.hh index eb00ffb93..66a3f4e00 100644 --- a/src/libexpr/attr-path.hh +++ b/src/libexpr/include/nix/expr/attr-path.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "eval.hh" +#include "nix/expr/eval.hh" #include #include diff --git a/src/libexpr/attr-set.hh b/src/libexpr/include/nix/expr/attr-set.hh similarity index 98% rename from src/libexpr/attr-set.hh rename to src/libexpr/include/nix/expr/attr-set.hh index 4df9a1acd..283786f4d 100644 --- a/src/libexpr/attr-set.hh +++ b/src/libexpr/include/nix/expr/attr-set.hh @@ -1,8 +1,8 @@ #pragma once ///@file -#include "nixexpr.hh" -#include "symbol-table.hh" +#include "nix/expr/nixexpr.hh" +#include "nix/expr/symbol-table.hh" #include diff --git a/src/libexpr/eval-cache.hh b/src/libexpr/include/nix/expr/eval-cache.hh similarity index 88% rename from src/libexpr/eval-cache.hh rename to src/libexpr/include/nix/expr/eval-cache.hh index b1911e3a4..31873f7a3 100644 --- a/src/libexpr/eval-cache.hh +++ b/src/libexpr/include/nix/expr/eval-cache.hh @@ -1,9 +1,9 @@ #pragma once ///@file -#include "sync.hh" -#include "hash.hh" -#include "eval.hh" +#include "nix/util/sync.hh" +#include "nix/util/hash.hh" +#include "nix/expr/eval.hh" #include #include @@ -90,7 +90,7 @@ class AttrCursor : public std::enable_shared_from_this friend struct CachedEvalError; ref root; - typedef std::optional, Symbol>> Parent; + using Parent = std::optional, Symbol>>; Parent parent; RootValue _value; std::optional> cachedValue; @@ -99,6 +99,14 @@ class AttrCursor : public std::enable_shared_from_this Value & getValue(); + /** + * If `cachedValue` is unset, try to initialize it from the + * database. It is not an error if it does not exist. Throw a + * `CachedEvalError` exception if it does exist but has type + * `AttrType::Failed`. + */ + void fetchCachedValue(); + public: AttrCursor( diff --git a/src/libexpr/eval-error.hh b/src/libexpr/include/nix/expr/eval-error.hh similarity index 98% rename from src/libexpr/eval-error.hh rename to src/libexpr/include/nix/expr/eval-error.hh index ed004eb53..ae4f40689 100644 --- a/src/libexpr/eval-error.hh +++ b/src/libexpr/include/nix/expr/eval-error.hh @@ -1,7 +1,7 @@ #pragma once -#include "error.hh" -#include "pos-idx.hh" +#include "nix/util/error.hh" +#include "nix/util/pos-idx.hh" namespace nix { diff --git a/src/libexpr/eval-gc.hh b/src/libexpr/include/nix/expr/eval-gc.hh similarity index 84% rename from src/libexpr/eval-gc.hh rename to src/libexpr/include/nix/expr/eval-gc.hh index f3b699b54..25144d40c 100644 --- a/src/libexpr/eval-gc.hh +++ b/src/libexpr/include/nix/expr/eval-gc.hh @@ -3,7 +3,10 @@ #include -#if HAVE_BOEHMGC +// For `NIX_USE_BOEHMGC`, and if that's set, `GC_THREADS` +#include "nix/expr/config.hh" + +#if NIX_USE_BOEHMGC # define GC_INCLUDE_NEW @@ -43,7 +46,7 @@ void initGC(); */ void assertGCInitialized(); -#ifdef HAVE_BOEHMGC +#if NIX_USE_BOEHMGC /** * The number of GC cycles since initGC(). */ diff --git a/src/libexpr/eval-inline.hh b/src/libexpr/include/nix/expr/eval-inline.hh similarity index 93% rename from src/libexpr/eval-inline.hh rename to src/libexpr/include/nix/expr/eval-inline.hh index 5d1a0c4d6..6e5759c0b 100644 --- a/src/libexpr/eval-inline.hh +++ b/src/libexpr/include/nix/expr/eval-inline.hh @@ -1,10 +1,13 @@ #pragma once ///@file -#include "print.hh" -#include "eval.hh" -#include "eval-error.hh" -#include "eval-settings.hh" +#include "nix/expr/print.hh" +#include "nix/expr/eval.hh" +#include "nix/expr/eval-error.hh" +#include "nix/expr/eval-settings.hh" + +// For `NIX_USE_BOEHMGC`, and if that's set, `GC_THREADS` +#include "nix/expr/config.hh" namespace nix { @@ -15,7 +18,7 @@ namespace nix { inline void * allocBytes(size_t n) { void * p; -#if HAVE_BOEHMGC +#if NIX_USE_BOEHMGC p = GC_MALLOC(n); #else p = calloc(n, 1); @@ -28,7 +31,7 @@ inline void * allocBytes(size_t n) [[gnu::always_inline]] Value * EvalState::allocValue() { -#if HAVE_BOEHMGC +#if NIX_USE_BOEHMGC /* We use the boehm batch allocator to speed up allocations of Values (of which there are many). GC_malloc_many returns a linked list of objects of the given size, where the first word of each object is also the pointer to the next object in the list. This also means that we @@ -60,7 +63,7 @@ Env & EvalState::allocEnv(size_t size) Env * env; -#if HAVE_BOEHMGC +#if NIX_USE_BOEHMGC if (size == 1) { /* see allocValue for explanations. */ if (!*env1AllocCache) { diff --git a/src/libexpr/eval-settings.hh b/src/libexpr/include/nix/expr/eval-settings.hh similarity index 98% rename from src/libexpr/eval-settings.hh rename to src/libexpr/include/nix/expr/eval-settings.hh index 3f8383dd6..fb482568a 100644 --- a/src/libexpr/eval-settings.hh +++ b/src/libexpr/include/nix/expr/eval-settings.hh @@ -1,12 +1,13 @@ #pragma once ///@file -#include "config.hh" -#include "source-path.hh" +#include "nix/util/configuration.hh" +#include "nix/util/source-path.hh" namespace nix { class EvalState; +struct PrimOp; struct EvalSettings : Config { @@ -50,6 +51,8 @@ struct EvalSettings : Config LookupPathHooks lookupPathHooks; + std::vector extraPrimOps; + Setting enableNativeCode{this, false, "allow-unsafe-native-code-during-evaluation", R"( Enable built-in functions that allow executing native code. diff --git a/src/libexpr/eval.hh b/src/libexpr/include/nix/expr/eval.hh similarity index 96% rename from src/libexpr/eval.hh rename to src/libexpr/include/nix/expr/eval.hh index 4ae73de57..9623c2a9c 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/include/nix/expr/eval.hh @@ -1,20 +1,23 @@ #pragma once ///@file -#include "attr-set.hh" -#include "eval-error.hh" -#include "types.hh" -#include "value.hh" -#include "nixexpr.hh" -#include "symbol-table.hh" -#include "config.hh" -#include "experimental-features.hh" -#include "position.hh" -#include "pos-table.hh" -#include "source-accessor.hh" -#include "search-path.hh" -#include "repl-exit-status.hh" -#include "ref.hh" +#include "nix/expr/attr-set.hh" +#include "nix/expr/eval-error.hh" +#include "nix/util/types.hh" +#include "nix/expr/value.hh" +#include "nix/expr/nixexpr.hh" +#include "nix/expr/symbol-table.hh" +#include "nix/util/configuration.hh" +#include "nix/util/experimental-features.hh" +#include "nix/util/position.hh" +#include "nix/util/pos-table.hh" +#include "nix/util/source-accessor.hh" +#include "nix/expr/search-path.hh" +#include "nix/expr/repl-exit-status.hh" +#include "nix/util/ref.hh" + +// For `NIX_USE_BOEHMGC`, and if that's set, `GC_THREADS` +#include "nix/expr/config.hh" #include #include @@ -160,7 +163,7 @@ void printEnvBindings(const SymbolTable & st, const StaticEnv & se, const Env & std::unique_ptr mapStaticEnvBindings(const SymbolTable & st, const StaticEnv & se, const Env & env); -void copyContext(const Value & v, NixStringContext & context); +void copyContext(const Value & v, NixStringContext & context, const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings); std::string printValue(EvalState & state, Value & v); @@ -280,14 +283,12 @@ public: /** * In-memory filesystem for internal, non-user-callable Nix - * expressions like call-flake.nix. + * expressions like `derivation.nix`. */ const ref internalFS; const SourcePath derivationInternal; - const SourcePath callFlakeInternal; - /** * Store used to materialise .drv files. */ @@ -377,7 +378,7 @@ private: */ std::shared_ptr regexCache; -#if HAVE_BOEHMGC +#if NIX_USE_BOEHMGC /** * Allocation cache for GC'd Value objects. */ @@ -533,7 +534,7 @@ public: */ void forceFunction(Value & v, const PosIdx pos, std::string_view errorCtx); std::string_view forceString(Value & v, const PosIdx pos, std::string_view errorCtx); - std::string_view forceString(Value & v, NixStringContext & context, const PosIdx pos, std::string_view errorCtx); + std::string_view forceString(Value & v, NixStringContext & context, const PosIdx pos, std::string_view errorCtx, const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings); std::string_view forceStringNoCtx(Value & v, const PosIdx pos, std::string_view errorCtx); template @@ -585,7 +586,7 @@ public: /** * Part of `coerceToSingleDerivedPath()` without any store IO which is exposed for unit testing only. */ - std::pair coerceToSingleDerivedPathUnchecked(const PosIdx pos, Value & v, std::string_view errorCtx); + std::pair coerceToSingleDerivedPathUnchecked(const PosIdx pos, Value & v, std::string_view errorCtx, const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings); /** * Coerce to `SingleDerivedPath`. @@ -604,7 +605,7 @@ public: */ SingleDerivedPath coerceToSingleDerivedPath(const PosIdx pos, Value & v, std::string_view errorCtx); -#if HAVE_BOEHMGC +#if NIX_USE_BOEHMGC /** A GC root for the baseEnv reference. */ std::shared_ptr baseEnvP; #endif @@ -639,7 +640,7 @@ private: unsigned int baseEnvDispl = 0; - void createBaseEnv(); + void createBaseEnv(const EvalSettings & settings); Value * addConstant(const std::string & name, Value & v, Constant info); @@ -952,4 +953,4 @@ bool isAllowedURI(std::string_view uri, const Strings & allowedPaths); } -#include "eval-inline.hh" +#include "nix/expr/eval-inline.hh" diff --git a/src/libexpr/function-trace.hh b/src/libexpr/include/nix/expr/function-trace.hh similarity index 86% rename from src/libexpr/function-trace.hh rename to src/libexpr/include/nix/expr/function-trace.hh index 91439b0aa..dc92d4b5c 100644 --- a/src/libexpr/function-trace.hh +++ b/src/libexpr/include/nix/expr/function-trace.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "eval.hh" +#include "nix/expr/eval.hh" #include diff --git a/src/libexpr/gc-small-vector.hh b/src/libexpr/include/nix/expr/gc-small-vector.hh similarity index 95% rename from src/libexpr/gc-small-vector.hh rename to src/libexpr/include/nix/expr/gc-small-vector.hh index 8330dd2dc..ad4503de7 100644 --- a/src/libexpr/gc-small-vector.hh +++ b/src/libexpr/include/nix/expr/gc-small-vector.hh @@ -2,7 +2,7 @@ #include -#include "value.hh" +#include "nix/expr/value.hh" namespace nix { diff --git a/src/libexpr/get-drvs.hh b/src/libexpr/include/nix/expr/get-drvs.hh similarity index 97% rename from src/libexpr/get-drvs.hh rename to src/libexpr/include/nix/expr/get-drvs.hh index e4e277af8..0787c44a8 100644 --- a/src/libexpr/get-drvs.hh +++ b/src/libexpr/include/nix/expr/get-drvs.hh @@ -1,8 +1,8 @@ #pragma once ///@file -#include "eval.hh" -#include "path.hh" +#include "nix/expr/eval.hh" +#include "nix/store/path.hh" #include #include diff --git a/src/libexpr/json-to-value.hh b/src/libexpr/include/nix/expr/json-to-value.hh similarity index 87% rename from src/libexpr/json-to-value.hh rename to src/libexpr/include/nix/expr/json-to-value.hh index 3c8fa5cc0..b01d63bfe 100644 --- a/src/libexpr/json-to-value.hh +++ b/src/libexpr/include/nix/expr/json-to-value.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "error.hh" +#include "nix/util/error.hh" #include diff --git a/src/libexpr/lexer-helpers.hh b/src/libexpr/include/nix/expr/lexer-helpers.hh similarity index 100% rename from src/libexpr/lexer-helpers.hh rename to src/libexpr/include/nix/expr/lexer-helpers.hh diff --git a/src/libexpr/include/nix/expr/meson.build b/src/libexpr/include/nix/expr/meson.build new file mode 100644 index 000000000..01275e52e --- /dev/null +++ b/src/libexpr/include/nix/expr/meson.build @@ -0,0 +1,37 @@ +# Public headers directory + +include_dirs = [include_directories('../..')] + +config_pub_h = configure_file( + configuration : configdata_pub, + output : 'config.hh', +) + +headers = [config_pub_h] + files( + 'attr-path.hh', + 'attr-set.hh', + 'eval-cache.hh', + 'eval-error.hh', + 'eval-gc.hh', + 'eval-inline.hh', + 'eval-settings.hh', + 'eval.hh', + 'function-trace.hh', + 'gc-small-vector.hh', + 'get-drvs.hh', + 'json-to-value.hh', + # internal: 'lexer-helpers.hh', + 'nixexpr.hh', + 'parser-state.hh', + 'primops.hh', + 'print-ambiguous.hh', + 'print-options.hh', + 'print.hh', + 'repl-exit-status.hh', + 'search-path.hh', + 'symbol-table.hh', + 'value-to-json.hh', + 'value-to-xml.hh', + 'value.hh', + 'value/context.hh', +) diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/include/nix/expr/nixexpr.hh similarity index 99% rename from src/libexpr/nixexpr.hh rename to src/libexpr/include/nix/expr/nixexpr.hh index 88ebc80f8..9409bdca8 100644 --- a/src/libexpr/nixexpr.hh +++ b/src/libexpr/include/nix/expr/nixexpr.hh @@ -4,10 +4,10 @@ #include #include -#include "value.hh" -#include "symbol-table.hh" -#include "eval-error.hh" -#include "pos-idx.hh" +#include "nix/expr/value.hh" +#include "nix/expr/symbol-table.hh" +#include "nix/expr/eval-error.hh" +#include "nix/util/pos-idx.hh" namespace nix { diff --git a/src/libexpr/parser-state.hh b/src/libexpr/include/nix/expr/parser-state.hh similarity index 99% rename from src/libexpr/parser-state.hh rename to src/libexpr/include/nix/expr/parser-state.hh index 21a880e8e..0505913d0 100644 --- a/src/libexpr/parser-state.hh +++ b/src/libexpr/include/nix/expr/parser-state.hh @@ -3,7 +3,7 @@ #include -#include "eval.hh" +#include "nix/expr/eval.hh" namespace nix { diff --git a/src/libexpr/primops.hh b/src/libexpr/include/nix/expr/primops.hh similarity index 98% rename from src/libexpr/primops.hh rename to src/libexpr/include/nix/expr/primops.hh index 9f76975db..f0742a138 100644 --- a/src/libexpr/primops.hh +++ b/src/libexpr/include/nix/expr/primops.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "eval.hh" +#include "nix/expr/eval.hh" #include #include diff --git a/src/libexpr/print-ambiguous.hh b/src/libexpr/include/nix/expr/print-ambiguous.hh similarity index 95% rename from src/libexpr/print-ambiguous.hh rename to src/libexpr/include/nix/expr/print-ambiguous.hh index 50c260a9b..09a849c49 100644 --- a/src/libexpr/print-ambiguous.hh +++ b/src/libexpr/include/nix/expr/print-ambiguous.hh @@ -1,6 +1,6 @@ #pragma once -#include "value.hh" +#include "nix/expr/value.hh" namespace nix { diff --git a/src/libexpr/print-options.hh b/src/libexpr/include/nix/expr/print-options.hh similarity index 100% rename from src/libexpr/print-options.hh rename to src/libexpr/include/nix/expr/print-options.hh diff --git a/src/libexpr/print.hh b/src/libexpr/include/nix/expr/print.hh similarity index 97% rename from src/libexpr/print.hh rename to src/libexpr/include/nix/expr/print.hh index 7ddda81b8..ac9bf23a4 100644 --- a/src/libexpr/print.hh +++ b/src/libexpr/include/nix/expr/print.hh @@ -9,8 +9,8 @@ #include -#include "fmt.hh" -#include "print-options.hh" +#include "nix/util/fmt.hh" +#include "nix/expr/print-options.hh" namespace nix { diff --git a/src/libexpr/repl-exit-status.hh b/src/libexpr/include/nix/expr/repl-exit-status.hh similarity index 100% rename from src/libexpr/repl-exit-status.hh rename to src/libexpr/include/nix/expr/repl-exit-status.hh diff --git a/src/libexpr/search-path.hh b/src/libexpr/include/nix/expr/search-path.hh similarity index 97% rename from src/libexpr/search-path.hh rename to src/libexpr/include/nix/expr/search-path.hh index acd843638..202527fd2 100644 --- a/src/libexpr/search-path.hh +++ b/src/libexpr/include/nix/expr/search-path.hh @@ -3,8 +3,8 @@ #include -#include "types.hh" -#include "comparator.hh" +#include "nix/util/types.hh" +#include "nix/util/comparator.hh" namespace nix { diff --git a/src/libexpr/symbol-table.hh b/src/libexpr/include/nix/expr/symbol-table.hh similarity index 97% rename from src/libexpr/symbol-table.hh rename to src/libexpr/include/nix/expr/symbol-table.hh index be12f6248..018465bf5 100644 --- a/src/libexpr/symbol-table.hh +++ b/src/libexpr/include/nix/expr/symbol-table.hh @@ -5,9 +5,9 @@ #include #include -#include "types.hh" -#include "chunked-vector.hh" -#include "error.hh" +#include "nix/util/types.hh" +#include "nix/util/chunked-vector.hh" +#include "nix/util/error.hh" namespace nix { diff --git a/src/libexpr/value-to-json.hh b/src/libexpr/include/nix/expr/value-to-json.hh similarity index 88% rename from src/libexpr/value-to-json.hh rename to src/libexpr/include/nix/expr/value-to-json.hh index 867c4e3a8..1a6911347 100644 --- a/src/libexpr/value-to-json.hh +++ b/src/libexpr/include/nix/expr/value-to-json.hh @@ -1,8 +1,8 @@ #pragma once ///@file -#include "nixexpr.hh" -#include "eval.hh" +#include "nix/expr/nixexpr.hh" +#include "nix/expr/eval.hh" #include #include diff --git a/src/libexpr/value-to-xml.hh b/src/libexpr/include/nix/expr/value-to-xml.hh similarity index 79% rename from src/libexpr/value-to-xml.hh rename to src/libexpr/include/nix/expr/value-to-xml.hh index 6d702c0f2..e22325de5 100644 --- a/src/libexpr/value-to-xml.hh +++ b/src/libexpr/include/nix/expr/value-to-xml.hh @@ -1,8 +1,8 @@ #pragma once ///@file -#include "nixexpr.hh" -#include "eval.hh" +#include "nix/expr/nixexpr.hh" +#include "nix/expr/eval.hh" #include #include diff --git a/src/libexpr/value.hh b/src/libexpr/include/nix/expr/value.hh similarity index 98% rename from src/libexpr/value.hh rename to src/libexpr/include/nix/expr/value.hh index 8925693e3..e9cc1cd3f 100644 --- a/src/libexpr/value.hh +++ b/src/libexpr/include/nix/expr/value.hh @@ -4,12 +4,12 @@ #include #include -#include "eval-gc.hh" -#include "symbol-table.hh" -#include "value/context.hh" -#include "source-path.hh" -#include "print-options.hh" -#include "checked-arithmetic.hh" +#include "nix/expr/eval-gc.hh" +#include "nix/expr/symbol-table.hh" +#include "nix/expr/value/context.hh" +#include "nix/util/source-path.hh" +#include "nix/expr/print-options.hh" +#include "nix/util/checked-arithmetic.hh" #include diff --git a/src/libexpr/value/context.hh b/src/libexpr/include/nix/expr/value/context.hh similarity index 94% rename from src/libexpr/value/context.hh rename to src/libexpr/include/nix/expr/value/context.hh index d6791c6e4..f2de184ea 100644 --- a/src/libexpr/value/context.hh +++ b/src/libexpr/include/nix/expr/value/context.hh @@ -1,9 +1,9 @@ #pragma once ///@file -#include "comparator.hh" -#include "derived-path.hh" -#include "variant-wrapper.hh" +#include "nix/util/comparator.hh" +#include "nix/store/derived-path.hh" +#include "nix/util/variant-wrapper.hh" #include diff --git a/src/libexpr/json-to-value.cc b/src/libexpr/json-to-value.cc index 17cab7ad5..e38ac7db4 100644 --- a/src/libexpr/json-to-value.cc +++ b/src/libexpr/json-to-value.cc @@ -1,6 +1,6 @@ -#include "json-to-value.hh" -#include "value.hh" -#include "eval.hh" +#include "nix/expr/json-to-value.hh" +#include "nix/expr/value.hh" +#include "nix/expr/eval.hh" #include #include diff --git a/src/libexpr/lexer-helpers.cc b/src/libexpr/lexer-helpers.cc index d9eeb73e2..4b27393bb 100644 --- a/src/libexpr/lexer-helpers.cc +++ b/src/libexpr/lexer-helpers.cc @@ -1,7 +1,8 @@ #include "lexer-tab.hh" -#include "lexer-helpers.hh" #include "parser-tab.hh" +#include "nix/expr/lexer-helpers.hh" + void nix::lexer::internal::initLoc(YYLTYPE * loc) { loc->beginOffset = loc->endOffset = 0; diff --git a/src/libexpr/lexer.l b/src/libexpr/lexer.l index 067f86e01..511c8e47b 100644 --- a/src/libexpr/lexer.l +++ b/src/libexpr/lexer.l @@ -16,7 +16,7 @@ %top { #include "parser-tab.hh" // YYSTYPE -#include "parser-state.hh" +#include "nix/expr/parser-state.hh" } %{ @@ -24,9 +24,9 @@ #pragma clang diagnostic ignored "-Wunneeded-internal-declaration" #endif -#include "nixexpr.hh" +#include "nix/expr/nixexpr.hh" #include "parser-tab.hh" -#include "lexer-helpers.hh" +#include "nix/expr/lexer-helpers.hh" namespace nix { struct LexerState; diff --git a/src/libexpr/meson.build b/src/libexpr/meson.build index dffcc1742..2e773938d 100644 --- a/src/libexpr/meson.build +++ b/src/libexpr/meson.build @@ -14,7 +14,8 @@ cxx = meson.get_compiler('cpp') subdir('nix-meson-build-support/deps-lists') -configdata = configuration_data() +configdata_pub = configuration_data() +configdata_priv = configuration_data() deps_private_maybe_subproject = [ ] @@ -26,6 +27,16 @@ deps_public_maybe_subproject = [ subdir('nix-meson-build-support/subprojects') subdir('nix-meson-build-support/big-objs') +# Check for each of these functions, and create a define like `#define HAVE_LCHOWN 1`. +check_funcs = [ + 'sysconf', +] +foreach funcspec : check_funcs + define_name = 'HAVE_' + funcspec.underscorify().to_upper() + define_value = cxx.has_function(funcspec).to_int() + configdata_priv.set(define_name, define_value) +endforeach + boost = dependency( 'boost', modules : ['container', 'context'], @@ -47,11 +58,13 @@ if bdw_gc.found() ] define_name = 'HAVE_' + funcspec.underscorify().to_upper() define_value = cxx.has_function(funcspec).to_int() - configdata.set(define_name, define_value) + configdata_priv.set(define_name, define_value) endforeach - configdata.set('GC_THREADS', 1) + # Affects ABI, because it changes what bdw_gc itself does! + configdata_pub.set('GC_THREADS', 1) endif -configdata.set('HAVE_BOEHMGC', bdw_gc.found().to_int()) +# Used in public header. Affects ABI! +configdata_pub.set('NIX_USE_BOEHMGC', bdw_gc.found().to_int()) toml11 = dependency( 'toml11', @@ -61,19 +74,9 @@ toml11 = dependency( ) deps_other += toml11 -config_h = configure_file( - configuration : configdata, - output : 'config-expr.hh', -) - -add_project_arguments( - # TODO(Qyriad): Yes this is how the autoconf+Make system did it. - # It would be nice for our headers to be idempotent instead. - '-include', 'config-util.hh', - '-include', 'config-store.hh', - # '-include', 'config-fetchers.h', - '-include', 'config-expr.hh', - language : 'cpp', +config_priv_h = configure_file( + configuration : configdata_priv, + output : 'expr-config-private.hh', ) subdir('nix-meson-build-support/common') @@ -126,7 +129,6 @@ generated_headers = [] foreach header : [ 'imported-drv-to-derivation.nix', 'fetchurl.nix', - 'call-flake.nix', ] generated_headers += gen_header.process(header) endforeach @@ -154,51 +156,28 @@ sources = files( 'value/context.cc', ) -include_dirs = [include_directories('.')] - -headers = [config_h] + files( - 'attr-path.hh', - 'attr-set.hh', - 'eval-cache.hh', - 'eval-error.hh', - 'eval-gc.hh', - 'eval-inline.hh', - 'eval-settings.hh', - 'eval.hh', - 'function-trace.hh', - 'gc-small-vector.hh', - 'get-drvs.hh', - 'json-to-value.hh', - # internal: 'lexer-helpers.hh', - 'nixexpr.hh', - 'parser-state.hh', - 'primops.hh', - 'print-ambiguous.hh', - 'print-options.hh', - 'print.hh', - 'repl-exit-status.hh', - 'search-path.hh', - 'symbol-table.hh', - 'value-to-json.hh', - 'value-to-xml.hh', - 'value.hh', - 'value/context.hh', -) +subdir('include/nix/expr') subdir('primops') +subdir('nix-meson-build-support/export-all-symbols') +subdir('nix-meson-build-support/windows-version') + this_library = library( 'nixexpr', sources, + config_priv_h, parser_tab, lexer_tab, generated_headers, dependencies : deps_public + deps_private + deps_other, + include_directories : include_dirs, + link_args: linker_export_flags, prelink : true, # For C++ static initializers install : true, ) -install_headers(headers, subdir : 'nix', preserve_path : true) +install_headers(headers, subdir : 'nix/expr', preserve_path : true) libraries_private = [] diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index f17226728..1a71096d4 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -1,13 +1,13 @@ -#include "nixexpr.hh" -#include "eval.hh" -#include "symbol-table.hh" -#include "util.hh" -#include "print.hh" +#include "nix/expr/nixexpr.hh" +#include "nix/expr/eval.hh" +#include "nix/expr/symbol-table.hh" +#include "nix/util/util.hh" +#include "nix/expr/print.hh" #include #include -#include "strings-inline.hh" +#include "nix/util/strings-inline.hh" namespace nix { diff --git a/src/libexpr/package.nix b/src/libexpr/package.nix index 309d57f9b..7e0041617 100644 --- a/src/libexpr/package.nix +++ b/src/libexpr/package.nix @@ -48,6 +48,7 @@ mkMesonLibrary (finalAttrs: { ./meson.build ./meson.options ./primops/meson.build + ./include/nix/expr/meson.build (fileset.fileFilter (file: file.hasExt "cc") ./.) (fileset.fileFilter (file: file.hasExt "hh") ./.) ./lexer.l @@ -81,13 +82,6 @@ mkMesonLibrary (finalAttrs: { (lib.mesonEnable "gc" enableGC) ]; - env = { - # Needed for Meson to find Boost. - # https://github.com/NixOS/nixpkgs/issues/86131. - BOOST_INCLUDEDIR = "${lib.getDev boost}/include"; - BOOST_LIBRARYDIR = "${lib.getLib boost}/lib"; - }; - meta = { platforms = lib.platforms.unix ++ lib.platforms.windows; }; diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y index bde721401..99cc687cc 100644 --- a/src/libexpr/parser.y +++ b/src/libexpr/parser.y @@ -17,14 +17,14 @@ #include -#include "finally.hh" -#include "util.hh" -#include "users.hh" +#include "nix/util/finally.hh" +#include "nix/util/util.hh" +#include "nix/util/users.hh" -#include "nixexpr.hh" -#include "eval.hh" -#include "eval-settings.hh" -#include "parser-state.hh" +#include "nix/expr/nixexpr.hh" +#include "nix/expr/eval.hh" +#include "nix/expr/eval-settings.hh" +#include "nix/expr/parser-state.hh" // Bison seems to have difficulty growing the parser stack when using C++ with // a custom location type. This undocumented macro tells Bison that our @@ -514,7 +514,7 @@ formal %% -#include "eval.hh" +#include "nix/expr/eval.hh" namespace nix { diff --git a/src/libexpr/paths.cc b/src/libexpr/paths.cc index 3d602ae2d..c5107de3a 100644 --- a/src/libexpr/paths.cc +++ b/src/libexpr/paths.cc @@ -1,5 +1,5 @@ -#include "store-api.hh" -#include "eval.hh" +#include "nix/store/store-api.hh" +#include "nix/expr/eval.hh" namespace nix { diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 54682ea31..47f048aef 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -1,19 +1,19 @@ -#include "derivations.hh" -#include "downstream-placeholder.hh" -#include "eval-inline.hh" -#include "eval.hh" -#include "eval-settings.hh" -#include "gc-small-vector.hh" -#include "json-to-value.hh" -#include "names.hh" -#include "path-references.hh" -#include "store-api.hh" -#include "util.hh" -#include "processes.hh" -#include "value-to-json.hh" -#include "value-to-xml.hh" -#include "primops.hh" -#include "fetch-to-store.hh" +#include "nix/store/derivations.hh" +#include "nix/store/downstream-placeholder.hh" +#include "nix/expr/eval-inline.hh" +#include "nix/expr/eval.hh" +#include "nix/expr/eval-settings.hh" +#include "nix/expr/gc-small-vector.hh" +#include "nix/expr/json-to-value.hh" +#include "nix/store/names.hh" +#include "nix/store/path-references.hh" +#include "nix/store/store-api.hh" +#include "nix/util/util.hh" +#include "nix/util/processes.hh" +#include "nix/expr/value-to-json.hh" +#include "nix/expr/value-to-xml.hh" +#include "nix/expr/primops.hh" +#include "nix/fetchers/fetch-to-store.hh" #include #include @@ -4669,7 +4669,7 @@ RegisterPrimOp::RegisterPrimOp(PrimOp && primOp) } -void EvalState::createBaseEnv() +void EvalState::createBaseEnv(const EvalSettings & evalSettings) { baseEnv.up = 0; @@ -4928,6 +4928,12 @@ void EvalState::createBaseEnv() addPrimOp(std::move(primOpAdjusted)); } + for (auto & primOp : evalSettings.extraPrimOps) { + auto primOpAdjusted = primOp; + primOpAdjusted.arity = std::max(primOp.args.size(), primOp.arity); + addPrimOp(std::move(primOpAdjusted)); + } + /* Add a wrapper around the derivation primop that computes the `drvPath' and `outPath' attributes lazily. diff --git a/src/libexpr/primops/context.cc b/src/libexpr/primops/context.cc index ede7d97ba..6a7284e05 100644 --- a/src/libexpr/primops/context.cc +++ b/src/libexpr/primops/context.cc @@ -1,7 +1,7 @@ -#include "primops.hh" -#include "eval-inline.hh" -#include "derivations.hh" -#include "store-api.hh" +#include "nix/expr/primops.hh" +#include "nix/expr/eval-inline.hh" +#include "nix/store/derivations.hh" +#include "nix/store/store-api.hh" namespace nix { diff --git a/src/libexpr/primops/fetchClosure.cc b/src/libexpr/primops/fetchClosure.cc index 04b8d0595..d28680ae5 100644 --- a/src/libexpr/primops/fetchClosure.cc +++ b/src/libexpr/primops/fetchClosure.cc @@ -1,8 +1,8 @@ -#include "primops.hh" -#include "store-api.hh" -#include "realisation.hh" -#include "make-content-addressed.hh" -#include "url.hh" +#include "nix/expr/primops.hh" +#include "nix/store/store-api.hh" +#include "nix/store/realisation.hh" +#include "nix/store/make-content-addressed.hh" +#include "nix/util/url.hh" namespace nix { diff --git a/src/libexpr/primops/fetchMercurial.cc b/src/libexpr/primops/fetchMercurial.cc index 96800d9ef..843beb4d1 100644 --- a/src/libexpr/primops/fetchMercurial.cc +++ b/src/libexpr/primops/fetchMercurial.cc @@ -1,10 +1,10 @@ -#include "primops.hh" -#include "eval-inline.hh" -#include "eval-settings.hh" -#include "store-api.hh" -#include "fetchers.hh" -#include "url.hh" -#include "url-parts.hh" +#include "nix/expr/primops.hh" +#include "nix/expr/eval-inline.hh" +#include "nix/expr/eval-settings.hh" +#include "nix/store/store-api.hh" +#include "nix/fetchers/fetchers.hh" +#include "nix/util/url.hh" +#include "nix/util/url-parts.hh" namespace nix { diff --git a/src/libexpr/primops/fetchTree.cc b/src/libexpr/primops/fetchTree.cc index f5ca5fd3e..e16dde12c 100644 --- a/src/libexpr/primops/fetchTree.cc +++ b/src/libexpr/primops/fetchTree.cc @@ -1,16 +1,16 @@ -#include "attrs.hh" -#include "primops.hh" -#include "eval-inline.hh" -#include "eval-settings.hh" -#include "store-api.hh" -#include "fetchers.hh" -#include "filetransfer.hh" -#include "registry.hh" -#include "tarball.hh" -#include "url.hh" -#include "value-to-json.hh" -#include "fetch-to-store.hh" -#include "mounted-source-accessor.hh" +#include "nix/fetchers/attrs.hh" +#include "nix/expr/primops.hh" +#include "nix/expr/eval-inline.hh" +#include "nix/expr/eval-settings.hh" +#include "nix/store/store-api.hh" +#include "nix/fetchers/fetchers.hh" +#include "nix/store/filetransfer.hh" +#include "nix/fetchers/registry.hh" +#include "nix/fetchers/tarball.hh" +#include "nix/util/url.hh" +#include "nix/expr/value-to-json.hh" +#include "nix/fetchers/fetch-to-store.hh" +#include "nix/util/mounted-source-accessor.hh" #include diff --git a/src/libexpr/primops/fromTOML.cc b/src/libexpr/primops/fromTOML.cc index 404425054..2a29e0424 100644 --- a/src/libexpr/primops/fromTOML.cc +++ b/src/libexpr/primops/fromTOML.cc @@ -1,5 +1,5 @@ -#include "primops.hh" -#include "eval-inline.hh" +#include "nix/expr/primops.hh" +#include "nix/expr/eval-inline.hh" #include diff --git a/src/libexpr/print-ambiguous.cc b/src/libexpr/print-ambiguous.cc index a40c98643..0646783c2 100644 --- a/src/libexpr/print-ambiguous.cc +++ b/src/libexpr/print-ambiguous.cc @@ -1,7 +1,7 @@ -#include "print-ambiguous.hh" -#include "print.hh" -#include "signals.hh" -#include "eval.hh" +#include "nix/expr/print-ambiguous.hh" +#include "nix/expr/print.hh" +#include "nix/util/signals.hh" +#include "nix/expr/eval.hh" namespace nix { diff --git a/src/libexpr/print.cc b/src/libexpr/print.cc index d62aaf25f..06bae9c5c 100644 --- a/src/libexpr/print.cc +++ b/src/libexpr/print.cc @@ -2,13 +2,13 @@ #include #include -#include "print.hh" -#include "ansicolor.hh" -#include "signals.hh" -#include "store-api.hh" -#include "terminal.hh" -#include "english.hh" -#include "eval.hh" +#include "nix/expr/print.hh" +#include "nix/util/ansicolor.hh" +#include "nix/util/signals.hh" +#include "nix/store/store-api.hh" +#include "nix/util/terminal.hh" +#include "nix/util/english.hh" +#include "nix/expr/eval.hh" namespace nix { diff --git a/src/libexpr/search-path.cc b/src/libexpr/search-path.cc index 657744e74..76aecd4e5 100644 --- a/src/libexpr/search-path.cc +++ b/src/libexpr/search-path.cc @@ -1,4 +1,4 @@ -#include "search-path.hh" +#include "nix/expr/search-path.hh" namespace nix { diff --git a/src/libexpr/value-to-json.cc b/src/libexpr/value-to-json.cc index 5aa4fe4fd..51652db1f 100644 --- a/src/libexpr/value-to-json.cc +++ b/src/libexpr/value-to-json.cc @@ -1,7 +1,7 @@ -#include "value-to-json.hh" -#include "eval-inline.hh" -#include "store-api.hh" -#include "signals.hh" +#include "nix/expr/value-to-json.hh" +#include "nix/expr/eval-inline.hh" +#include "nix/store/store-api.hh" +#include "nix/util/signals.hh" #include #include diff --git a/src/libexpr/value-to-xml.cc b/src/libexpr/value-to-xml.cc index 9734ebec4..e26fff71b 100644 --- a/src/libexpr/value-to-xml.cc +++ b/src/libexpr/value-to-xml.cc @@ -1,7 +1,7 @@ -#include "value-to-xml.hh" -#include "xml-writer.hh" -#include "eval-inline.hh" -#include "signals.hh" +#include "nix/expr/value-to-xml.hh" +#include "nix/util/xml-writer.hh" +#include "nix/expr/eval-inline.hh" +#include "nix/util/signals.hh" #include diff --git a/src/libexpr/value/context.cc b/src/libexpr/value/context.cc index 6d9633268..40d08da59 100644 --- a/src/libexpr/value/context.cc +++ b/src/libexpr/value/context.cc @@ -1,5 +1,5 @@ -#include "util.hh" -#include "value/context.hh" +#include "nix/util/util.hh" +#include "nix/expr/value/context.hh" #include diff --git a/src/libfetchers-tests/access-tokens.cc b/src/libfetchers-tests/access-tokens.cc index a869b088b..e7570c31c 100644 --- a/src/libfetchers-tests/access-tokens.cc +++ b/src/libfetchers-tests/access-tokens.cc @@ -1,9 +1,10 @@ -#include -#include "fetchers.hh" -#include "fetch-settings.hh" -#include "json-utils.hh" #include -#include "tests/characterization.hh" +#include + +#include "nix/fetchers/fetchers.hh" +#include "nix/fetchers/fetch-settings.hh" +#include "nix/util/json-utils.hh" +#include "nix/util/tests/characterization.hh" namespace nix::fetchers { diff --git a/src/libfetchers-tests/git-utils.cc b/src/libfetchers-tests/git-utils.cc index ee6ef1734..ceac809de 100644 --- a/src/libfetchers-tests/git-utils.cc +++ b/src/libfetchers-tests/git-utils.cc @@ -1,13 +1,13 @@ -#include "git-utils.hh" -#include "file-system.hh" -#include "gmock/gmock.h" +#include "nix/fetchers/git-utils.hh" +#include "nix/util/file-system.hh" +#include #include #include #include #include -#include "fs-sink.hh" -#include "serialise.hh" -#include "git-lfs-fetch.hh" +#include "nix/util/fs-sink.hh" +#include "nix/util/serialise.hh" +#include "nix/fetchers/git-lfs-fetch.hh" namespace nix { diff --git a/src/libfetchers-tests/meson.build b/src/libfetchers-tests/meson.build index b60ff5675..12b748e65 100644 --- a/src/libfetchers-tests/meson.build +++ b/src/libfetchers-tests/meson.build @@ -34,15 +34,6 @@ deps_private += gtest libgit2 = dependency('libgit2') deps_private += libgit2 -add_project_arguments( - # TODO(Qyriad): Yes this is how the autoconf+Make system did it. - # It would be nice for our headers to be idempotent instead. - '-include', 'config-util.hh', - '-include', 'config-store.hh', - # '-include', 'config-fetchers.h', - language : 'cpp', -) - subdir('nix-meson-build-support/common') sources = files( diff --git a/src/libfetchers-tests/public-key.cc b/src/libfetchers-tests/public-key.cc index 80796bd0f..39a7cf4bd 100644 --- a/src/libfetchers-tests/public-key.cc +++ b/src/libfetchers-tests/public-key.cc @@ -1,8 +1,8 @@ #include -#include "fetchers.hh" -#include "json-utils.hh" +#include "nix/fetchers/fetchers.hh" +#include "nix/util/json-utils.hh" #include -#include "tests/characterization.hh" +#include "nix/util/tests/characterization.hh" namespace nix { diff --git a/src/libfetchers/attrs.cc b/src/libfetchers/attrs.cc index 25d04cdc9..47f6aa8c5 100644 --- a/src/libfetchers/attrs.cc +++ b/src/libfetchers/attrs.cc @@ -1,5 +1,5 @@ -#include "attrs.hh" -#include "fetchers.hh" +#include "nix/fetchers/attrs.hh" +#include "nix/fetchers/fetchers.hh" #include diff --git a/src/libfetchers/cache.cc b/src/libfetchers/cache.cc index 6c2241f3a..d369d213f 100644 --- a/src/libfetchers/cache.cc +++ b/src/libfetchers/cache.cc @@ -1,8 +1,8 @@ -#include "cache.hh" -#include "users.hh" -#include "sqlite.hh" -#include "sync.hh" -#include "store-api.hh" +#include "nix/fetchers/cache.hh" +#include "nix/util/users.hh" +#include "nix/store/sqlite.hh" +#include "nix/util/sync.hh" +#include "nix/store/store-api.hh" #include diff --git a/src/libfetchers/fetch-settings.cc b/src/libfetchers/fetch-settings.cc index c7ed4c7af..4b4e4e29d 100644 --- a/src/libfetchers/fetch-settings.cc +++ b/src/libfetchers/fetch-settings.cc @@ -1,4 +1,4 @@ -#include "fetch-settings.hh" +#include "nix/fetchers/fetch-settings.hh" namespace nix::fetchers { diff --git a/src/libfetchers/fetch-to-store.cc b/src/libfetchers/fetch-to-store.cc index fe347a59d..f1b02f4e0 100644 --- a/src/libfetchers/fetch-to-store.cc +++ b/src/libfetchers/fetch-to-store.cc @@ -1,9 +1,23 @@ -#include "fetch-to-store.hh" -#include "fetchers.hh" -#include "cache.hh" +#include "nix/fetchers/fetch-to-store.hh" +#include "nix/fetchers/fetchers.hh" namespace nix { +fetchers::Cache::Key makeFetchToStoreCacheKey( + const std::string &name, + const std::string &fingerprint, + ContentAddressMethod method, + const std::string &path) +{ + return fetchers::Cache::Key{"fetchToStore", { + {"name", name}, + {"fingerprint", fingerprint}, + {"method", std::string{method.render()}}, + {"path", path} + }}; + +} + StorePath fetchToStore( Store & store, const SourcePath & path, @@ -19,12 +33,7 @@ StorePath fetchToStore( std::optional cacheKey; if (!filter && path.accessor->fingerprint) { - cacheKey = fetchers::Cache::Key{"fetchToStore", { - {"name", std::string{name}}, - {"fingerprint", *path.accessor->fingerprint}, - {"method", std::string{method.render()}}, - {"path", path.path.abs()} - }}; + cacheKey = makeFetchToStoreCacheKey(std::string{name}, *path.accessor->fingerprint, method, path.path.abs()); if (auto res = fetchers::getCache()->lookupStorePath(*cacheKey, store)) { debug("store path cache hit for '%s'", path); return res->storePath; diff --git a/src/libfetchers/fetchers.cc b/src/libfetchers/fetchers.cc index 67728501e..9693f1773 100644 --- a/src/libfetchers/fetchers.cc +++ b/src/libfetchers/fetchers.cc @@ -1,10 +1,10 @@ -#include "fetchers.hh" -#include "store-api.hh" -#include "source-path.hh" -#include "fetch-to-store.hh" -#include "json-utils.hh" -#include "store-path-accessor.hh" -#include "fetch-settings.hh" +#include "nix/fetchers/fetchers.hh" +#include "nix/store/store-api.hh" +#include "nix/util/source-path.hh" +#include "nix/fetchers/fetch-to-store.hh" +#include "nix/util/json-utils.hh" +#include "nix/fetchers/store-path-accessor.hh" +#include "nix/fetchers/fetch-settings.hh" #include diff --git a/src/libfetchers/filtering-source-accessor.cc b/src/libfetchers/filtering-source-accessor.cc index 10a22d026..97f230c7e 100644 --- a/src/libfetchers/filtering-source-accessor.cc +++ b/src/libfetchers/filtering-source-accessor.cc @@ -1,4 +1,4 @@ -#include "filtering-source-accessor.hh" +#include "nix/fetchers/filtering-source-accessor.hh" namespace nix { diff --git a/src/libfetchers/git-lfs-fetch.cc b/src/libfetchers/git-lfs-fetch.cc index bd6c01435..dbf4b1eb9 100644 --- a/src/libfetchers/git-lfs-fetch.cc +++ b/src/libfetchers/git-lfs-fetch.cc @@ -1,10 +1,10 @@ -#include "git-lfs-fetch.hh" -#include "git-utils.hh" -#include "filetransfer.hh" -#include "processes.hh" -#include "url.hh" -#include "users.hh" -#include "hash.hh" +#include "nix/fetchers/git-lfs-fetch.hh" +#include "nix/fetchers/git-utils.hh" +#include "nix/store/filetransfer.hh" +#include "nix/util/processes.hh" +#include "nix/util/url.hh" +#include "nix/util/users.hh" +#include "nix/util/hash.hh" #include #include diff --git a/src/libfetchers/git-utils.cc b/src/libfetchers/git-utils.cc index 6fa33e130..7e1f085f5 100644 --- a/src/libfetchers/git-utils.cc +++ b/src/libfetchers/git-utils.cc @@ -1,12 +1,12 @@ -#include "git-utils.hh" -#include "git-lfs-fetch.hh" -#include "cache.hh" -#include "finally.hh" -#include "processes.hh" -#include "signals.hh" -#include "users.hh" -#include "fs-sink.hh" -#include "sync.hh" +#include "nix/fetchers/git-utils.hh" +#include "nix/fetchers/git-lfs-fetch.hh" +#include "nix/fetchers/cache.hh" +#include "nix/util/finally.hh" +#include "nix/util/processes.hh" +#include "nix/util/signals.hh" +#include "nix/util/users.hh" +#include "nix/util/fs-sink.hh" +#include "nix/util/sync.hh" #include #include diff --git a/src/libfetchers/git.cc b/src/libfetchers/git.cc index e182740d6..9a0b8c65a 100644 --- a/src/libfetchers/git.cc +++ b/src/libfetchers/git.cc @@ -1,21 +1,21 @@ -#include "error.hh" -#include "fetchers.hh" -#include "users.hh" -#include "cache.hh" -#include "globals.hh" -#include "tarfile.hh" -#include "store-api.hh" -#include "url-parts.hh" -#include "pathlocks.hh" -#include "processes.hh" -#include "git.hh" -#include "git-utils.hh" -#include "logging.hh" -#include "finally.hh" -#include "fetch-settings.hh" -#include "json-utils.hh" -#include "archive.hh" -#include "mounted-source-accessor.hh" +#include "nix/util/error.hh" +#include "nix/fetchers/fetchers.hh" +#include "nix/util/users.hh" +#include "nix/fetchers/cache.hh" +#include "nix/store/globals.hh" +#include "nix/util/tarfile.hh" +#include "nix/store/store-api.hh" +#include "nix/util/url-parts.hh" +#include "nix/store/pathlocks.hh" +#include "nix/util/processes.hh" +#include "nix/util/git.hh" +#include "nix/fetchers/git-utils.hh" +#include "nix/util/logging.hh" +#include "nix/util/finally.hh" +#include "nix/fetchers/fetch-settings.hh" +#include "nix/util/json-utils.hh" +#include "nix/util/archive.hh" +#include "nix/util/mounted-source-accessor.hh" #include #include @@ -536,7 +536,7 @@ struct GitInputScheme : InputScheme static MakeNotAllowedError makeNotAllowedError(std::filesystem::path repoPath) { return [repoPath{std::move(repoPath)}](const CanonPath & path) -> RestrictedPathError { - if (nix::pathExists(repoPath / path.rel())) + if (fs::symlink_exists(repoPath / path.rel())) return RestrictedPathError( "Path '%1%' in the repository %2% is not tracked by Git.\n" "\n" diff --git a/src/libfetchers/github.cc b/src/libfetchers/github.cc index 5cea22eea..f24c07fc2 100644 --- a/src/libfetchers/github.cc +++ b/src/libfetchers/github.cc @@ -1,15 +1,15 @@ -#include "filetransfer.hh" -#include "cache.hh" -#include "globals.hh" -#include "store-api.hh" -#include "types.hh" -#include "url-parts.hh" -#include "git.hh" -#include "fetchers.hh" -#include "fetch-settings.hh" -#include "tarball.hh" -#include "tarfile.hh" -#include "git-utils.hh" +#include "nix/store/filetransfer.hh" +#include "nix/fetchers/cache.hh" +#include "nix/store/globals.hh" +#include "nix/store/store-api.hh" +#include "nix/util/types.hh" +#include "nix/util/url-parts.hh" +#include "nix/util/git.hh" +#include "nix/fetchers/fetchers.hh" +#include "nix/fetchers/fetch-settings.hh" +#include "nix/fetchers/tarball.hh" +#include "nix/util/tarfile.hh" +#include "nix/fetchers/git-utils.hh" #include #include diff --git a/src/libfetchers/attrs.hh b/src/libfetchers/include/nix/fetchers/attrs.hh similarity index 95% rename from src/libfetchers/attrs.hh rename to src/libfetchers/include/nix/fetchers/attrs.hh index 97a74bce0..1b757d712 100644 --- a/src/libfetchers/attrs.hh +++ b/src/libfetchers/include/nix/fetchers/attrs.hh @@ -1,8 +1,8 @@ #pragma once ///@file -#include "types.hh" -#include "hash.hh" +#include "nix/util/types.hh" +#include "nix/util/hash.hh" #include diff --git a/src/libfetchers/cache.hh b/src/libfetchers/include/nix/fetchers/cache.hh similarity index 97% rename from src/libfetchers/cache.hh rename to src/libfetchers/include/nix/fetchers/cache.hh index 4d834fe0c..5b9319d77 100644 --- a/src/libfetchers/cache.hh +++ b/src/libfetchers/include/nix/fetchers/cache.hh @@ -1,8 +1,8 @@ #pragma once ///@file -#include "fetchers.hh" -#include "path.hh" +#include "nix/fetchers/fetchers.hh" +#include "nix/store/path.hh" namespace nix::fetchers { diff --git a/src/libfetchers/fetch-settings.hh b/src/libfetchers/include/nix/fetchers/fetch-settings.hh similarity index 98% rename from src/libfetchers/fetch-settings.hh rename to src/libfetchers/include/nix/fetchers/fetch-settings.hh index 971ec4719..831a18bf0 100644 --- a/src/libfetchers/fetch-settings.hh +++ b/src/libfetchers/include/nix/fetchers/fetch-settings.hh @@ -1,8 +1,8 @@ #pragma once ///@file -#include "types.hh" -#include "config.hh" +#include "nix/util/types.hh" +#include "nix/util/configuration.hh" #include #include diff --git a/src/libfetchers/fetch-to-store.hh b/src/libfetchers/include/nix/fetchers/fetch-to-store.hh similarity index 50% rename from src/libfetchers/fetch-to-store.hh rename to src/libfetchers/include/nix/fetchers/fetch-to-store.hh index c762629f3..44c33c147 100644 --- a/src/libfetchers/fetch-to-store.hh +++ b/src/libfetchers/include/nix/fetchers/fetch-to-store.hh @@ -1,10 +1,11 @@ #pragma once -#include "source-path.hh" -#include "store-api.hh" -#include "file-system.hh" -#include "repair-flag.hh" -#include "file-content-address.hh" +#include "nix/util/source-path.hh" +#include "nix/store/store-api.hh" +#include "nix/util/file-system.hh" +#include "nix/util/repair-flag.hh" +#include "nix/util/file-content-address.hh" +#include "nix/fetchers/cache.hh" namespace nix { @@ -22,4 +23,7 @@ StorePath fetchToStore( PathFilter * filter = nullptr, RepairFlag repair = NoRepair); +fetchers::Cache::Key makeFetchToStoreCacheKey( + const std::string & name, const std::string & fingerprint, ContentAddressMethod method, const std::string & path); + } diff --git a/src/libfetchers/fetchers.hh b/src/libfetchers/include/nix/fetchers/fetchers.hh similarity index 97% rename from src/libfetchers/fetchers.hh rename to src/libfetchers/include/nix/fetchers/fetchers.hh index 798d60177..c2ae647af 100644 --- a/src/libfetchers/fetchers.hh +++ b/src/libfetchers/include/nix/fetchers/fetchers.hh @@ -1,17 +1,17 @@ #pragma once ///@file -#include "types.hh" -#include "hash.hh" -#include "canon-path.hh" -#include "json-impls.hh" -#include "attrs.hh" -#include "url.hh" +#include "nix/util/types.hh" +#include "nix/util/hash.hh" +#include "nix/util/canon-path.hh" +#include "nix/util/json-impls.hh" +#include "nix/fetchers/attrs.hh" +#include "nix/util/url.hh" #include #include -#include "ref.hh" +#include "nix/util/ref.hh" namespace nix { class Store; class StorePath; struct SourceAccessor; } diff --git a/src/libfetchers/filtering-source-accessor.hh b/src/libfetchers/include/nix/fetchers/filtering-source-accessor.hh similarity index 97% rename from src/libfetchers/filtering-source-accessor.hh rename to src/libfetchers/include/nix/fetchers/filtering-source-accessor.hh index 544b4a490..c3b99fa5a 100644 --- a/src/libfetchers/filtering-source-accessor.hh +++ b/src/libfetchers/include/nix/fetchers/filtering-source-accessor.hh @@ -1,6 +1,8 @@ #pragma once -#include "source-path.hh" +#include "nix/util/source-path.hh" + +#include #include diff --git a/src/libfetchers/git-lfs-fetch.hh b/src/libfetchers/include/nix/fetchers/git-lfs-fetch.hh similarity index 90% rename from src/libfetchers/git-lfs-fetch.hh rename to src/libfetchers/include/nix/fetchers/git-lfs-fetch.hh index 36df91962..e701288cf 100644 --- a/src/libfetchers/git-lfs-fetch.hh +++ b/src/libfetchers/include/nix/fetchers/git-lfs-fetch.hh @@ -1,6 +1,6 @@ -#include "canon-path.hh" -#include "serialise.hh" -#include "url.hh" +#include "nix/util/canon-path.hh" +#include "nix/util/serialise.hh" +#include "nix/util/url.hh" #include diff --git a/src/libfetchers/git-utils.hh b/src/libfetchers/include/nix/fetchers/git-utils.hh similarity index 97% rename from src/libfetchers/git-utils.hh rename to src/libfetchers/include/nix/fetchers/git-utils.hh index c683bd058..1506f8509 100644 --- a/src/libfetchers/git-utils.hh +++ b/src/libfetchers/include/nix/fetchers/git-utils.hh @@ -1,7 +1,7 @@ #pragma once -#include "filtering-source-accessor.hh" -#include "fs-sink.hh" +#include "nix/fetchers/filtering-source-accessor.hh" +#include "nix/util/fs-sink.hh" namespace nix { diff --git a/src/libfetchers/include/nix/fetchers/meson.build b/src/libfetchers/include/nix/fetchers/meson.build new file mode 100644 index 000000000..3a752d9cb --- /dev/null +++ b/src/libfetchers/include/nix/fetchers/meson.build @@ -0,0 +1,15 @@ +include_dirs = [include_directories('../..')] + +headers = files( + 'attrs.hh', + 'cache.hh', + 'fetch-settings.hh', + 'fetch-to-store.hh', + 'fetchers.hh', + 'filtering-source-accessor.hh', + 'git-lfs-fetch.hh', + 'git-utils.hh', + 'registry.hh', + 'store-path-accessor.hh', + 'tarball.hh', +) diff --git a/src/libfetchers/registry.hh b/src/libfetchers/include/nix/fetchers/registry.hh similarity index 96% rename from src/libfetchers/registry.hh rename to src/libfetchers/include/nix/fetchers/registry.hh index 8f47e1590..47ff9e86f 100644 --- a/src/libfetchers/registry.hh +++ b/src/libfetchers/include/nix/fetchers/registry.hh @@ -1,8 +1,8 @@ #pragma once ///@file -#include "types.hh" -#include "fetchers.hh" +#include "nix/util/types.hh" +#include "nix/fetchers/fetchers.hh" namespace nix { class Store; } diff --git a/src/libfetchers/store-path-accessor.hh b/src/libfetchers/include/nix/fetchers/store-path-accessor.hh similarity index 85% rename from src/libfetchers/store-path-accessor.hh rename to src/libfetchers/include/nix/fetchers/store-path-accessor.hh index 989cf3fa2..021df5a62 100644 --- a/src/libfetchers/store-path-accessor.hh +++ b/src/libfetchers/include/nix/fetchers/store-path-accessor.hh @@ -1,6 +1,6 @@ #pragma once -#include "source-path.hh" +#include "nix/util/source-path.hh" namespace nix { diff --git a/src/libfetchers/tarball.hh b/src/libfetchers/include/nix/fetchers/tarball.hh similarity index 88% rename from src/libfetchers/tarball.hh rename to src/libfetchers/include/nix/fetchers/tarball.hh index 2042041d5..691142091 100644 --- a/src/libfetchers/tarball.hh +++ b/src/libfetchers/include/nix/fetchers/tarball.hh @@ -2,10 +2,10 @@ #include -#include "hash.hh" -#include "path.hh" -#include "ref.hh" -#include "types.hh" +#include "nix/util/hash.hh" +#include "nix/store/path.hh" +#include "nix/util/ref.hh" +#include "nix/util/types.hh" namespace nix { class Store; diff --git a/src/libfetchers/indirect.cc b/src/libfetchers/indirect.cc index c50b92379..0ff05af03 100644 --- a/src/libfetchers/indirect.cc +++ b/src/libfetchers/indirect.cc @@ -1,6 +1,6 @@ -#include "fetchers.hh" -#include "url-parts.hh" -#include "path.hh" +#include "nix/fetchers/fetchers.hh" +#include "nix/util/url-parts.hh" +#include "nix/store/path.hh" namespace nix::fetchers { diff --git a/src/libfetchers/mercurial.cc b/src/libfetchers/mercurial.cc index 61cbca202..eb6bdd1eb 100644 --- a/src/libfetchers/mercurial.cc +++ b/src/libfetchers/mercurial.cc @@ -1,13 +1,13 @@ -#include "fetchers.hh" -#include "processes.hh" -#include "users.hh" -#include "cache.hh" -#include "globals.hh" -#include "tarfile.hh" -#include "store-api.hh" -#include "url-parts.hh" -#include "store-path-accessor.hh" -#include "fetch-settings.hh" +#include "nix/fetchers/fetchers.hh" +#include "nix/util/processes.hh" +#include "nix/util/users.hh" +#include "nix/fetchers/cache.hh" +#include "nix/store/globals.hh" +#include "nix/util/tarfile.hh" +#include "nix/store/store-api.hh" +#include "nix/util/url-parts.hh" +#include "nix/fetchers/store-path-accessor.hh" +#include "nix/fetchers/fetch-settings.hh" #include diff --git a/src/libfetchers/meson.build b/src/libfetchers/meson.build index 725254b56..6e7129f4c 100644 --- a/src/libfetchers/meson.build +++ b/src/libfetchers/meson.build @@ -30,15 +30,6 @@ deps_public += nlohmann_json libgit2 = dependency('libgit2') deps_private += libgit2 -add_project_arguments( - # TODO(Qyriad): Yes this is how the autoconf+Make system did it. - # It would be nice for our headers to be idempotent instead. - '-include', 'config-util.hh', - '-include', 'config-store.hh', - # '-include', 'config-fetchers.h', - language : 'cpp', -) - subdir('nix-meson-build-support/common') sources = files( @@ -60,31 +51,22 @@ sources = files( 'tarball.cc', ) -include_dirs = [include_directories('.')] +subdir('include/nix/fetchers') -headers = files( - 'attrs.hh', - 'cache.hh', - 'fetch-settings.hh', - 'fetch-to-store.hh', - 'fetchers.hh', - 'filtering-source-accessor.hh', - 'git-lfs-fetch.hh', - 'git-utils.hh', - 'registry.hh', - 'store-path-accessor.hh', - 'tarball.hh', -) +subdir('nix-meson-build-support/export-all-symbols') +subdir('nix-meson-build-support/windows-version') this_library = library( 'nixfetchers', sources, dependencies : deps_public + deps_private + deps_other, + include_directories : include_dirs, + link_args: linker_export_flags, prelink : true, # For C++ static initializers install : true, ) -install_headers(headers, subdir : 'nix', preserve_path : true) +install_headers(headers, subdir : 'nix/fetchers', preserve_path : true) libraries_private = [] diff --git a/src/libfetchers/package.nix b/src/libfetchers/package.nix index 5aa096082..b6b061e2d 100644 --- a/src/libfetchers/package.nix +++ b/src/libfetchers/package.nix @@ -27,6 +27,7 @@ mkMesonLibrary (finalAttrs: { ../../.version ./.version ./meson.build + ./include/nix/fetchers/meson.build (fileset.fileFilter (file: file.hasExt "cc") ./.) (fileset.fileFilter (file: file.hasExt "hh") ./.) ]; diff --git a/src/libfetchers/path.cc b/src/libfetchers/path.cc index e3f2afd8a..ff39cb02f 100644 --- a/src/libfetchers/path.cc +++ b/src/libfetchers/path.cc @@ -1,7 +1,9 @@ -#include "fetchers.hh" -#include "store-api.hh" -#include "archive.hh" -#include "store-path-accessor.hh" +#include "nix/fetchers/fetchers.hh" +#include "nix/store/store-api.hh" +#include "nix/util/archive.hh" +#include "nix/fetchers/store-path-accessor.hh" +#include "nix/fetchers/cache.hh" +#include "nix/fetchers/fetch-to-store.hh" namespace nix::fetchers { @@ -142,6 +144,14 @@ struct PathInputScheme : InputScheme storePath = store->addToStoreFromDump(*src, "source"); } + // To avoid copying the path again to the /nix/store, we need to add a cache entry. + ContentAddressMethod method = ContentAddressMethod::Raw::NixArchive; + auto fp = getFingerprint(store, input); + if (fp) { + auto cacheKey = makeFetchToStoreCacheKey(input.getName(), *fp, method, "/"); + fetchers::getCache()->upsert(cacheKey, *store, {}, *storePath); + } + /* Trust the lastModified value supplied by the user, if any. It's not a "secure" attribute so we don't care. */ if (!input.getLastModified()) diff --git a/src/libfetchers/registry.cc b/src/libfetchers/registry.cc index c18e12d23..e9b55f7f2 100644 --- a/src/libfetchers/registry.cc +++ b/src/libfetchers/registry.cc @@ -1,10 +1,10 @@ -#include "fetch-settings.hh" -#include "registry.hh" -#include "tarball.hh" -#include "users.hh" -#include "globals.hh" -#include "store-api.hh" -#include "local-fs-store.hh" +#include "nix/fetchers/fetch-settings.hh" +#include "nix/fetchers/registry.hh" +#include "nix/fetchers/tarball.hh" +#include "nix/util/users.hh" +#include "nix/store/globals.hh" +#include "nix/store/store-api.hh" +#include "nix/store/local-fs-store.hh" #include diff --git a/src/libfetchers/store-path-accessor.cc b/src/libfetchers/store-path-accessor.cc index 528bf2a4f..bed51541e 100644 --- a/src/libfetchers/store-path-accessor.cc +++ b/src/libfetchers/store-path-accessor.cc @@ -1,5 +1,5 @@ -#include "store-path-accessor.hh" -#include "store-api.hh" +#include "nix/fetchers/store-path-accessor.hh" +#include "nix/store/store-api.hh" namespace nix { diff --git a/src/libfetchers/tarball.cc b/src/libfetchers/tarball.cc index 699612e25..ef91d6b25 100644 --- a/src/libfetchers/tarball.cc +++ b/src/libfetchers/tarball.cc @@ -1,14 +1,14 @@ -#include "tarball.hh" -#include "fetchers.hh" -#include "cache.hh" -#include "filetransfer.hh" -#include "store-api.hh" -#include "archive.hh" -#include "tarfile.hh" -#include "types.hh" -#include "store-path-accessor.hh" -#include "store-api.hh" -#include "git-utils.hh" +#include "nix/fetchers/tarball.hh" +#include "nix/fetchers/fetchers.hh" +#include "nix/fetchers/cache.hh" +#include "nix/store/filetransfer.hh" +#include "nix/store/store-api.hh" +#include "nix/util/archive.hh" +#include "nix/util/tarfile.hh" +#include "nix/util/types.hh" +#include "nix/fetchers/store-path-accessor.hh" +#include "nix/store/store-api.hh" +#include "nix/fetchers/git-utils.hh" namespace nix::fetchers { diff --git a/src/libflake-c/meson.build b/src/libflake-c/meson.build index 85d20644d..fd3cdd01b 100644 --- a/src/libflake-c/meson.build +++ b/src/libflake-c/meson.build @@ -14,8 +14,6 @@ cxx = meson.get_compiler('cpp') subdir('nix-meson-build-support/deps-lists') -configdata = configuration_data() - deps_private_maybe_subproject = [ dependency('nix-util'), dependency('nix-store'), @@ -29,33 +27,6 @@ deps_public_maybe_subproject = [ ] subdir('nix-meson-build-support/subprojects') -# TODO rename, because it will conflict with downstream projects -configdata.set_quoted('PACKAGE_VERSION', meson.project_version()) - -config_h = configure_file( - configuration : configdata, - output : 'config-flake.h', -) - -add_project_arguments( - # TODO(Qyriad): Yes this is how the autoconf+Make system did it. - # It would be nice for our headers to be idempotent instead. - - # From C++ libraries, only for internals - '-include', 'config-util.hh', - '-include', 'config-store.hh', - '-include', 'config-expr.hh', - # not generated (yet?) - # '-include', 'config-flake.hh', - - # From C libraries, for our public, installed headers too - '-include', 'config-util.h', - '-include', 'config-store.h', - '-include', 'config-expr.h', - '-include', 'config-flake.h', - language : 'cpp', -) - subdir('nix-meson-build-support/common') sources = files( @@ -64,7 +35,7 @@ sources = files( include_dirs = [include_directories('.')] -headers = [config_h] + files( +headers = files( 'nix_api_flake.h', ) @@ -84,7 +55,7 @@ this_library = library( install : true, ) -install_headers(headers, subdir : 'nix', preserve_path : true) +install_headers(headers, preserve_path : true) libraries_private = [] diff --git a/src/libflake-c/nix_api_flake.cc b/src/libflake-c/nix_api_flake.cc index 17cf6572d..a1b586e82 100644 --- a/src/libflake-c/nix_api_flake.cc +++ b/src/libflake-c/nix_api_flake.cc @@ -1,8 +1,9 @@ #include "nix_api_flake.h" #include "nix_api_flake_internal.hh" #include "nix_api_util_internal.h" +#include "nix_api_expr_internal.h" -#include "flake/flake.hh" +#include "nix/flake/flake.hh" nix_flake_settings * nix_flake_settings_new(nix_c_context * context) { @@ -18,15 +19,11 @@ void nix_flake_settings_free(nix_flake_settings * settings) delete settings; } -nix_err nix_flake_init_global(nix_c_context * context, nix_flake_settings * settings) +nix_err nix_flake_settings_add_to_eval_state_builder( + nix_c_context * context, nix_flake_settings * settings, nix_eval_state_builder * builder) { - static std::shared_ptr registeredSettings; try { - if (registeredSettings) - throw nix::Error("nix_flake_init_global already initialized"); - - registeredSettings = settings->settings; - nix::flake::initLib(*registeredSettings); + settings->settings->configureEvalSettings(builder->settings); } NIXC_CATCH_ERRS } diff --git a/src/libflake-c/nix_api_flake.h b/src/libflake-c/nix_api_flake.h index 80051298d..75675835e 100644 --- a/src/libflake-c/nix_api_flake.h +++ b/src/libflake-c/nix_api_flake.h @@ -35,9 +35,15 @@ nix_flake_settings * nix_flake_settings_new(nix_c_context * context); void nix_flake_settings_free(nix_flake_settings * settings); /** - * @brief Register Flakes support process-wide. + * @brief Initialize a `nix_flake_settings` to contain `builtins.getFlake` and + * potentially more. + * + * @param[out] context Optional, stores error information + * @param[in] settings The settings to use for e.g. `builtins.getFlake` + * @param[in] builder The builder to modify */ -nix_err nix_flake_init_global(nix_c_context * context, nix_flake_settings * settings); +nix_err nix_flake_settings_add_to_eval_state_builder( + nix_c_context * context, nix_flake_settings * settings, nix_eval_state_builder * builder); #ifdef __cplusplus } // extern "C" diff --git a/src/libflake-c/nix_api_flake_internal.hh b/src/libflake-c/nix_api_flake_internal.hh index 4c154a342..f7c5e7838 100644 --- a/src/libflake-c/nix_api_flake_internal.hh +++ b/src/libflake-c/nix_api_flake_internal.hh @@ -1,7 +1,7 @@ #pragma once -#include "ref.hh" -#include "flake/settings.hh" +#include "nix/util/ref.hh" +#include "nix/flake/settings.hh" struct nix_flake_settings { diff --git a/src/libflake-tests/flakeref.cc b/src/libflake-tests/flakeref.cc index c7007a7af..ccef8f379 100644 --- a/src/libflake-tests/flakeref.cc +++ b/src/libflake-tests/flakeref.cc @@ -1,7 +1,7 @@ #include -#include "fetch-settings.hh" -#include "flake/flakeref.hh" +#include "nix/fetchers/fetch-settings.hh" +#include "nix/flake/flakeref.hh" namespace nix { diff --git a/src/libflake-tests/meson.build b/src/libflake-tests/meson.build index 2d653bb7b..80c94bd77 100644 --- a/src/libflake-tests/meson.build +++ b/src/libflake-tests/meson.build @@ -32,15 +32,6 @@ deps_private += rapidcheck gtest = dependency('gtest', main : true) deps_private += gtest -add_project_arguments( - # TODO(Qyriad): Yes this is how the autoconf+Make system did it. - # It would be nice for our headers to be idempotent instead. - '-include', 'config-util.hh', - '-include', 'config-store.hh', - '-include', 'config-expr.hh', - language : 'cpp', -) - subdir('nix-meson-build-support/common') sources = files( diff --git a/src/libflake-tests/nix_api_flake.cc b/src/libflake-tests/nix_api_flake.cc index 21109d181..b72342e4d 100644 --- a/src/libflake-tests/nix_api_flake.cc +++ b/src/libflake-tests/nix_api_flake.cc @@ -6,8 +6,8 @@ #include "nix_api_value.h" #include "nix_api_flake.h" -#include "tests/nix_api_expr.hh" -#include "tests/string_callback.hh" +#include "nix/expr/tests/nix_api_expr.hh" +#include "nix/util/tests/string_callback.hh" #include #include @@ -25,13 +25,13 @@ TEST_F(nix_api_store_test, nix_api_init_global_getFlake_exists) assert_ctx_ok(); ASSERT_NE(nullptr, settings); - nix_flake_init_global(ctx, settings); - assert_ctx_ok(); - nix_eval_state_builder * builder = nix_eval_state_builder_new(ctx, store); ASSERT_NE(nullptr, builder); assert_ctx_ok(); + nix_flake_settings_add_to_eval_state_builder(ctx, settings, builder); + assert_ctx_ok(); + auto state = nix_eval_state_build(ctx, builder); assert_ctx_ok(); ASSERT_NE(nullptr, state); diff --git a/src/libflake-tests/url-name.cc b/src/libflake-tests/url-name.cc index 15bc6b111..c795850f9 100644 --- a/src/libflake-tests/url-name.cc +++ b/src/libflake-tests/url-name.cc @@ -1,4 +1,4 @@ -#include "flake/url-name.hh" +#include "nix/flake/url-name.hh" #include namespace nix { diff --git a/src/libexpr/call-flake.nix b/src/libflake/call-flake.nix similarity index 100% rename from src/libexpr/call-flake.nix rename to src/libflake/call-flake.nix diff --git a/src/libflake/flake/config.cc b/src/libflake/flake/config.cc index 4879de463..a67f7884c 100644 --- a/src/libflake/flake/config.cc +++ b/src/libflake/flake/config.cc @@ -1,7 +1,7 @@ -#include "users.hh" -#include "config-global.hh" -#include "flake/settings.hh" -#include "flake.hh" +#include "nix/util/users.hh" +#include "nix/util/config-global.hh" +#include "nix/flake/settings.hh" +#include "nix/flake/flake.hh" #include diff --git a/src/libflake/flake/flake-primops.cc b/src/libflake/flake/flake-primops.cc new file mode 100644 index 000000000..703463141 --- /dev/null +++ b/src/libflake/flake/flake-primops.cc @@ -0,0 +1,157 @@ +#include "nix/flake/flake-primops.hh" +#include "nix/expr/eval.hh" +#include "nix/flake/flake.hh" +#include "nix/flake/flakeref.hh" +#include "nix/flake/settings.hh" + +namespace nix::flake::primops { + +PrimOp getFlake(const Settings & settings) +{ + auto prim_getFlake = [&settings](EvalState & state, const PosIdx pos, Value ** args, Value & v) { + std::string flakeRefS( + state.forceStringNoCtx(*args[0], pos, "while evaluating the argument passed to builtins.getFlake")); + auto flakeRef = nix::parseFlakeRef(state.fetchSettings, flakeRefS, {}, true); + if (state.settings.pureEval && !flakeRef.input.isLocked()) + throw Error( + "cannot call 'getFlake' on unlocked flake reference '%s', at %s (use --impure to override)", + flakeRefS, + state.positions[pos]); + + callFlake( + state, + lockFlake( + settings, + state, + flakeRef, + LockFlags{ + .updateLockFile = false, + .writeLockFile = false, + .useRegistries = !state.settings.pureEval && settings.useRegistries, + .allowUnlocked = !state.settings.pureEval, + }), + v); + }; + + return PrimOp{ + .name = "__getFlake", + .args = {"args"}, + .doc = R"( + Fetch a flake from a flake reference, and return its output attributes and some metadata. For example: + + ```nix + (builtins.getFlake "nix/55bc52401966fbffa525c574c14f67b00bc4fb3a").packages.x86_64-linux.nix + ``` + + Unless impure evaluation is allowed (`--impure`), the flake reference + must be "locked", e.g. contain a Git revision or content hash. An + example of an unlocked usage is: + + ```nix + (builtins.getFlake "github:edolstra/dwarffs").rev + ``` + )", + .fun = prim_getFlake, + }; +} + +static void prim_parseFlakeRef(EvalState & state, const PosIdx pos, Value ** args, Value & v) +{ + std::string flakeRefS( + state.forceStringNoCtx(*args[0], pos, "while evaluating the argument passed to builtins.parseFlakeRef")); + auto attrs = nix::parseFlakeRef(state.fetchSettings, flakeRefS, {}, true).toAttrs(); + auto binds = state.buildBindings(attrs.size()); + for (const auto & [key, value] : attrs) { + auto s = state.symbols.create(key); + auto & vv = binds.alloc(s); + std::visit( + overloaded{ + [&vv](const std::string & value) { vv.mkString(value); }, + [&vv](const uint64_t & value) { vv.mkInt(value); }, + [&vv](const Explicit & value) { vv.mkBool(value.t); }}, + value); + } + v.mkAttrs(binds); +} + +nix::PrimOp parseFlakeRef({ + .name = "__parseFlakeRef", + .args = {"flake-ref"}, + .doc = R"( + Parse a flake reference, and return its exploded form. + + For example: + + ```nix + builtins.parseFlakeRef "github:NixOS/nixpkgs/23.05?dir=lib" + ``` + + evaluates to: + + ```nix + { dir = "lib"; owner = "NixOS"; ref = "23.05"; repo = "nixpkgs"; type = "github"; } + ``` + )", + .fun = prim_parseFlakeRef, +}); + +static void prim_flakeRefToString(EvalState & state, const PosIdx pos, Value ** args, Value & v) +{ + state.forceAttrs(*args[0], noPos, "while evaluating the argument passed to builtins.flakeRefToString"); + fetchers::Attrs attrs; + for (const auto & attr : *args[0]->attrs()) { + auto t = attr.value->type(); + if (t == nInt) { + auto intValue = attr.value->integer().value; + + if (intValue < 0) { + state + .error( + "negative value given for flake ref attr %1%: %2%", state.symbols[attr.name], intValue) + .atPos(pos) + .debugThrow(); + } + + attrs.emplace(state.symbols[attr.name], uint64_t(intValue)); + } else if (t == nBool) { + attrs.emplace(state.symbols[attr.name], Explicit{attr.value->boolean()}); + } else if (t == nString) { + attrs.emplace(state.symbols[attr.name], std::string(attr.value->string_view())); + } else { + state + .error( + "flake reference attribute sets may only contain integers, Booleans, " + "and strings, but attribute '%s' is %s", + state.symbols[attr.name], + showType(*attr.value)) + .debugThrow(); + } + } + auto flakeRef = FlakeRef::fromAttrs(state.fetchSettings, attrs); + v.mkString(flakeRef.to_string()); +} + +nix::PrimOp flakeRefToString({ + .name = "__flakeRefToString", + .args = {"attrs"}, + .doc = R"( + Convert a flake reference from attribute set format to URL format. + + For example: + + ```nix + builtins.flakeRefToString { + dir = "lib"; owner = "NixOS"; ref = "23.05"; repo = "nixpkgs"; type = "github"; + } + ``` + + evaluates to + + ```nix + "github:NixOS/nixpkgs/23.05?dir=lib" + ``` + )", + .fun = prim_flakeRefToString, +}); + +} // namespace nix::flake::primops diff --git a/src/libflake/flake/flake.cc b/src/libflake/flake/flake.cc index d61210670..6ea9626b9 100644 --- a/src/libflake/flake/flake.cc +++ b/src/libflake/flake/flake.cc @@ -1,19 +1,20 @@ -#include "terminal.hh" -#include "flake.hh" -#include "eval.hh" -#include "eval-settings.hh" -#include "lockfile.hh" -#include "primops.hh" -#include "eval-inline.hh" -#include "store-api.hh" -#include "fetchers.hh" -#include "finally.hh" -#include "fetch-settings.hh" -#include "flake/settings.hh" -#include "value-to-json.hh" -#include "local-fs-store.hh" -#include "fetch-to-store.hh" -#include "mounted-source-accessor.hh" +#include "nix/util/terminal.hh" +#include "nix/flake/flake.hh" +#include "nix/expr/eval.hh" +#include "nix/expr/eval-settings.hh" +#include "nix/flake/lockfile.hh" +#include "nix/expr/primops.hh" +#include "nix/expr/eval-inline.hh" +#include "nix/store/store-api.hh" +#include "nix/fetchers/fetchers.hh" +#include "nix/util/finally.hh" +#include "nix/fetchers/fetch-settings.hh" +#include "nix/flake/settings.hh" +#include "nix/expr/value-to-json.hh" +#include "nix/store/local-fs-store.hh" +#include "nix/fetchers/fetch-to-store.hh" +#include "nix/util/memory-source-accessor.hh" +#include "nix/util/mounted-source-accessor.hh" #include @@ -922,6 +923,25 @@ LockedFlake lockFlake( } } +static ref makeInternalFS() { + auto internalFS = make_ref(MemorySourceAccessor {}); + internalFS->setPathDisplay("«flakes-internal»", ""); + internalFS->addFile( + CanonPath("call-flake.nix"), + #include "call-flake.nix.gen.hh" + ); + return internalFS; +} + +static auto internalFS = makeInternalFS(); + +static Value * requireInternalFile(EvalState & state, CanonPath path) { + SourcePath p {internalFS, path}; + auto v = state.allocValue(); + state.evalFile(p, *v); // has caching + return v; +} + void callFlake(EvalState & state, const LockedFlake & lockedFlake, Value & vRes) @@ -959,8 +979,7 @@ void callFlake(EvalState & state, auto & vOverrides = state.allocValue()->mkAttrs(overrides); - auto vCallFlake = state.allocValue(); - state.evalFile(state.callFlakeInternal, *vCallFlake); + Value * vCallFlake = requireInternalFile(state, CanonPath("call-flake.nix")); auto vLocks = state.allocValue(); vLocks->mkString(lockFileStr); @@ -972,152 +991,6 @@ void callFlake(EvalState & state, state.callFunction(*vCallFlake, args, vRes, noPos); } -void initLib(const Settings & settings) -{ - auto prim_getFlake = [&settings](EvalState & state, const PosIdx pos, Value * * args, Value & v) - { - std::string flakeRefS(state.forceStringNoCtx(*args[0], pos, "while evaluating the argument passed to builtins.getFlake")); - auto flakeRef = parseFlakeRef(state.fetchSettings, flakeRefS, {}, true); - if (state.settings.pureEval && !flakeRef.input.isLocked()) - throw Error("cannot call 'getFlake' on unlocked flake reference '%s', at %s (use --impure to override)", flakeRefS, state.positions[pos]); - - callFlake(state, - lockFlake(settings, state, flakeRef, - LockFlags { - .updateLockFile = false, - .writeLockFile = false, - .useRegistries = !state.settings.pureEval && settings.useRegistries, - .allowUnlocked = !state.settings.pureEval, - }), - v); - }; - - RegisterPrimOp::primOps->push_back({ - .name = "__getFlake", - .args = {"args"}, - .doc = R"( - Fetch a flake from a flake reference, and return its output attributes and some metadata. For example: - - ```nix - (builtins.getFlake "nix/55bc52401966fbffa525c574c14f67b00bc4fb3a").packages.x86_64-linux.nix - ``` - - Unless impure evaluation is allowed (`--impure`), the flake reference - must be "locked", e.g. contain a Git revision or content hash. An - example of an unlocked usage is: - - ```nix - (builtins.getFlake "github:edolstra/dwarffs").rev - ``` - )", - .fun = prim_getFlake, - }); -} - -static void prim_parseFlakeRef( - EvalState & state, - const PosIdx pos, - Value * * args, - Value & v) -{ - std::string flakeRefS(state.forceStringNoCtx(*args[0], pos, - "while evaluating the argument passed to builtins.parseFlakeRef")); - auto attrs = parseFlakeRef(state.fetchSettings, flakeRefS, {}, true).toAttrs(); - auto binds = state.buildBindings(attrs.size()); - for (const auto & [key, value] : attrs) { - auto s = state.symbols.create(key); - auto & vv = binds.alloc(s); - std::visit(overloaded { - [&vv](const std::string & value) { vv.mkString(value); }, - [&vv](const uint64_t & value) { vv.mkInt(value); }, - [&vv](const Explicit & value) { vv.mkBool(value.t); } - }, value); - } - v.mkAttrs(binds); -} - -static RegisterPrimOp r3({ - .name = "__parseFlakeRef", - .args = {"flake-ref"}, - .doc = R"( - Parse a flake reference, and return its exploded form. - - For example: - - ```nix - builtins.parseFlakeRef "github:NixOS/nixpkgs/23.05?dir=lib" - ``` - - evaluates to: - - ```nix - { dir = "lib"; owner = "NixOS"; ref = "23.05"; repo = "nixpkgs"; type = "github"; } - ``` - )", - .fun = prim_parseFlakeRef, -}); - - -static void prim_flakeRefToString( - EvalState & state, - const PosIdx pos, - Value * * args, - Value & v) -{ - state.forceAttrs(*args[0], noPos, - "while evaluating the argument passed to builtins.flakeRefToString"); - fetchers::Attrs attrs; - for (const auto & attr : *args[0]->attrs()) { - auto t = attr.value->type(); - if (t == nInt) { - auto intValue = attr.value->integer().value; - - if (intValue < 0) { - state.error("negative value given for flake ref attr %1%: %2%", state.symbols[attr.name], intValue).atPos(pos).debugThrow(); - } - - attrs.emplace(state.symbols[attr.name], uint64_t(intValue)); - } else if (t == nBool) { - attrs.emplace(state.symbols[attr.name], - Explicit { attr.value->boolean() }); - } else if (t == nString) { - attrs.emplace(state.symbols[attr.name], - std::string(attr.value->string_view())); - } else { - state.error( - "flake reference attribute sets may only contain integers, Booleans, " - "and strings, but attribute '%s' is %s", - state.symbols[attr.name], - showType(*attr.value)).debugThrow(); - } - } - auto flakeRef = FlakeRef::fromAttrs(state.fetchSettings, attrs); - v.mkString(flakeRef.to_string()); -} - -static RegisterPrimOp r4({ - .name = "__flakeRefToString", - .args = {"attrs"}, - .doc = R"( - Convert a flake reference from attribute set format to URL format. - - For example: - - ```nix - builtins.flakeRefToString { - dir = "lib"; owner = "NixOS"; ref = "23.05"; repo = "nixpkgs"; type = "github"; - } - ``` - - evaluates to - - ```nix - "github:NixOS/nixpkgs/23.05?dir=lib" - ``` - )", - .fun = prim_flakeRefToString, -}); - } std::optional LockedFlake::getFingerprint( diff --git a/src/libflake/flake/flakeref.cc b/src/libflake/flake/flakeref.cc index 4fc720eb5..6e95eb767 100644 --- a/src/libflake/flake/flakeref.cc +++ b/src/libflake/flake/flakeref.cc @@ -1,8 +1,8 @@ -#include "flakeref.hh" -#include "store-api.hh" -#include "url.hh" -#include "url-parts.hh" -#include "fetchers.hh" +#include "nix/flake/flakeref.hh" +#include "nix/store/store-api.hh" +#include "nix/util/url.hh" +#include "nix/util/url-parts.hh" +#include "nix/fetchers/fetchers.hh" namespace nix { diff --git a/src/libflake/flake/lockfile.cc b/src/libflake/flake/lockfile.cc index b0971a696..646516caf 100644 --- a/src/libflake/flake/lockfile.cc +++ b/src/libflake/flake/lockfile.cc @@ -1,10 +1,10 @@ #include -#include "fetch-settings.hh" -#include "flake/settings.hh" -#include "lockfile.hh" -#include "store-api.hh" -#include "strings.hh" +#include "nix/fetchers/fetch-settings.hh" +#include "nix/flake/settings.hh" +#include "nix/flake/lockfile.hh" +#include "nix/store/store-api.hh" +#include "nix/util/strings.hh" #include #include @@ -108,8 +108,13 @@ LockFile::LockFile( const fetchers::Settings & fetchSettings, std::string_view contents, std::string_view path) { - auto json = nlohmann::json::parse(contents); - + auto json = [=] { + try { + return nlohmann::json::parse(contents); + } catch (const nlohmann::json::parse_error & e) { + throw Error("Could not parse '%s': %s", path, e.what()); + } + }(); auto version = json.value("version", 0); if (version < 5 || version > 7) throw Error("lock file '%s' has unsupported version %d", path, version); diff --git a/src/libflake/flake/settings.cc b/src/libflake/flake/settings.cc index 6a0294e62..bab7f9439 100644 --- a/src/libflake/flake/settings.cc +++ b/src/libflake/flake/settings.cc @@ -1,7 +1,15 @@ -#include "flake/settings.hh" +#include "nix/flake/settings.hh" +#include "nix/flake/flake-primops.hh" namespace nix::flake { Settings::Settings() {} +void Settings::configureEvalSettings(nix::EvalSettings & evalSettings) const +{ + evalSettings.extraPrimOps.emplace_back(primops::getFlake(*this)); + evalSettings.extraPrimOps.emplace_back(primops::parseFlakeRef); + evalSettings.extraPrimOps.emplace_back(primops::flakeRefToString); } + +} // namespace nix diff --git a/src/libflake/flake/url-name.cc b/src/libflake/flake/url-name.cc index d62b34552..3e3311cf7 100644 --- a/src/libflake/flake/url-name.cc +++ b/src/libflake/flake/url-name.cc @@ -1,4 +1,4 @@ -#include "url-name.hh" +#include "nix/flake/url-name.hh" #include #include diff --git a/src/libflake/include/nix/flake/flake-primops.hh b/src/libflake/include/nix/flake/flake-primops.hh new file mode 100644 index 000000000..e7b86b9b3 --- /dev/null +++ b/src/libflake/include/nix/flake/flake-primops.hh @@ -0,0 +1,16 @@ +#pragma once + +#include "nix/expr/eval.hh" +#include "nix/flake/settings.hh" + +namespace nix::flake::primops { + +/** + * Returns a `builtins.getFlake` primop with the given nix::flake::Settings. + */ +nix::PrimOp getFlake(const Settings & settings); + +extern nix::PrimOp parseFlakeRef; +extern nix::PrimOp flakeRefToString; + +} // namespace nix::flake diff --git a/src/libflake/flake/flake.hh b/src/libflake/include/nix/flake/flake.hh similarity index 95% rename from src/libflake/flake/flake.hh rename to src/libflake/include/nix/flake/flake.hh index d8cd9aac0..3336f8557 100644 --- a/src/libflake/flake/flake.hh +++ b/src/libflake/include/nix/flake/flake.hh @@ -1,10 +1,10 @@ #pragma once ///@file -#include "types.hh" -#include "flakeref.hh" -#include "lockfile.hh" -#include "value.hh" +#include "nix/util/types.hh" +#include "nix/flake/flakeref.hh" +#include "nix/flake/lockfile.hh" +#include "nix/expr/value.hh" namespace nix { @@ -14,14 +14,6 @@ namespace flake { struct Settings; -/** - * Initialize `libnixflake` - * - * So far, this registers the `builtins.getFlake` primop, which depends - * on the choice of `flake:Settings`. - */ -void initLib(const Settings & settings); - struct FlakeInput; typedef std::map FlakeInputs; diff --git a/src/libflake/flake/flakeref.hh b/src/libflake/include/nix/flake/flakeref.hh similarity index 96% rename from src/libflake/flake/flakeref.hh rename to src/libflake/include/nix/flake/flakeref.hh index d3c15018e..0fd1fec4d 100644 --- a/src/libflake/flake/flakeref.hh +++ b/src/libflake/include/nix/flake/flakeref.hh @@ -3,10 +3,10 @@ #include -#include "types.hh" -#include "fetchers.hh" -#include "outputs-spec.hh" -#include "registry.hh" +#include "nix/util/types.hh" +#include "nix/fetchers/fetchers.hh" +#include "nix/store/outputs-spec.hh" +#include "nix/fetchers/registry.hh" namespace nix { diff --git a/src/libflake/flake/lockfile.hh b/src/libflake/include/nix/flake/lockfile.hh similarity index 98% rename from src/libflake/flake/lockfile.hh rename to src/libflake/include/nix/flake/lockfile.hh index cbc6d01eb..97bd7a495 100644 --- a/src/libflake/flake/lockfile.hh +++ b/src/libflake/include/nix/flake/lockfile.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "flakeref.hh" +#include "nix/flake/flakeref.hh" #include diff --git a/src/libflake/include/nix/flake/meson.build b/src/libflake/include/nix/flake/meson.build new file mode 100644 index 000000000..ece1ad4ea --- /dev/null +++ b/src/libflake/include/nix/flake/meson.build @@ -0,0 +1,11 @@ +# Public headers directory + +include_dirs = [include_directories('../..')] + +headers = files( + 'flake.hh', + 'flakeref.hh', + 'lockfile.hh', + 'settings.hh', + 'url-name.hh', +) diff --git a/src/libflake/flake/settings.hh b/src/libflake/include/nix/flake/settings.hh similarity index 81% rename from src/libflake/flake/settings.hh rename to src/libflake/include/nix/flake/settings.hh index faf76249c..c9f82218c 100644 --- a/src/libflake/flake/settings.hh +++ b/src/libflake/include/nix/flake/settings.hh @@ -1,21 +1,24 @@ #pragma once ///@file -#include "types.hh" -#include "config.hh" -#include "util.hh" - -#include -#include +#include "nix/util/configuration.hh" #include +namespace nix { +// Forward declarations +struct EvalSettings; + +} // namespace nix + namespace nix::flake { struct Settings : public Config { Settings(); + void configureEvalSettings(nix::EvalSettings & evalSettings) const; + Setting useRegistries{ this, true, "use-registries", "Whether to use flake registries to resolve flake references.", {}, true}; diff --git a/src/libflake/flake/url-name.hh b/src/libflake/include/nix/flake/url-name.hh similarity index 83% rename from src/libflake/flake/url-name.hh rename to src/libflake/include/nix/flake/url-name.hh index 6f32754d2..d295ca8f8 100644 --- a/src/libflake/flake/url-name.hh +++ b/src/libflake/include/nix/flake/url-name.hh @@ -1,7 +1,7 @@ -#include "url.hh" -#include "url-parts.hh" -#include "util.hh" -#include "split.hh" +#include "nix/util/url.hh" +#include "nix/util/url-parts.hh" +#include "nix/util/util.hh" +#include "nix/util/split.hh" namespace nix { diff --git a/src/libflake/meson.build b/src/libflake/meson.build index b757d0d76..f4c034490 100644 --- a/src/libflake/meson.build +++ b/src/libflake/meson.build @@ -27,46 +27,44 @@ subdir('nix-meson-build-support/subprojects') nlohmann_json = dependency('nlohmann_json', version : '>= 3.9') deps_public += nlohmann_json -add_project_arguments( - # TODO(Qyriad): Yes this is how the autoconf+Make system did it. - # It would be nice for our headers to be idempotent instead. - '-include', 'config-util.hh', - '-include', 'config-store.hh', - # '-include', 'config-fetchers.h', - '-include', 'config-expr.hh', - language : 'cpp', -) - subdir('nix-meson-build-support/common') +subdir('nix-meson-build-support/generate-header') + +generated_headers = [] +foreach header : [ + 'call-flake.nix', +] + generated_headers += gen_header.process(header) +endforeach + sources = files( 'flake/config.cc', 'flake/flake.cc', 'flake/flakeref.cc', 'flake/lockfile.cc', + 'flake/flake-primops.cc', 'flake/settings.cc', 'flake/url-name.cc', ) -include_dirs = [include_directories('.')] +subdir('include/nix/flake') -headers = files( - 'flake/flake.hh', - 'flake/flakeref.hh', - 'flake/lockfile.hh', - 'flake/settings.hh', - 'flake/url-name.hh', -) +subdir('nix-meson-build-support/export-all-symbols') +subdir('nix-meson-build-support/windows-version') this_library = library( 'nixflake', sources, + generated_headers, dependencies : deps_public + deps_private + deps_other, + include_directories : include_dirs, + link_args: linker_export_flags, prelink : true, # For C++ static initializers install : true, ) -install_headers(headers, subdir : 'nix', preserve_path : true) +install_headers(headers, subdir : 'nix/flake', preserve_path : true) libraries_private = [] diff --git a/src/libflake/package.nix b/src/libflake/package.nix index 2c28235f1..2b0c827a0 100644 --- a/src/libflake/package.nix +++ b/src/libflake/package.nix @@ -28,6 +28,8 @@ mkMesonLibrary (finalAttrs: { ../../.version ./.version ./meson.build + ./include/nix/flake/meson.build + ./call-flake.nix (fileset.fileFilter (file: file.hasExt "cc") ./.) (fileset.fileFilter (file: file.hasExt "hh") ./.) ]; diff --git a/src/libmain-c/meson.build b/src/libmain-c/meson.build index d875d2c3f..e420520e6 100644 --- a/src/libmain-c/meson.build +++ b/src/libmain-c/meson.build @@ -14,8 +14,6 @@ cxx = meson.get_compiler('cpp') subdir('nix-meson-build-support/deps-lists') -configdata = configuration_data() - deps_private_maybe_subproject = [ dependency('nix-util'), dependency('nix-store'), @@ -27,30 +25,6 @@ deps_public_maybe_subproject = [ ] subdir('nix-meson-build-support/subprojects') -# TODO rename, because it will conflict with downstream projects -configdata.set_quoted('PACKAGE_VERSION', meson.project_version()) - -config_h = configure_file( - configuration : configdata, - output : 'config-main.h', -) - -add_project_arguments( - # TODO(Qyriad): Yes this is how the autoconf+Make system did it. - # It would be nice for our headers to be idempotent instead. - - # From C++ libraries, only for internals - '-include', 'config-util.hh', - '-include', 'config-store.hh', - '-include', 'config-main.hh', - - # From C libraries, for our public, installed headers too - '-include', 'config-util.h', - '-include', 'config-store.h', - '-include', 'config-main.h', - language : 'cpp', -) - subdir('nix-meson-build-support/common') sources = files( @@ -59,7 +33,7 @@ sources = files( include_dirs = [include_directories('.')] -headers = [config_h] + files( +headers = files( 'nix_api_main.h', ) @@ -76,7 +50,7 @@ this_library = library( install : true, ) -install_headers(headers, subdir : 'nix', preserve_path : true) +install_headers(headers, preserve_path : true) libraries_private = [] diff --git a/src/libmain-c/nix_api_main.cc b/src/libmain-c/nix_api_main.cc index 692d53f47..eacb80455 100644 --- a/src/libmain-c/nix_api_main.cc +++ b/src/libmain-c/nix_api_main.cc @@ -3,7 +3,7 @@ #include "nix_api_util.h" #include "nix_api_util_internal.h" -#include "plugin.hh" +#include "nix/main/plugin.hh" nix_err nix_init_plugins(nix_c_context * context) { diff --git a/src/libmain/common-args.cc b/src/libmain/common-args.cc index 13d358623..c3338996c 100644 --- a/src/libmain/common-args.cc +++ b/src/libmain/common-args.cc @@ -1,11 +1,11 @@ -#include "common-args.hh" -#include "args/root.hh" -#include "config-global.hh" -#include "globals.hh" -#include "logging.hh" -#include "loggers.hh" -#include "util.hh" -#include "plugin.hh" +#include "nix/main/common-args.hh" +#include "nix/util/args/root.hh" +#include "nix/util/config-global.hh" +#include "nix/store/globals.hh" +#include "nix/util/logging.hh" +#include "nix/main/loggers.hh" +#include "nix/util/util.hh" +#include "nix/main/plugin.hh" namespace nix { diff --git a/src/libmain/common-args.hh b/src/libmain/include/nix/main/common-args.hh similarity index 96% rename from src/libmain/common-args.hh rename to src/libmain/include/nix/main/common-args.hh index c35406c3b..ae0f3c6c5 100644 --- a/src/libmain/common-args.hh +++ b/src/libmain/include/nix/main/common-args.hh @@ -1,8 +1,8 @@ #pragma once ///@file -#include "args.hh" -#include "repair-flag.hh" +#include "nix/util/args.hh" +#include "nix/util/repair-flag.hh" namespace nix { diff --git a/src/libmain/loggers.hh b/src/libmain/include/nix/main/loggers.hh similarity index 88% rename from src/libmain/loggers.hh rename to src/libmain/include/nix/main/loggers.hh index 98b287fa7..061b4a32a 100644 --- a/src/libmain/loggers.hh +++ b/src/libmain/include/nix/main/loggers.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "types.hh" +#include "nix/util/types.hh" namespace nix { diff --git a/src/libmain/include/nix/main/meson.build b/src/libmain/include/nix/main/meson.build new file mode 100644 index 000000000..992a5ff0e --- /dev/null +++ b/src/libmain/include/nix/main/meson.build @@ -0,0 +1,11 @@ +# Public headers directory + +include_dirs = [include_directories('../..')] + +headers = files( + 'common-args.hh', + 'loggers.hh', + 'plugin.hh', + 'progress-bar.hh', + 'shared.hh', +) diff --git a/src/libmain/plugin.hh b/src/libmain/include/nix/main/plugin.hh similarity index 100% rename from src/libmain/plugin.hh rename to src/libmain/include/nix/main/plugin.hh diff --git a/src/libmain/progress-bar.hh b/src/libmain/include/nix/main/progress-bar.hh similarity index 73% rename from src/libmain/progress-bar.hh rename to src/libmain/include/nix/main/progress-bar.hh index fc1b0fe78..f49fb2198 100644 --- a/src/libmain/progress-bar.hh +++ b/src/libmain/include/nix/main/progress-bar.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "logging.hh" +#include "nix/util/logging.hh" namespace nix { diff --git a/src/libmain/shared.hh b/src/libmain/include/nix/main/shared.hh similarity index 94% rename from src/libmain/shared.hh rename to src/libmain/include/nix/main/shared.hh index a6a18ceb0..2ff57135b 100644 --- a/src/libmain/shared.hh +++ b/src/libmain/include/nix/main/shared.hh @@ -1,13 +1,13 @@ #pragma once ///@file -#include "file-descriptor.hh" -#include "processes.hh" -#include "args.hh" -#include "args/root.hh" -#include "common-args.hh" -#include "path.hh" -#include "derived-path.hh" +#include "nix/util/file-descriptor.hh" +#include "nix/util/processes.hh" +#include "nix/util/args.hh" +#include "nix/util/args/root.hh" +#include "nix/main/common-args.hh" +#include "nix/store/path.hh" +#include "nix/store/derived-path.hh" #include diff --git a/src/libmain/loggers.cc b/src/libmain/loggers.cc index 07d83a960..c78e49b63 100644 --- a/src/libmain/loggers.cc +++ b/src/libmain/loggers.cc @@ -1,6 +1,6 @@ -#include "loggers.hh" -#include "environment-variables.hh" -#include "progress-bar.hh" +#include "nix/main/loggers.hh" +#include "nix/util/environment-variables.hh" +#include "nix/main/progress-bar.hh" namespace nix { diff --git a/src/libmain/meson.build b/src/libmain/meson.build index 00f945f49..65fcb6239 100644 --- a/src/libmain/meson.build +++ b/src/libmain/meson.build @@ -21,6 +21,10 @@ deps_private_maybe_subproject = [ deps_public_maybe_subproject = [ dependency('nix-util'), dependency('nix-store'), + # FIXME: This is only here for the NIX_USE_BOEHMGC macro dependency + # Removing nix-expr will make the build more concurrent and is + # architecturally nice, perhaps. + dependency('nix-expr'), ] subdir('nix-meson-build-support/subprojects') @@ -42,18 +46,9 @@ configdata.set( description: 'Optionally used for buffering on standard error' ) -config_h = configure_file( +config_priv_h = configure_file( configuration : configdata, - output : 'config-main.hh', -) - -add_project_arguments( - # TODO(Qyriad): Yes this is how the autoconf+Make system did it. - # It would be nice for our headers to be idempotent instead. - '-include', 'config-util.hh', - '-include', 'config-store.hh', - '-include', 'config-main.hh', - language : 'cpp', + output : 'main-config-private.hh', ) subdir('nix-meson-build-support/common') @@ -72,25 +67,23 @@ if host_machine.system() != 'windows' ) endif -include_dirs = [include_directories('.')] +subdir('include/nix/main') -headers = [config_h] + files( - 'common-args.hh', - 'loggers.hh', - 'plugin.hh', - 'progress-bar.hh', - 'shared.hh', -) +subdir('nix-meson-build-support/export-all-symbols') +subdir('nix-meson-build-support/windows-version') this_library = library( 'nixmain', sources, + config_priv_h, dependencies : deps_public + deps_private + deps_other, + include_directories : include_dirs, + link_args: linker_export_flags, prelink : true, # For C++ static initializers install : true, ) -install_headers(headers, subdir : 'nix', preserve_path : true) +install_headers(headers, subdir : 'nix/main', preserve_path : true) libraries_private = [] diff --git a/src/libmain/package.nix b/src/libmain/package.nix index 5ee2e61e4..119e1f1ac 100644 --- a/src/libmain/package.nix +++ b/src/libmain/package.nix @@ -6,6 +6,7 @@ nix-util, nix-store, + nix-expr, # Configuration Options @@ -27,11 +28,16 @@ mkMesonLibrary (finalAttrs: { ../../.version ./.version ./meson.build + ./include/nix/main/meson.build (fileset.fileFilter (file: file.hasExt "cc") ./.) (fileset.fileFilter (file: file.hasExt "hh") ./.) ]; propagatedBuildInputs = [ + # FIXME: This is only here for the NIX_USE_BOEHMGC macro dependency + # Removing nix-expr will make the build more concurrent and is + # architecturally nice, perhaps. + nix-expr nix-util nix-store openssl diff --git a/src/libmain/plugin.cc b/src/libmain/plugin.cc index ccfd7f900..63ed650a7 100644 --- a/src/libmain/plugin.cc +++ b/src/libmain/plugin.cc @@ -4,8 +4,8 @@ #include -#include "config-global.hh" -#include "signals.hh" +#include "nix/util/config-global.hh" +#include "nix/util/signals.hh" namespace nix { diff --git a/src/libmain/progress-bar.cc b/src/libmain/progress-bar.cc index 2d4d901db..23f5ff8f7 100644 --- a/src/libmain/progress-bar.cc +++ b/src/libmain/progress-bar.cc @@ -1,8 +1,8 @@ -#include "progress-bar.hh" -#include "terminal.hh" -#include "sync.hh" -#include "store-api.hh" -#include "names.hh" +#include "nix/main/progress-bar.hh" +#include "nix/util/terminal.hh" +#include "nix/util/sync.hh" +#include "nix/store/store-api.hh" +#include "nix/store/names.hh" #include #include diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index 28869c4db..62bd3b1d3 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -1,11 +1,11 @@ -#include "globals.hh" -#include "current-process.hh" -#include "shared.hh" -#include "store-api.hh" -#include "gc-store.hh" -#include "loggers.hh" -#include "progress-bar.hh" -#include "signals.hh" +#include "nix/store/globals.hh" +#include "nix/util/current-process.hh" +#include "nix/main/shared.hh" +#include "nix/store/store-api.hh" +#include "nix/store/gc-store.hh" +#include "nix/main/loggers.hh" +#include "nix/main/progress-bar.hh" +#include "nix/util/signals.hh" #include #include @@ -22,8 +22,11 @@ #include -#include "exit.hh" -#include "strings.hh" +#include "nix/util/exit.hh" +#include "nix/util/strings.hh" + +#include "main-config-private.hh" +#include "nix/expr/config.hh" namespace nix { @@ -141,7 +144,7 @@ void initNix(bool loadConfig) if (sigaction(SIGUSR1, &act, 0)) throw SysError("handling SIGUSR1"); #endif -#if __APPLE__ +#ifdef __APPLE__ /* HACK: on darwin, we need can’t use sigprocmask with SIGWINCH. * Instead, add a dummy sigaction handler, and signalHandlerThread * can handle the rest. */ @@ -297,7 +300,7 @@ void printVersion(const std::string & programName) std::cout << fmt("%s (Determinate Nix %s) %s", programName, determinateNixVersion, nixVersion) << std::endl; if (verbosity > lvlInfo) { Strings cfg; -#if HAVE_BOEHMGC +#if NIX_USE_BOEHMGC cfg.push_back("gc"); #endif cfg.push_back("signed-caches"); diff --git a/src/libmain/unix/stack.cc b/src/libmain/unix/stack.cc index 10f71c1dc..cee21d2a2 100644 --- a/src/libmain/unix/stack.cc +++ b/src/libmain/unix/stack.cc @@ -1,5 +1,5 @@ -#include "error.hh" -#include "shared.hh" +#include "nix/util/error.hh" +#include "nix/main/shared.hh" #include #include diff --git a/src/libstore-c/meson.build b/src/libstore-c/meson.build index 17d18609f..eb5563161 100644 --- a/src/libstore-c/meson.build +++ b/src/libstore-c/meson.build @@ -14,8 +14,6 @@ cxx = meson.get_compiler('cpp') subdir('nix-meson-build-support/deps-lists') -configdata = configuration_data() - deps_private_maybe_subproject = [ dependency('nix-util'), dependency('nix-store'), @@ -25,28 +23,6 @@ deps_public_maybe_subproject = [ ] subdir('nix-meson-build-support/subprojects') -# TODO rename, because it will conflict with downstream projects -configdata.set_quoted('PACKAGE_VERSION', meson.project_version()) - -config_h = configure_file( - configuration : configdata, - output : 'config-store.h', -) - -add_project_arguments( - # TODO(Qyriad): Yes this is how the autoconf+Make system did it. - # It would be nice for our headers to be idempotent instead. - - # From C++ libraries, only for internals - '-include', 'config-util.hh', - '-include', 'config-store.hh', - - # From C libraries, for our public, installed headers too - '-include', 'config-util.h', - '-include', 'config-store.h', - language : 'cpp', -) - subdir('nix-meson-build-support/common') sources = files( @@ -55,7 +31,7 @@ sources = files( include_dirs = [include_directories('.')] -headers = [config_h] + files( +headers = files( 'nix_api_store.h', ) @@ -75,7 +51,7 @@ this_library = library( install : true, ) -install_headers(headers, subdir : 'nix', preserve_path : true) +install_headers(headers, preserve_path : true) libraries_private = [] diff --git a/src/libstore-c/nix_api_store.cc b/src/libstore-c/nix_api_store.cc index bc306e0d0..92aed9187 100644 --- a/src/libstore-c/nix_api_store.cc +++ b/src/libstore-c/nix_api_store.cc @@ -3,11 +3,11 @@ #include "nix_api_util.h" #include "nix_api_util_internal.h" -#include "path.hh" -#include "store-api.hh" -#include "build-result.hh" +#include "nix/store/path.hh" +#include "nix/store/store-api.hh" +#include "nix/store/build-result.hh" -#include "globals.hh" +#include "nix/store/globals.hh" nix_err nix_libstore_init(nix_c_context * context) { diff --git a/src/libstore-c/nix_api_store_internal.h b/src/libstore-c/nix_api_store_internal.h index 13db0c07c..b0194bfd3 100644 --- a/src/libstore-c/nix_api_store_internal.h +++ b/src/libstore-c/nix_api_store_internal.h @@ -1,6 +1,6 @@ #ifndef NIX_API_STORE_INTERNAL_H #define NIX_API_STORE_INTERNAL_H -#include "store-api.hh" +#include "nix/store/store-api.hh" struct Store { diff --git a/src/libstore-test-support/derived-path.cc b/src/libstore-test-support/derived-path.cc new file mode 100644 index 000000000..c7714449c --- /dev/null +++ b/src/libstore-test-support/derived-path.cc @@ -0,0 +1,71 @@ +#include + +#include + +#include "nix/store/tests/derived-path.hh" + +namespace rc { +using namespace nix; + +Gen Arbitrary::arbitrary() +{ + return gen::map(gen::arbitrary(), [](StorePath path) { + return DerivedPath::Opaque{ + .path = path, + }; + }); +} + +Gen Arbitrary::arbitrary() +{ + return gen::mapcat(gen::arbitrary(), [](SingleDerivedPath drvPath) { + return gen::map(gen::arbitrary(), [drvPath](StorePathName outputPath) { + return SingleDerivedPath::Built{ + .drvPath = make_ref(drvPath), + .output = outputPath.name, + }; + }); + }); +} + +Gen Arbitrary::arbitrary() +{ + return gen::mapcat(gen::arbitrary(), [](SingleDerivedPath drvPath) { + return gen::map(gen::arbitrary(), [drvPath](OutputsSpec outputs) { + return DerivedPath::Built{ + .drvPath = make_ref(drvPath), + .outputs = outputs, + }; + }); + }); +} + +Gen Arbitrary::arbitrary() +{ + return gen::mapcat(gen::inRange(0, std::variant_size_v), [](uint8_t n) { + switch (n) { + case 0: + return gen::map(gen::arbitrary(), [](SingleDerivedPath a) { return a; }); + case 1: + return gen::map(gen::arbitrary(), [](SingleDerivedPath a) { return a; }); + default: + assert(false); + } + }); +} + +Gen Arbitrary::arbitrary() +{ + return gen::mapcat(gen::inRange(0, std::variant_size_v), [](uint8_t n) { + switch (n) { + case 0: + return gen::map(gen::arbitrary(), [](DerivedPath a) { return a; }); + case 1: + return gen::map(gen::arbitrary(), [](DerivedPath a) { return a; }); + default: + assert(false); + } + }); +} + +} diff --git a/src/libstore-test-support/tests/derived-path.hh b/src/libstore-test-support/include/nix/store/tests/derived-path.hh similarity index 84% rename from src/libstore-test-support/tests/derived-path.hh rename to src/libstore-test-support/include/nix/store/tests/derived-path.hh index 98d61f228..642ce557c 100644 --- a/src/libstore-test-support/tests/derived-path.hh +++ b/src/libstore-test-support/include/nix/store/tests/derived-path.hh @@ -3,10 +3,10 @@ #include -#include +#include "nix/store/derived-path.hh" -#include "tests/path.hh" -#include "tests/outputs-spec.hh" +#include "nix/store/tests/path.hh" +#include "nix/store/tests/outputs-spec.hh" namespace rc { using namespace nix; diff --git a/src/libstore-test-support/tests/libstore.hh b/src/libstore-test-support/include/nix/store/tests/libstore.hh similarity index 93% rename from src/libstore-test-support/tests/libstore.hh rename to src/libstore-test-support/include/nix/store/tests/libstore.hh index 699ba957e..466b6f9b1 100644 --- a/src/libstore-test-support/tests/libstore.hh +++ b/src/libstore-test-support/include/nix/store/tests/libstore.hh @@ -4,7 +4,7 @@ #include #include -#include "store-api.hh" +#include "nix/store/store-api.hh" namespace nix { diff --git a/src/libstore-test-support/include/nix/store/tests/meson.build b/src/libstore-test-support/include/nix/store/tests/meson.build new file mode 100644 index 000000000..ae5db049e --- /dev/null +++ b/src/libstore-test-support/include/nix/store/tests/meson.build @@ -0,0 +1,12 @@ +# Public headers directory + +include_dirs = [include_directories('../../..')] + +headers = files( + 'derived-path.hh', + 'libstore.hh', + 'nix_api_store.hh', + 'outputs-spec.hh', + 'path.hh', + 'protocol.hh', +) diff --git a/src/libstore-test-support/tests/nix_api_store.hh b/src/libstore-test-support/include/nix/store/tests/nix_api_store.hh similarity index 96% rename from src/libstore-test-support/tests/nix_api_store.hh rename to src/libstore-test-support/include/nix/store/tests/nix_api_store.hh index b7d5c2c33..bc0f31d05 100644 --- a/src/libstore-test-support/tests/nix_api_store.hh +++ b/src/libstore-test-support/include/nix/store/tests/nix_api_store.hh @@ -1,8 +1,8 @@ #pragma once ///@file -#include "tests/nix_api_util.hh" +#include "nix/util/tests/nix_api_util.hh" -#include "file-system.hh" +#include "nix/util/file-system.hh" #include #include "nix_api_store.h" diff --git a/src/libstore-test-support/tests/outputs-spec.hh b/src/libstore-test-support/include/nix/store/tests/outputs-spec.hh similarity index 72% rename from src/libstore-test-support/tests/outputs-spec.hh rename to src/libstore-test-support/include/nix/store/tests/outputs-spec.hh index f5bf9042d..c13c992b6 100644 --- a/src/libstore-test-support/tests/outputs-spec.hh +++ b/src/libstore-test-support/include/nix/store/tests/outputs-spec.hh @@ -3,9 +3,9 @@ #include -#include +#include "nix/store/outputs-spec.hh" -#include "tests/path.hh" +#include "nix/store/tests/path.hh" namespace rc { using namespace nix; diff --git a/src/libstore-test-support/tests/path.hh b/src/libstore-test-support/include/nix/store/tests/path.hh similarity index 93% rename from src/libstore-test-support/tests/path.hh rename to src/libstore-test-support/include/nix/store/tests/path.hh index 4751b3373..59ff604d7 100644 --- a/src/libstore-test-support/tests/path.hh +++ b/src/libstore-test-support/include/nix/store/tests/path.hh @@ -3,7 +3,7 @@ #include -#include +#include "nix/store/path.hh" namespace nix { diff --git a/src/libstore-test-support/tests/protocol.hh b/src/libstore-test-support/include/nix/store/tests/protocol.hh similarity index 96% rename from src/libstore-test-support/tests/protocol.hh rename to src/libstore-test-support/include/nix/store/tests/protocol.hh index 3f6799d1c..acd10bf9d 100644 --- a/src/libstore-test-support/tests/protocol.hh +++ b/src/libstore-test-support/include/nix/store/tests/protocol.hh @@ -4,8 +4,8 @@ #include #include -#include "tests/libstore.hh" -#include "tests/characterization.hh" +#include "nix/store/tests/libstore.hh" +#include "nix/util/tests/characterization.hh" namespace nix { diff --git a/src/libstore-test-support/meson.build b/src/libstore-test-support/meson.build index 59d649889..779b122fa 100644 --- a/src/libstore-test-support/meson.build +++ b/src/libstore-test-support/meson.build @@ -27,32 +27,15 @@ subdir('nix-meson-build-support/subprojects') rapidcheck = dependency('rapidcheck') deps_public += rapidcheck -add_project_arguments( - # TODO(Qyriad): Yes this is how the autoconf+Make system did it. - # It would be nice for our headers to be idempotent instead. - '-include', 'config-util.hh', - '-include', 'config-store.hh', - language : 'cpp', -) - subdir('nix-meson-build-support/common') sources = files( - 'tests/derived-path.cc', - 'tests/outputs-spec.cc', - 'tests/path.cc', + 'derived-path.cc', + 'outputs-spec.cc', + 'path.cc', ) -include_dirs = [include_directories('.')] - -headers = files( - 'tests/derived-path.hh', - 'tests/libstore.hh', - 'tests/nix_api_store.hh', - 'tests/outputs-spec.hh', - 'tests/path.hh', - 'tests/protocol.hh', -) +subdir('include/nix/store/tests') subdir('nix-meson-build-support/export-all-symbols') subdir('nix-meson-build-support/windows-version') @@ -69,7 +52,7 @@ this_library = library( install : true, ) -install_headers(headers, subdir : 'nix', preserve_path : true) +install_headers(headers, subdir : 'nix/store/tests', preserve_path : true) libraries_private = [] diff --git a/src/libstore-test-support/outputs-spec.cc b/src/libstore-test-support/outputs-spec.cc new file mode 100644 index 000000000..e186ad8ae --- /dev/null +++ b/src/libstore-test-support/outputs-spec.cc @@ -0,0 +1,26 @@ +#include "nix/store/tests/outputs-spec.hh" + +#include + +namespace rc { +using namespace nix; + +Gen Arbitrary::arbitrary() +{ + return gen::mapcat( + gen::inRange(0, std::variant_size_v), [](uint8_t n) -> Gen { + switch (n) { + case 0: + return gen::just((OutputsSpec) OutputsSpec::All{}); + case 1: + return gen::map( + gen::nonEmpty(gen::container( + gen::map(gen::arbitrary(), [](StorePathName n) { return n.name; }))), + [](StringSet names) { return (OutputsSpec) OutputsSpec::Names{names}; }); + default: + assert(false); + } + }); +} + +} diff --git a/src/libstore-test-support/package.nix b/src/libstore-test-support/package.nix index 8a4658ae7..2561dd791 100644 --- a/src/libstore-test-support/package.nix +++ b/src/libstore-test-support/package.nix @@ -29,6 +29,7 @@ mkMesonLibrary (finalAttrs: { ./.version ./meson.build # ./meson.options + ./include/nix/store/tests/meson.build (fileset.fileFilter (file: file.hasExt "cc") ./.) (fileset.fileFilter (file: file.hasExt "hh") ./.) ]; diff --git a/src/libstore-test-support/tests/path.cc b/src/libstore-test-support/path.cc similarity index 92% rename from src/libstore-test-support/tests/path.cc rename to src/libstore-test-support/path.cc index 8ddda8027..47c1d693b 100644 --- a/src/libstore-test-support/tests/path.cc +++ b/src/libstore-test-support/path.cc @@ -3,11 +3,11 @@ #include -#include "path-regex.hh" -#include "store-api.hh" +#include "nix/store/path-regex.hh" +#include "nix/store/store-api.hh" -#include "tests/hash.hh" -#include "tests/path.hh" +#include "nix/util/tests/hash.hh" +#include "nix/store/tests/path.hh" namespace nix { diff --git a/src/libstore-test-support/tests/derived-path.cc b/src/libstore-test-support/tests/derived-path.cc deleted file mode 100644 index 078615bbd..000000000 --- a/src/libstore-test-support/tests/derived-path.cc +++ /dev/null @@ -1,57 +0,0 @@ -#include - -#include - -#include "tests/derived-path.hh" - -namespace rc { -using namespace nix; - -Gen Arbitrary::arbitrary() -{ - return gen::just(DerivedPath::Opaque { - .path = *gen::arbitrary(), - }); -} - -Gen Arbitrary::arbitrary() -{ - return gen::just(SingleDerivedPath::Built { - .drvPath = make_ref(*gen::arbitrary()), - .output = (*gen::arbitrary()).name, - }); -} - -Gen Arbitrary::arbitrary() -{ - return gen::just(DerivedPath::Built { - .drvPath = make_ref(*gen::arbitrary()), - .outputs = *gen::arbitrary(), - }); -} - -Gen Arbitrary::arbitrary() -{ - switch (*gen::inRange(0, std::variant_size_v)) { - case 0: - return gen::just(*gen::arbitrary()); - case 1: - return gen::just(*gen::arbitrary()); - default: - assert(false); - } -} - -Gen Arbitrary::arbitrary() -{ - switch (*gen::inRange(0, std::variant_size_v)) { - case 0: - return gen::just(*gen::arbitrary()); - case 1: - return gen::just(*gen::arbitrary()); - default: - assert(false); - } -} - -} diff --git a/src/libstore-test-support/tests/outputs-spec.cc b/src/libstore-test-support/tests/outputs-spec.cc deleted file mode 100644 index e9d602203..000000000 --- a/src/libstore-test-support/tests/outputs-spec.cc +++ /dev/null @@ -1,24 +0,0 @@ -#include "tests/outputs-spec.hh" - -#include - -namespace rc { -using namespace nix; - -Gen Arbitrary::arbitrary() -{ - switch (*gen::inRange(0, std::variant_size_v)) { - case 0: - return gen::just((OutputsSpec) OutputsSpec::All { }); - case 1: - return gen::just((OutputsSpec) OutputsSpec::Names { - *gen::nonEmpty(gen::container(gen::map( - gen::arbitrary(), - [](StorePathName n) { return n.name; }))), - }); - default: - assert(false); - } -} - -} diff --git a/src/libstore-tests/common-protocol.cc b/src/libstore-tests/common-protocol.cc index c8f6dd002..6bfb8bd80 100644 --- a/src/libstore-tests/common-protocol.cc +++ b/src/libstore-tests/common-protocol.cc @@ -3,11 +3,11 @@ #include #include -#include "common-protocol.hh" -#include "common-protocol-impl.hh" -#include "build-result.hh" -#include "tests/protocol.hh" -#include "tests/characterization.hh" +#include "nix/store/common-protocol.hh" +#include "nix/store/common-protocol-impl.hh" +#include "nix/store/build-result.hh" +#include "nix/store/tests/protocol.hh" +#include "nix/util/tests/characterization.hh" namespace nix { diff --git a/src/libstore-tests/content-address.cc b/src/libstore-tests/content-address.cc index 72eb84fec..c208c944d 100644 --- a/src/libstore-tests/content-address.cc +++ b/src/libstore-tests/content-address.cc @@ -1,6 +1,6 @@ #include -#include "content-address.hh" +#include "nix/store/content-address.hh" namespace nix { diff --git a/src/libstore-tests/derivation-advanced-attrs.cc b/src/libstore-tests/derivation-advanced-attrs.cc index 107cf13e3..57b226826 100644 --- a/src/libstore-tests/derivation-advanced-attrs.cc +++ b/src/libstore-tests/derivation-advanced-attrs.cc @@ -1,16 +1,16 @@ #include #include -#include "experimental-features.hh" -#include "derivations.hh" -#include "derivations.hh" -#include "derivation-options.hh" -#include "parsed-derivations.hh" -#include "types.hh" -#include "json-utils.hh" +#include "nix/util/experimental-features.hh" +#include "nix/store/derivations.hh" +#include "nix/store/derivations.hh" +#include "nix/store/derivation-options.hh" +#include "nix/store/parsed-derivations.hh" +#include "nix/util/types.hh" +#include "nix/util/json-utils.hh" -#include "tests/libstore.hh" -#include "tests/characterization.hh" +#include "nix/store/tests/libstore.hh" +#include "nix/util/tests/characterization.hh" namespace nix { diff --git a/src/libstore-tests/derivation.cc b/src/libstore-tests/derivation.cc index 14652921a..fa6711d40 100644 --- a/src/libstore-tests/derivation.cc +++ b/src/libstore-tests/derivation.cc @@ -1,11 +1,11 @@ #include #include -#include "experimental-features.hh" -#include "derivations.hh" +#include "nix/util/experimental-features.hh" +#include "nix/store/derivations.hh" -#include "tests/libstore.hh" -#include "tests/characterization.hh" +#include "nix/store/tests/libstore.hh" +#include "nix/util/tests/characterization.hh" namespace nix { diff --git a/src/libstore-tests/derived-path.cc b/src/libstore-tests/derived-path.cc index c62d79a78..51df25198 100644 --- a/src/libstore-tests/derived-path.cc +++ b/src/libstore-tests/derived-path.cc @@ -3,8 +3,8 @@ #include #include -#include "tests/derived-path.hh" -#include "tests/libstore.hh" +#include "nix/store/tests/derived-path.hh" +#include "nix/store/tests/libstore.hh" namespace nix { @@ -79,12 +79,19 @@ TEST_F(DerivedPathTest, built_built_xp) { #ifndef COVERAGE +/* TODO: Disabled due to the following error: + + path '00000000000000000000000000000000-0^0' is not a valid store path: + name '0^0' contains illegal character '^' +*/ RC_GTEST_FIXTURE_PROP( DerivedPathTest, - prop_legacy_round_rip, + DISABLED_prop_legacy_round_rip, (const DerivedPath & o)) { - RC_ASSERT(o == DerivedPath::parseLegacy(*store, o.to_string_legacy(*store))); + ExperimentalFeatureSettings xpSettings; + xpSettings.set("experimental-features", "dynamic-derivations"); + RC_ASSERT(o == DerivedPath::parseLegacy(*store, o.to_string_legacy(*store), xpSettings)); } RC_GTEST_FIXTURE_PROP( @@ -92,7 +99,9 @@ RC_GTEST_FIXTURE_PROP( prop_round_rip, (const DerivedPath & o)) { - RC_ASSERT(o == DerivedPath::parse(*store, o.to_string(*store))); + ExperimentalFeatureSettings xpSettings; + xpSettings.set("experimental-features", "dynamic-derivations"); + RC_ASSERT(o == DerivedPath::parse(*store, o.to_string(*store), xpSettings)); } #endif diff --git a/src/libstore-tests/downstream-placeholder.cc b/src/libstore-tests/downstream-placeholder.cc index fd29530ac..604c80017 100644 --- a/src/libstore-tests/downstream-placeholder.cc +++ b/src/libstore-tests/downstream-placeholder.cc @@ -1,6 +1,6 @@ #include -#include "downstream-placeholder.hh" +#include "nix/store/downstream-placeholder.hh" namespace nix { diff --git a/src/libstore-tests/http-binary-cache-store.cc b/src/libstore-tests/http-binary-cache-store.cc index 1e415f625..f4a3408b5 100644 --- a/src/libstore-tests/http-binary-cache-store.cc +++ b/src/libstore-tests/http-binary-cache-store.cc @@ -1,6 +1,6 @@ #include -#include "http-binary-cache-store.hh" +#include "nix/store/http-binary-cache-store.hh" namespace nix { diff --git a/src/libstore-tests/legacy-ssh-store.cc b/src/libstore-tests/legacy-ssh-store.cc index eb31a2408..158da2831 100644 --- a/src/libstore-tests/legacy-ssh-store.cc +++ b/src/libstore-tests/legacy-ssh-store.cc @@ -1,6 +1,6 @@ #include -#include "legacy-ssh-store.hh" +#include "nix/store/legacy-ssh-store.hh" namespace nix { diff --git a/src/libstore-tests/local-binary-cache-store.cc b/src/libstore-tests/local-binary-cache-store.cc index 2e840228d..01f514e89 100644 --- a/src/libstore-tests/local-binary-cache-store.cc +++ b/src/libstore-tests/local-binary-cache-store.cc @@ -1,6 +1,6 @@ #include -#include "local-binary-cache-store.hh" +#include "nix/store/local-binary-cache-store.hh" namespace nix { diff --git a/src/libstore-tests/local-overlay-store.cc b/src/libstore-tests/local-overlay-store.cc index b34ca9237..fe064c3a5 100644 --- a/src/libstore-tests/local-overlay-store.cc +++ b/src/libstore-tests/local-overlay-store.cc @@ -3,7 +3,7 @@ #if 0 # include -# include "local-overlay-store.hh" +# include "nix/store/local-overlay-store.hh" namespace nix { diff --git a/src/libstore-tests/local-store.cc b/src/libstore-tests/local-store.cc index abc3ea796..ece277609 100644 --- a/src/libstore-tests/local-store.cc +++ b/src/libstore-tests/local-store.cc @@ -3,13 +3,13 @@ #if 0 # include -# include "local-store.hh" +# include "nix/store/local-store.hh" // Needed for template specialisations. This is not good! When we // overhaul how store configs work, this should be fixed. -# include "args.hh" -# include "config-impl.hh" -# include "abstract-setting-to-json.hh" +# include "nix/util/args.hh" +# include "nix/util/config-impl.hh" +# include "nix/util/abstract-setting-to-json.hh" namespace nix { diff --git a/src/libstore-tests/machines.cc b/src/libstore-tests/machines.cc index 2d66e9534..1d574ceeb 100644 --- a/src/libstore-tests/machines.cc +++ b/src/libstore-tests/machines.cc @@ -1,8 +1,8 @@ -#include "machines.hh" -#include "file-system.hh" -#include "util.hh" +#include "nix/store/machines.hh" +#include "nix/util/file-system.hh" +#include "nix/util/util.hh" -#include "tests/characterization.hh" +#include "nix/util/tests/characterization.hh" #include #include diff --git a/src/libstore-tests/meson.build b/src/libstore-tests/meson.build index 3ba0795e9..8a1ff40f0 100644 --- a/src/libstore-tests/meson.build +++ b/src/libstore-tests/meson.build @@ -37,19 +37,19 @@ deps_private += rapidcheck gtest = dependency('gtest', main : true) deps_private += gtest +configdata = configuration_data() +configdata.set_quoted('PACKAGE_VERSION', meson.project_version()) + +configdata.set_quoted('NIX_STORE_DIR', nix_store.get_variable('storedir')) + +config_priv_h = configure_file( + configuration : configdata, + output : 'store-tests-config.hh', +) + gtest = dependency('gmock') deps_private += gtest -add_project_arguments( - # TODO(Qyriad): Yes this is how the autoconf+Make system did it. - # It would be nice for our headers to be idempotent instead. - '-include', 'config-util.hh', - '-include', 'config-store.hh', - '-include', 'config-util.h', - '-include', 'config-store.h', - language : 'cpp', -) - subdir('nix-meson-build-support/common') sources = files( @@ -86,11 +86,11 @@ include_dirs = [include_directories('.')] this_exe = executable( meson.project_name(), sources, + config_priv_h, dependencies : deps_private_subproject + deps_private + deps_other, include_directories : include_dirs, # TODO: -lrapidcheck, see ../libutil-support/build.meson link_args: linker_export_flags + ['-lrapidcheck'], - cpp_args : [ '-DNIX_STORE_DIR="' + nix_store.get_variable('storedir') + '"' ], # get main from gtest install : true, ) diff --git a/src/libstore-tests/nar-info-disk-cache.cc b/src/libstore-tests/nar-info-disk-cache.cc index b4bdb8329..4c7354c0c 100644 --- a/src/libstore-tests/nar-info-disk-cache.cc +++ b/src/libstore-tests/nar-info-disk-cache.cc @@ -1,8 +1,8 @@ -#include "nar-info-disk-cache.hh" +#include "nix/store/nar-info-disk-cache.hh" #include #include -#include "sqlite.hh" +#include "nix/store/sqlite.hh" #include diff --git a/src/libstore-tests/nar-info.cc b/src/libstore-tests/nar-info.cc index 0d155743d..1979deef8 100644 --- a/src/libstore-tests/nar-info.cc +++ b/src/libstore-tests/nar-info.cc @@ -1,11 +1,11 @@ #include #include -#include "path-info.hh" -#include "nar-info.hh" +#include "nix/store/path-info.hh" +#include "nix/store/nar-info.hh" -#include "tests/characterization.hh" -#include "tests/libstore.hh" +#include "nix/util/tests/characterization.hh" +#include "nix/store/tests/libstore.hh" namespace nix { diff --git a/src/libstore-tests/nix_api_store.cc b/src/libstore-tests/nix_api_store.cc index a8b7b8e5f..4eb95360a 100644 --- a/src/libstore-tests/nix_api_store.cc +++ b/src/libstore-tests/nix_api_store.cc @@ -3,8 +3,10 @@ #include "nix_api_store.h" #include "nix_api_store_internal.h" -#include "tests/nix_api_store.hh" -#include "tests/string_callback.hh" +#include "nix/store/tests/nix_api_store.hh" +#include "nix/util/tests/string_callback.hh" + +#include "store-tests-config.hh" namespace nixC { diff --git a/src/libstore-tests/outputs-spec.cc b/src/libstore-tests/outputs-spec.cc index 63cde681b..a17922c46 100644 --- a/src/libstore-tests/outputs-spec.cc +++ b/src/libstore-tests/outputs-spec.cc @@ -1,4 +1,4 @@ -#include "tests/outputs-spec.hh" +#include "nix/store/tests/outputs-spec.hh" #include #include diff --git a/src/libstore-tests/path-info.cc b/src/libstore-tests/path-info.cc index d6c4c2a7f..9cd98a3d9 100644 --- a/src/libstore-tests/path-info.cc +++ b/src/libstore-tests/path-info.cc @@ -1,10 +1,10 @@ #include #include -#include "path-info.hh" +#include "nix/store/path-info.hh" -#include "tests/characterization.hh" -#include "tests/libstore.hh" +#include "nix/util/tests/characterization.hh" +#include "nix/store/tests/libstore.hh" namespace nix { diff --git a/src/libstore-tests/path.cc b/src/libstore-tests/path.cc index c4c055abf..4da73a0ad 100644 --- a/src/libstore-tests/path.cc +++ b/src/libstore-tests/path.cc @@ -4,12 +4,12 @@ #include #include -#include "path-regex.hh" -#include "store-api.hh" +#include "nix/store/path-regex.hh" +#include "nix/store/store-api.hh" -#include "tests/hash.hh" -#include "tests/libstore.hh" -#include "tests/path.hh" +#include "nix/util/tests/hash.hh" +#include "nix/store/tests/libstore.hh" +#include "nix/store/tests/path.hh" namespace nix { diff --git a/src/libstore-tests/references.cc b/src/libstore-tests/references.cc index d91d1cedd..59993727d 100644 --- a/src/libstore-tests/references.cc +++ b/src/libstore-tests/references.cc @@ -1,4 +1,4 @@ -#include "references.hh" +#include "nix/util/references.hh" #include diff --git a/src/libstore-tests/s3-binary-cache-store.cc b/src/libstore-tests/s3-binary-cache-store.cc index 7aa5f2f2c..251e96172 100644 --- a/src/libstore-tests/s3-binary-cache-store.cc +++ b/src/libstore-tests/s3-binary-cache-store.cc @@ -1,9 +1,9 @@ -#if ENABLE_S3 +#include "nix/store/s3-binary-cache-store.hh" + +#if NIX_WITH_S3_SUPPORT # include -# include "s3-binary-cache-store.hh" - namespace nix { TEST(S3BinaryCacheStore, constructConfig) diff --git a/src/libstore-tests/serve-protocol.cc b/src/libstore-tests/serve-protocol.cc index 3dbbf3879..9297d46ea 100644 --- a/src/libstore-tests/serve-protocol.cc +++ b/src/libstore-tests/serve-protocol.cc @@ -4,13 +4,13 @@ #include #include -#include "serve-protocol.hh" -#include "serve-protocol-impl.hh" -#include "serve-protocol-connection.hh" -#include "build-result.hh" -#include "file-descriptor.hh" -#include "tests/protocol.hh" -#include "tests/characterization.hh" +#include "nix/store/serve-protocol.hh" +#include "nix/store/serve-protocol-impl.hh" +#include "nix/store/serve-protocol-connection.hh" +#include "nix/store/build-result.hh" +#include "nix/util/file-descriptor.hh" +#include "nix/store/tests/protocol.hh" +#include "nix/util/tests/characterization.hh" namespace nix { diff --git a/src/libstore-tests/ssh-store.cc b/src/libstore-tests/ssh-store.cc index b853a5f1f..ccb87b767 100644 --- a/src/libstore-tests/ssh-store.cc +++ b/src/libstore-tests/ssh-store.cc @@ -3,7 +3,7 @@ #if 0 # include -# include "ssh-store.hh" +# include "nix/store/ssh-store.hh" namespace nix { diff --git a/src/libstore-tests/store-reference.cc b/src/libstore-tests/store-reference.cc index d4c42f0fd..dd1b83090 100644 --- a/src/libstore-tests/store-reference.cc +++ b/src/libstore-tests/store-reference.cc @@ -1,11 +1,11 @@ #include #include -#include "file-system.hh" -#include "store-reference.hh" +#include "nix/util/file-system.hh" +#include "nix/store/store-reference.hh" -#include "tests/characterization.hh" -#include "tests/libstore.hh" +#include "nix/util/tests/characterization.hh" +#include "nix/store/tests/libstore.hh" namespace nix { diff --git a/src/libstore-tests/uds-remote-store.cc b/src/libstore-tests/uds-remote-store.cc index 5ccb20871..c6a926668 100644 --- a/src/libstore-tests/uds-remote-store.cc +++ b/src/libstore-tests/uds-remote-store.cc @@ -3,7 +3,7 @@ #if 0 # include -# include "uds-remote-store.hh" +# include "nix/store/uds-remote-store.hh" namespace nix { diff --git a/src/libstore-tests/worker-protocol.cc b/src/libstore-tests/worker-protocol.cc index 99b042d5b..091cf8a0e 100644 --- a/src/libstore-tests/worker-protocol.cc +++ b/src/libstore-tests/worker-protocol.cc @@ -4,13 +4,13 @@ #include #include -#include "worker-protocol.hh" -#include "worker-protocol-connection.hh" -#include "worker-protocol-impl.hh" -#include "derived-path.hh" -#include "build-result.hh" -#include "tests/protocol.hh" -#include "tests/characterization.hh" +#include "nix/store/worker-protocol.hh" +#include "nix/store/worker-protocol-connection.hh" +#include "nix/store/worker-protocol-impl.hh" +#include "nix/store/derived-path.hh" +#include "nix/store/build-result.hh" +#include "nix/store/tests/protocol.hh" +#include "nix/util/tests/characterization.hh" namespace nix { diff --git a/src/libstore/binary-cache-store.cc b/src/libstore/binary-cache-store.cc index 896779f85..60bd68026 100644 --- a/src/libstore/binary-cache-store.cc +++ b/src/libstore/binary-cache-store.cc @@ -1,18 +1,18 @@ -#include "archive.hh" -#include "binary-cache-store.hh" -#include "compression.hh" -#include "derivations.hh" -#include "source-accessor.hh" -#include "globals.hh" -#include "nar-info.hh" -#include "sync.hh" -#include "remote-fs-accessor.hh" -#include "nar-info-disk-cache.hh" -#include "nar-accessor.hh" -#include "thread-pool.hh" -#include "callback.hh" -#include "signals.hh" -#include "archive.hh" +#include "nix/util/archive.hh" +#include "nix/store/binary-cache-store.hh" +#include "nix/util/compression.hh" +#include "nix/store/derivations.hh" +#include "nix/util/source-accessor.hh" +#include "nix/store/globals.hh" +#include "nix/store/nar-info.hh" +#include "nix/util/sync.hh" +#include "nix/store/remote-fs-accessor.hh" +#include "nix/store/nar-info-disk-cache.hh" +#include "nix/store/nar-accessor.hh" +#include "nix/util/thread-pool.hh" +#include "nix/util/callback.hh" +#include "nix/util/signals.hh" +#include "nix/util/archive.hh" #include #include diff --git a/src/libstore/build-result.cc b/src/libstore/build-result.cc index 1f27f68f4..264424613 100644 --- a/src/libstore/build-result.cc +++ b/src/libstore/build-result.cc @@ -1,4 +1,4 @@ -#include "build-result.hh" +#include "nix/store/build-result.hh" #include diff --git a/src/libstore/build/derivation-goal.cc b/src/libstore/build/derivation-goal.cc index b54176418..d7f8846bd 100644 --- a/src/libstore/build/derivation-goal.cc +++ b/src/libstore/build/derivation-goal.cc @@ -1,22 +1,22 @@ -#include "derivation-goal.hh" +#include "nix/store/build/derivation-goal.hh" #ifndef _WIN32 // TODO enable build hook on Windows -# include "hook-instance.hh" +# include "nix/store/build/hook-instance.hh" #endif -#include "processes.hh" -#include "config-global.hh" -#include "worker.hh" -#include "builtins.hh" -#include "builtins/buildenv.hh" -#include "references.hh" -#include "finally.hh" -#include "util.hh" -#include "archive.hh" -#include "compression.hh" -#include "common-protocol.hh" -#include "common-protocol-impl.hh" -#include "topo-sort.hh" -#include "callback.hh" -#include "local-store.hh" // TODO remove, along with remaining downcasts +#include "nix/util/processes.hh" +#include "nix/util/config-global.hh" +#include "nix/store/build/worker.hh" +#include "nix/store/builtins.hh" +#include "nix/store/builtins/buildenv.hh" +#include "nix/util/references.hh" +#include "nix/util/finally.hh" +#include "nix/util/util.hh" +#include "nix/util/archive.hh" +#include "nix/util/compression.hh" +#include "nix/store/common-protocol.hh" +#include "nix/store/common-protocol-impl.hh" +#include "nix/util/topo-sort.hh" +#include "nix/util/callback.hh" +#include "nix/store/local-store.hh" // TODO remove, along with remaining downcasts #include #include @@ -32,7 +32,7 @@ #include -#include "strings.hh" +#include "nix/util/strings.hh" namespace nix { diff --git a/src/libstore/build/drv-output-substitution-goal.cc b/src/libstore/build/drv-output-substitution-goal.cc index f069c0d94..bc2030fa5 100644 --- a/src/libstore/build/drv-output-substitution-goal.cc +++ b/src/libstore/build/drv-output-substitution-goal.cc @@ -1,8 +1,8 @@ -#include "drv-output-substitution-goal.hh" -#include "finally.hh" -#include "worker.hh" -#include "substitution-goal.hh" -#include "callback.hh" +#include "nix/store/build/drv-output-substitution-goal.hh" +#include "nix/util/finally.hh" +#include "nix/store/build/worker.hh" +#include "nix/store/build/substitution-goal.hh" +#include "nix/util/callback.hh" namespace nix { diff --git a/src/libstore/build/entry-points.cc b/src/libstore/build/entry-points.cc index 3bf22320e..c934b0704 100644 --- a/src/libstore/build/entry-points.cc +++ b/src/libstore/build/entry-points.cc @@ -1,10 +1,10 @@ -#include "worker.hh" -#include "substitution-goal.hh" +#include "nix/store/build/worker.hh" +#include "nix/store/build/substitution-goal.hh" #ifndef _WIN32 // TODO Enable building on Windows -# include "derivation-goal.hh" +# include "nix/store/build/derivation-goal.hh" #endif -#include "local-store.hh" -#include "strings.hh" +#include "nix/store/local-store.hh" +#include "nix/util/strings.hh" namespace nix { diff --git a/src/libstore/build/goal.cc b/src/libstore/build/goal.cc index 9a16da145..aaa426793 100644 --- a/src/libstore/build/goal.cc +++ b/src/libstore/build/goal.cc @@ -1,5 +1,5 @@ -#include "goal.hh" -#include "worker.hh" +#include "nix/store/build/goal.hh" +#include "nix/store/build/worker.hh" namespace nix { diff --git a/src/libstore/build/substitution-goal.cc b/src/libstore/build/substitution-goal.cc index 41d8a0c30..fc1261935 100644 --- a/src/libstore/build/substitution-goal.cc +++ b/src/libstore/build/substitution-goal.cc @@ -1,8 +1,8 @@ -#include "worker.hh" -#include "substitution-goal.hh" -#include "nar-info.hh" -#include "finally.hh" -#include "signals.hh" +#include "nix/store/build/worker.hh" +#include "nix/store/build/substitution-goal.hh" +#include "nix/store/nar-info.hh" +#include "nix/util/finally.hh" +#include "nix/util/signals.hh" #include diff --git a/src/libstore/build/worker.cc b/src/libstore/build/worker.cc index dbe86f43f..87710e9ee 100644 --- a/src/libstore/build/worker.cc +++ b/src/libstore/build/worker.cc @@ -1,14 +1,14 @@ -#include "local-store.hh" -#include "machines.hh" -#include "worker.hh" -#include "substitution-goal.hh" -#include "drv-output-substitution-goal.hh" -#include "derivation-goal.hh" +#include "nix/store/local-store.hh" +#include "nix/store/machines.hh" +#include "nix/store/build/worker.hh" +#include "nix/store/build/substitution-goal.hh" +#include "nix/store/build/drv-output-substitution-goal.hh" +#include "nix/store/build/derivation-goal.hh" #ifndef _WIN32 // TODO Enable building on Windows -# include "local-derivation-goal.hh" -# include "hook-instance.hh" +# include "nix/store/build/local-derivation-goal.hh" +# include "nix/store/build/hook-instance.hh" #endif -#include "signals.hh" +#include "nix/util/signals.hh" namespace nix { diff --git a/src/libstore/builtins/buildenv.cc b/src/libstore/builtins/buildenv.cc index 0f7bcd99b..c3b80bb0b 100644 --- a/src/libstore/builtins/buildenv.cc +++ b/src/libstore/builtins/buildenv.cc @@ -1,6 +1,6 @@ -#include "buildenv.hh" -#include "derivations.hh" -#include "signals.hh" +#include "nix/store/builtins/buildenv.hh" +#include "nix/store/derivations.hh" +#include "nix/util/signals.hh" #include #include diff --git a/src/libstore/builtins/fetchurl.cc b/src/libstore/builtins/fetchurl.cc index 90e58dfdb..82f268d80 100644 --- a/src/libstore/builtins/fetchurl.cc +++ b/src/libstore/builtins/fetchurl.cc @@ -1,8 +1,8 @@ -#include "builtins.hh" -#include "filetransfer.hh" -#include "store-api.hh" -#include "archive.hh" -#include "compression.hh" +#include "nix/store/builtins.hh" +#include "nix/store/filetransfer.hh" +#include "nix/store/store-api.hh" +#include "nix/util/archive.hh" +#include "nix/util/compression.hh" namespace nix { diff --git a/src/libstore/builtins/unpack-channel.cc b/src/libstore/builtins/unpack-channel.cc index a6369ee1c..f6be21e35 100644 --- a/src/libstore/builtins/unpack-channel.cc +++ b/src/libstore/builtins/unpack-channel.cc @@ -1,5 +1,5 @@ -#include "builtins.hh" -#include "tarfile.hh" +#include "nix/store/builtins.hh" +#include "nix/util/tarfile.hh" namespace nix { @@ -23,11 +23,7 @@ void builtinUnpackChannel( throw Error("channelName is not allowed to contain filesystem separators, got %1%", channelName); } - try { - fs::create_directories(out); - } catch (fs::filesystem_error &) { - throw SysError("creating directory '%1%'", out.string()); - } + createDirs(out); unpackTarfile(src, out); diff --git a/src/libstore/common-protocol.cc b/src/libstore/common-protocol.cc index fc2b5ac6f..311f4888c 100644 --- a/src/libstore/common-protocol.cc +++ b/src/libstore/common-protocol.cc @@ -1,11 +1,11 @@ -#include "serialise.hh" -#include "path-with-outputs.hh" -#include "store-api.hh" -#include "build-result.hh" -#include "common-protocol.hh" -#include "common-protocol-impl.hh" -#include "archive.hh" -#include "derivations.hh" +#include "nix/util/serialise.hh" +#include "nix/store/path-with-outputs.hh" +#include "nix/store/store-api.hh" +#include "nix/store/build-result.hh" +#include "nix/store/common-protocol.hh" +#include "nix/store/common-protocol-impl.hh" +#include "nix/util/archive.hh" +#include "nix/store/derivations.hh" #include diff --git a/src/libstore/common-ssh-store-config.cc b/src/libstore/common-ssh-store-config.cc index 05332b9bb..7cfbc5f98 100644 --- a/src/libstore/common-ssh-store-config.cc +++ b/src/libstore/common-ssh-store-config.cc @@ -1,7 +1,7 @@ #include -#include "common-ssh-store-config.hh" -#include "ssh.hh" +#include "nix/store/common-ssh-store-config.hh" +#include "nix/store/ssh.hh" namespace nix { diff --git a/src/libstore/content-address.cc b/src/libstore/content-address.cc index e1cdfece6..5d27c4136 100644 --- a/src/libstore/content-address.cc +++ b/src/libstore/content-address.cc @@ -1,6 +1,6 @@ -#include "args.hh" -#include "content-address.hh" -#include "split.hh" +#include "nix/util/args.hh" +#include "nix/store/content-address.hh" +#include "nix/util/split.hh" namespace nix { diff --git a/src/libstore/daemon.cc b/src/libstore/daemon.cc index 32c8f4d2d..dfc068bc7 100644 --- a/src/libstore/daemon.cc +++ b/src/libstore/daemon.cc @@ -1,24 +1,24 @@ -#include "daemon.hh" -#include "signals.hh" -#include "worker-protocol.hh" -#include "worker-protocol-connection.hh" -#include "worker-protocol-impl.hh" -#include "build-result.hh" -#include "store-api.hh" -#include "store-cast.hh" -#include "gc-store.hh" -#include "log-store.hh" -#include "indirect-root-store.hh" -#include "path-with-outputs.hh" -#include "finally.hh" -#include "archive.hh" -#include "derivations.hh" -#include "args.hh" -#include "git.hh" -#include "logging.hh" +#include "nix/store/daemon.hh" +#include "nix/util/signals.hh" +#include "nix/store/worker-protocol.hh" +#include "nix/store/worker-protocol-connection.hh" +#include "nix/store/worker-protocol-impl.hh" +#include "nix/store/build-result.hh" +#include "nix/store/store-api.hh" +#include "nix/store/store-cast.hh" +#include "nix/store/gc-store.hh" +#include "nix/store/log-store.hh" +#include "nix/store/indirect-root-store.hh" +#include "nix/store/path-with-outputs.hh" +#include "nix/util/finally.hh" +#include "nix/util/archive.hh" +#include "nix/store/derivations.hh" +#include "nix/util/args.hh" +#include "nix/util/git.hh" +#include "nix/util/logging.hh" #ifndef _WIN32 // TODO need graceful async exit support on Windows? -# include "monitor-fd.hh" +# include "nix/util/monitor-fd.hh" #endif #include @@ -1026,6 +1026,7 @@ void processConnection( { #ifndef _WIN32 // TODO need graceful async exit support on Windows? auto monitor = !recursive ? std::make_unique(from.fd) : nullptr; + (void) monitor; // suppress warning #endif /* Exchange the greeting. */ diff --git a/src/libstore/derivation-options.cc b/src/libstore/derivation-options.cc index 1fc1718f7..962222f6d 100644 --- a/src/libstore/derivation-options.cc +++ b/src/libstore/derivation-options.cc @@ -1,8 +1,8 @@ -#include "derivation-options.hh" -#include "json-utils.hh" -#include "parsed-derivations.hh" -#include "types.hh" -#include "util.hh" +#include "nix/store/derivation-options.hh" +#include "nix/util/json-utils.hh" +#include "nix/store/parsed-derivations.hh" +#include "nix/util/types.hh" +#include "nix/util/util.hh" #include #include #include diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc index b54838a0a..360d19afe 100644 --- a/src/libstore/derivations.cc +++ b/src/libstore/derivations.cc @@ -1,14 +1,14 @@ -#include "derivations.hh" -#include "downstream-placeholder.hh" -#include "store-api.hh" -#include "globals.hh" -#include "types.hh" -#include "util.hh" -#include "split.hh" -#include "common-protocol.hh" -#include "common-protocol-impl.hh" -#include "strings-inline.hh" -#include "json-utils.hh" +#include "nix/store/derivations.hh" +#include "nix/store/downstream-placeholder.hh" +#include "nix/store/store-api.hh" +#include "nix/store/globals.hh" +#include "nix/util/types.hh" +#include "nix/util/util.hh" +#include "nix/util/split.hh" +#include "nix/store/common-protocol.hh" +#include "nix/store/common-protocol-impl.hh" +#include "nix/util/strings-inline.hh" +#include "nix/util/json-utils.hh" #include #include diff --git a/src/libstore/derived-path-map.cc b/src/libstore/derived-path-map.cc index c97d52773..d4234d92c 100644 --- a/src/libstore/derived-path-map.cc +++ b/src/libstore/derived-path-map.cc @@ -1,5 +1,5 @@ -#include "derived-path-map.hh" -#include "util.hh" +#include "nix/store/derived-path-map.hh" +#include "nix/util/util.hh" namespace nix { diff --git a/src/libstore/derived-path.cc b/src/libstore/derived-path.cc index 1eef881de..950ac1c1a 100644 --- a/src/libstore/derived-path.cc +++ b/src/libstore/derived-path.cc @@ -1,7 +1,7 @@ -#include "derived-path.hh" -#include "derivations.hh" -#include "store-api.hh" -#include "comparator.hh" +#include "nix/store/derived-path.hh" +#include "nix/store/derivations.hh" +#include "nix/store/store-api.hh" +#include "nix/util/comparator.hh" #include diff --git a/src/libstore/downstream-placeholder.cc b/src/libstore/downstream-placeholder.cc index 91d47f946..24ce2ad99 100644 --- a/src/libstore/downstream-placeholder.cc +++ b/src/libstore/downstream-placeholder.cc @@ -1,5 +1,5 @@ -#include "downstream-placeholder.hh" -#include "derivations.hh" +#include "nix/store/downstream-placeholder.hh" +#include "nix/store/derivations.hh" namespace nix { diff --git a/src/libstore/dummy-store.cc b/src/libstore/dummy-store.cc index c1e871e93..7252e1d33 100644 --- a/src/libstore/dummy-store.cc +++ b/src/libstore/dummy-store.cc @@ -1,5 +1,5 @@ -#include "store-api.hh" -#include "callback.hh" +#include "nix/store/store-api.hh" +#include "nix/util/callback.hh" namespace nix { diff --git a/src/libstore/export-import.cc b/src/libstore/export-import.cc index 1c62cdfad..5bbdd1e5c 100644 --- a/src/libstore/export-import.cc +++ b/src/libstore/export-import.cc @@ -1,8 +1,8 @@ -#include "serialise.hh" -#include "store-api.hh" -#include "archive.hh" -#include "common-protocol.hh" -#include "common-protocol-impl.hh" +#include "nix/util/serialise.hh" +#include "nix/store/store-api.hh" +#include "nix/util/archive.hh" +#include "nix/store/common-protocol.hh" +#include "nix/store/common-protocol-impl.hh" #include diff --git a/src/libstore/filetransfer.cc b/src/libstore/filetransfer.cc index 1e7ee8c37..055c0739d 100644 --- a/src/libstore/filetransfer.cc +++ b/src/libstore/filetransfer.cc @@ -1,19 +1,20 @@ -#include "filetransfer.hh" -#include "globals.hh" -#include "config-global.hh" -#include "store-api.hh" -#include "s3.hh" -#include "compression.hh" -#include "finally.hh" -#include "callback.hh" -#include "signals.hh" +#include "nix/store/filetransfer.hh" +#include "nix/store/globals.hh" +#include "nix/util/config-global.hh" +#include "nix/store/store-api.hh" +#include "nix/store/s3.hh" +#include "nix/util/compression.hh" +#include "nix/util/finally.hh" +#include "nix/util/callback.hh" +#include "nix/util/signals.hh" -#if ENABLE_S3 +#include "store-config-private.hh" +#if NIX_WITH_S3_SUPPORT #include #endif -#if __linux__ -# include "namespaces.hh" +#ifdef __linux__ +# include "nix/util/namespaces.hh" #endif #include @@ -623,7 +624,7 @@ struct curlFileTransfer : public FileTransfer }); #endif - #if __linux__ + #ifdef __linux__ try { tryUnshareFilesystem(); } catch (nix::Error & e) { @@ -757,7 +758,7 @@ struct curlFileTransfer : public FileTransfer #endif } -#if ENABLE_S3 +#if NIX_WITH_S3_SUPPORT std::tuple parseS3Uri(std::string uri) { auto [path, params] = splitUriAndParams(uri); @@ -780,7 +781,7 @@ struct curlFileTransfer : public FileTransfer if (hasPrefix(request.uri, "s3://")) { // FIXME: do this on a worker thread try { -#if ENABLE_S3 +#if NIX_WITH_S3_SUPPORT auto [bucketName, key, params] = parseS3Uri(request.uri); std::string profile = getOr(params, "profile", ""); diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc index ac354f3fa..dabfa4a5f 100644 --- a/src/libstore/gc.cc +++ b/src/libstore/gc.cc @@ -1,14 +1,16 @@ -#include "derivations.hh" -#include "globals.hh" -#include "local-store.hh" -#include "finally.hh" -#include "unix-domain-socket.hh" -#include "signals.hh" -#include "posix-fs-canonicalise.hh" +#include "nix/store/derivations.hh" +#include "nix/store/globals.hh" +#include "nix/store/local-store.hh" +#include "nix/util/finally.hh" +#include "nix/util/unix-domain-socket.hh" +#include "nix/util/signals.hh" +#include "nix/store/posix-fs-canonicalise.hh" + +#include "store-config-private.hh" #if !defined(__linux__) // For shelling out to lsof -# include "processes.hh" +# include "nix/util/processes.hh" #endif #include @@ -333,7 +335,7 @@ static std::string quoteRegexChars(const std::string & raw) return std::regex_replace(raw, specialRegex, R"(\$&)"); } -#if __linux__ +#ifdef __linux__ static void readFileRoots(const std::filesystem::path & path, UncheckedRoots & roots) { try { @@ -425,7 +427,7 @@ void LocalStore::findRuntimeRoots(Roots & roots, bool censor) } #endif -#if __linux__ +#ifdef __linux__ readFileRoots("/proc/sys/kernel/modprobe", unchecked); readFileRoots("/proc/sys/kernel/fbsplash", unchecked); readFileRoots("/proc/sys/kernel/poweroff_cmd", unchecked); diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc index f4abbe43f..76ebd16ba 100644 --- a/src/libstore/globals.cc +++ b/src/libstore/globals.cc @@ -1,11 +1,11 @@ -#include "globals.hh" -#include "config-global.hh" -#include "current-process.hh" -#include "archive.hh" -#include "args.hh" -#include "abstract-setting-to-json.hh" -#include "compute-levels.hh" -#include "signals.hh" +#include "nix/store/globals.hh" +#include "nix/util/config-global.hh" +#include "nix/util/current-process.hh" +#include "nix/util/archive.hh" +#include "nix/util/args.hh" +#include "nix/util/abstract-setting-to-json.hh" +#include "nix/util/compute-levels.hh" +#include "nix/util/signals.hh" #include #include @@ -25,17 +25,17 @@ # include #endif -#if __APPLE__ -# include "processes.hh" +#ifdef __APPLE__ +# include "nix/util/processes.hh" #endif -#include "config-impl.hh" +#include "nix/util/config-impl.hh" #ifdef __APPLE__ #include #endif -#include "strings.hh" +#include "store-config-private.hh" namespace nix { @@ -90,7 +90,7 @@ Settings::Settings() #endif /* chroot-like behavior from Apple's sandbox */ -#if __APPLE__ +#ifdef __APPLE__ sandboxPaths = tokenizeString("/System/Library/Frameworks /System/Library/PrivateFrameworks /bin/sh /bin/bash /private/tmp /private/var/tmp /usr/lib"); allowedImpureHostPrefixes = tokenizeString("/System/Library /usr/lib /dev /bin/sh"); #endif @@ -151,7 +151,7 @@ unsigned int Settings::getDefaultCores() return concurrency; } -#if __APPLE__ +#ifdef __APPLE__ static bool hasVirt() { int hasVMM; @@ -181,16 +181,16 @@ StringSet Settings::getDefaultSystemFeatures() actually require anything special on the machines. */ StringSet features{"nixos-test", "benchmark", "big-parallel"}; - #if __linux__ + #ifdef __linux__ features.insert("uid-range"); #endif - #if __linux__ + #ifdef __linux__ if (access("/dev/kvm", R_OK | W_OK) == 0) features.insert("kvm"); #endif - #if __APPLE__ + #ifdef __APPLE__ if (hasVirt()) features.insert("apple-virt"); #endif @@ -202,19 +202,19 @@ StringSet Settings::getDefaultExtraPlatforms() { StringSet extraPlatforms; - if (std::string{SYSTEM} == "x86_64-linux" && !isWSL1()) + if (std::string{NIX_LOCAL_SYSTEM} == "x86_64-linux" && !isWSL1()) extraPlatforms.insert("i686-linux"); -#if __linux__ +#ifdef __linux__ StringSet levels = computeLevels(); for (auto iter = levels.begin(); iter != levels.end(); ++iter) extraPlatforms.insert(*iter + "-linux"); -#elif __APPLE__ +#elif defined(__APPLE__) // Rosetta 2 emulation layer can run x86_64 binaries on aarch64 // machines. Note that we can’t force processes from executing // x86_64 in aarch64 environments or vice versa since they can // always exec with their own binary preferences. - if (std::string{SYSTEM} == "aarch64-darwin" && + if (std::string{NIX_LOCAL_SYSTEM} == "aarch64-darwin" && runProgram(RunOptions {.program = "arch", .args = {"-arch", "x86_64", "/usr/bin/true"}, .mergeStderrToStdout = true}).first == 0) extraPlatforms.insert("x86_64-darwin"); #endif @@ -224,7 +224,7 @@ StringSet Settings::getDefaultExtraPlatforms() bool Settings::isWSL1() { -#if __linux__ +#ifdef __linux__ struct utsname utsbuf; uname(&utsbuf); // WSL1 uses -Microsoft suffix @@ -376,7 +376,7 @@ void initLibStore(bool loadConfig) { [1] https://github.com/apple-oss-distributions/objc4/blob/01edf1705fbc3ff78a423cd21e03dfc21eb4d780/runtime/objc-initialize.mm#L614-L636 */ curl_global_init(CURL_GLOBAL_ALL); -#if __APPLE__ +#ifdef __APPLE__ /* On macOS, don't use the per-session TMPDIR (as set e.g. by sshd). This breaks build users because they don't have access to the TMPDIR, in particular in ‘nix-store --serve’. */ diff --git a/src/libstore/http-binary-cache-store.cc b/src/libstore/http-binary-cache-store.cc index f32616f94..4c13d5c73 100644 --- a/src/libstore/http-binary-cache-store.cc +++ b/src/libstore/http-binary-cache-store.cc @@ -1,8 +1,8 @@ -#include "http-binary-cache-store.hh" -#include "filetransfer.hh" -#include "globals.hh" -#include "nar-info-disk-cache.hh" -#include "callback.hh" +#include "nix/store/http-binary-cache-store.hh" +#include "nix/store/filetransfer.hh" +#include "nix/store/globals.hh" +#include "nix/store/nar-info-disk-cache.hh" +#include "nix/util/callback.hh" namespace nix { diff --git a/src/libstore/binary-cache-store.hh b/src/libstore/include/nix/store/binary-cache-store.hh similarity index 97% rename from src/libstore/binary-cache-store.hh rename to src/libstore/include/nix/store/binary-cache-store.hh index 6bd7fd14a..da4906d3f 100644 --- a/src/libstore/binary-cache-store.hh +++ b/src/libstore/include/nix/store/binary-cache-store.hh @@ -1,11 +1,11 @@ #pragma once ///@file -#include "signature/local-keys.hh" -#include "store-api.hh" -#include "log-store.hh" +#include "nix/util/signature/local-keys.hh" +#include "nix/store/store-api.hh" +#include "nix/store/log-store.hh" -#include "pool.hh" +#include "nix/util/pool.hh" #include diff --git a/src/libstore/build-result.hh b/src/libstore/include/nix/store/build-result.hh similarity index 98% rename from src/libstore/build-result.hh rename to src/libstore/include/nix/store/build-result.hh index 44862980d..40b3cdcf1 100644 --- a/src/libstore/build-result.hh +++ b/src/libstore/include/nix/store/build-result.hh @@ -1,8 +1,8 @@ #pragma once ///@file -#include "realisation.hh" -#include "derived-path.hh" +#include "nix/store/realisation.hh" +#include "nix/store/derived-path.hh" #include #include diff --git a/src/libstore/build/derivation-goal.hh b/src/libstore/include/nix/store/build/derivation-goal.hh similarity index 97% rename from src/libstore/build/derivation-goal.hh rename to src/libstore/include/nix/store/build/derivation-goal.hh index 4622cb2b1..8a1c6f33b 100644 --- a/src/libstore/build/derivation-goal.hh +++ b/src/libstore/include/nix/store/build/derivation-goal.hh @@ -1,15 +1,15 @@ #pragma once ///@file -#include "parsed-derivations.hh" -#include "derivation-options.hh" +#include "nix/store/parsed-derivations.hh" +#include "nix/store/derivation-options.hh" #ifndef _WIN32 -# include "user-lock.hh" +# include "nix/store/user-lock.hh" #endif -#include "outputs-spec.hh" -#include "store-api.hh" -#include "pathlocks.hh" -#include "goal.hh" +#include "nix/store/outputs-spec.hh" +#include "nix/store/store-api.hh" +#include "nix/store/pathlocks.hh" +#include "nix/store/build/goal.hh" namespace nix { diff --git a/src/libstore/build/drv-output-substitution-goal.hh b/src/libstore/include/nix/store/build/drv-output-substitution-goal.hh similarity index 88% rename from src/libstore/build/drv-output-substitution-goal.hh rename to src/libstore/include/nix/store/build/drv-output-substitution-goal.hh index 8c60d0198..81d66fe1e 100644 --- a/src/libstore/build/drv-output-substitution-goal.hh +++ b/src/libstore/include/nix/store/build/drv-output-substitution-goal.hh @@ -4,10 +4,10 @@ #include #include -#include "store-api.hh" -#include "goal.hh" -#include "realisation.hh" -#include "muxable-pipe.hh" +#include "nix/store/store-api.hh" +#include "nix/store/build/goal.hh" +#include "nix/store/realisation.hh" +#include "nix/util/muxable-pipe.hh" namespace nix { diff --git a/src/libstore/build/goal.hh b/src/libstore/include/nix/store/build/goal.hh similarity index 99% rename from src/libstore/build/goal.hh rename to src/libstore/include/nix/store/build/goal.hh index 1dd7ed525..7c3873012 100644 --- a/src/libstore/build/goal.hh +++ b/src/libstore/include/nix/store/build/goal.hh @@ -1,8 +1,8 @@ #pragma once ///@file -#include "store-api.hh" -#include "build-result.hh" +#include "nix/store/store-api.hh" +#include "nix/store/build-result.hh" #include diff --git a/src/libstore/build/substitution-goal.hh b/src/libstore/include/nix/store/build/substitution-goal.hh similarity index 93% rename from src/libstore/build/substitution-goal.hh rename to src/libstore/include/nix/store/build/substitution-goal.hh index f2cf797e5..7b68b0821 100644 --- a/src/libstore/build/substitution-goal.hh +++ b/src/libstore/include/nix/store/build/substitution-goal.hh @@ -1,10 +1,10 @@ #pragma once ///@file -#include "worker.hh" -#include "store-api.hh" -#include "goal.hh" -#include "muxable-pipe.hh" +#include "nix/store/build/worker.hh" +#include "nix/store/store-api.hh" +#include "nix/store/build/goal.hh" +#include "nix/util/muxable-pipe.hh" #include #include #include diff --git a/src/libstore/build/worker.hh b/src/libstore/include/nix/store/build/worker.hh similarity index 98% rename from src/libstore/build/worker.hh rename to src/libstore/include/nix/store/build/worker.hh index f5e617208..7e03a0c2f 100644 --- a/src/libstore/build/worker.hh +++ b/src/libstore/include/nix/store/build/worker.hh @@ -1,11 +1,11 @@ #pragma once ///@file -#include "types.hh" -#include "store-api.hh" -#include "goal.hh" -#include "realisation.hh" -#include "muxable-pipe.hh" +#include "nix/util/types.hh" +#include "nix/store/store-api.hh" +#include "nix/store/build/goal.hh" +#include "nix/store/realisation.hh" +#include "nix/util/muxable-pipe.hh" #include #include diff --git a/src/libstore/builtins.hh b/src/libstore/include/nix/store/builtins.hh similarity index 90% rename from src/libstore/builtins.hh rename to src/libstore/include/nix/store/builtins.hh index 091946e01..004e9ef64 100644 --- a/src/libstore/builtins.hh +++ b/src/libstore/include/nix/store/builtins.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "derivations.hh" +#include "nix/store/derivations.hh" namespace nix { diff --git a/src/libstore/builtins/buildenv.hh b/src/libstore/include/nix/store/builtins/buildenv.hh similarity index 96% rename from src/libstore/builtins/buildenv.hh rename to src/libstore/include/nix/store/builtins/buildenv.hh index 8e112e176..a0a262037 100644 --- a/src/libstore/builtins/buildenv.hh +++ b/src/libstore/include/nix/store/builtins/buildenv.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "store-api.hh" +#include "nix/store/store-api.hh" namespace nix { diff --git a/src/libstore/common-protocol-impl.hh b/src/libstore/include/nix/store/common-protocol-impl.hh similarity index 92% rename from src/libstore/common-protocol-impl.hh rename to src/libstore/include/nix/store/common-protocol-impl.hh index 360882c02..171b4c6a5 100644 --- a/src/libstore/common-protocol-impl.hh +++ b/src/libstore/include/nix/store/common-protocol-impl.hh @@ -8,8 +8,8 @@ * contributing guide. */ -#include "common-protocol.hh" -#include "length-prefixed-protocol-helper.hh" +#include "nix/store/common-protocol.hh" +#include "nix/store/length-prefixed-protocol-helper.hh" namespace nix { diff --git a/src/libstore/common-protocol.hh b/src/libstore/include/nix/store/common-protocol.hh similarity index 98% rename from src/libstore/common-protocol.hh rename to src/libstore/include/nix/store/common-protocol.hh index a878e84c9..b464cda67 100644 --- a/src/libstore/common-protocol.hh +++ b/src/libstore/include/nix/store/common-protocol.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "serialise.hh" +#include "nix/util/serialise.hh" namespace nix { diff --git a/src/libstore/common-ssh-store-config.hh b/src/libstore/include/nix/store/common-ssh-store-config.hh similarity index 98% rename from src/libstore/common-ssh-store-config.hh rename to src/libstore/include/nix/store/common-ssh-store-config.hh index 5deb6f4c9..f82124c66 100644 --- a/src/libstore/common-ssh-store-config.hh +++ b/src/libstore/include/nix/store/common-ssh-store-config.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "store-api.hh" +#include "nix/store/store-api.hh" namespace nix { diff --git a/src/libstore/content-address.hh b/src/libstore/include/nix/store/content-address.hh similarity index 98% rename from src/libstore/content-address.hh rename to src/libstore/include/nix/store/content-address.hh index 2b5d1296a..8442fabb2 100644 --- a/src/libstore/content-address.hh +++ b/src/libstore/include/nix/store/content-address.hh @@ -2,10 +2,10 @@ ///@file #include -#include "hash.hh" -#include "path.hh" -#include "file-content-address.hh" -#include "variant-wrapper.hh" +#include "nix/util/hash.hh" +#include "nix/store/path.hh" +#include "nix/util/file-content-address.hh" +#include "nix/util/variant-wrapper.hh" namespace nix { diff --git a/src/libstore/daemon.hh b/src/libstore/include/nix/store/daemon.hh similarity index 79% rename from src/libstore/daemon.hh rename to src/libstore/include/nix/store/daemon.hh index a8ce32d8d..d14541df7 100644 --- a/src/libstore/daemon.hh +++ b/src/libstore/include/nix/store/daemon.hh @@ -1,8 +1,8 @@ #pragma once ///@file -#include "serialise.hh" -#include "store-api.hh" +#include "nix/util/serialise.hh" +#include "nix/store/store-api.hh" namespace nix::daemon { diff --git a/src/libstore/derivation-options.hh b/src/libstore/include/nix/store/derivation-options.hh similarity index 98% rename from src/libstore/derivation-options.hh rename to src/libstore/include/nix/store/derivation-options.hh index 6e4ea5cd9..8f549b737 100644 --- a/src/libstore/derivation-options.hh +++ b/src/libstore/include/nix/store/derivation-options.hh @@ -6,8 +6,8 @@ #include #include -#include "types.hh" -#include "json-impls.hh" +#include "nix/util/types.hh" +#include "nix/util/json-impls.hh" namespace nix { diff --git a/src/libstore/derivations.hh b/src/libstore/include/nix/store/derivations.hh similarity index 98% rename from src/libstore/derivations.hh rename to src/libstore/include/nix/store/derivations.hh index 5b2101ed5..df490dc7b 100644 --- a/src/libstore/derivations.hh +++ b/src/libstore/include/nix/store/derivations.hh @@ -1,14 +1,14 @@ #pragma once ///@file -#include "path.hh" -#include "types.hh" -#include "hash.hh" -#include "content-address.hh" -#include "repair-flag.hh" -#include "derived-path-map.hh" -#include "sync.hh" -#include "variant-wrapper.hh" +#include "nix/store/path.hh" +#include "nix/util/types.hh" +#include "nix/util/hash.hh" +#include "nix/store/content-address.hh" +#include "nix/util/repair-flag.hh" +#include "nix/store/derived-path-map.hh" +#include "nix/util/sync.hh" +#include "nix/util/variant-wrapper.hh" #include #include diff --git a/src/libstore/derived-path-map.hh b/src/libstore/include/nix/store/derived-path-map.hh similarity index 98% rename from src/libstore/derived-path-map.hh rename to src/libstore/include/nix/store/derived-path-map.hh index bd60fe887..956f8bb0b 100644 --- a/src/libstore/derived-path-map.hh +++ b/src/libstore/include/nix/store/derived-path-map.hh @@ -1,8 +1,8 @@ #pragma once ///@file -#include "types.hh" -#include "derived-path.hh" +#include "nix/util/types.hh" +#include "nix/store/derived-path.hh" namespace nix { diff --git a/src/libstore/derived-path.hh b/src/libstore/include/nix/store/derived-path.hh similarity index 98% rename from src/libstore/derived-path.hh rename to src/libstore/include/nix/store/derived-path.hh index 4ba3fb37d..2cf06c9b7 100644 --- a/src/libstore/derived-path.hh +++ b/src/libstore/include/nix/store/derived-path.hh @@ -1,10 +1,10 @@ #pragma once ///@file -#include "path.hh" -#include "outputs-spec.hh" -#include "config.hh" -#include "ref.hh" +#include "nix/store/path.hh" +#include "nix/store/outputs-spec.hh" +#include "nix/util/configuration.hh" +#include "nix/util/ref.hh" #include diff --git a/src/libstore/downstream-placeholder.hh b/src/libstore/include/nix/store/downstream-placeholder.hh similarity index 97% rename from src/libstore/downstream-placeholder.hh rename to src/libstore/include/nix/store/downstream-placeholder.hh index c911ecea2..da03cd9a6 100644 --- a/src/libstore/downstream-placeholder.hh +++ b/src/libstore/include/nix/store/downstream-placeholder.hh @@ -1,9 +1,9 @@ #pragma once ///@file -#include "hash.hh" -#include "path.hh" -#include "derived-path.hh" +#include "nix/util/hash.hh" +#include "nix/store/path.hh" +#include "nix/store/derived-path.hh" namespace nix { diff --git a/src/libstore/filetransfer.hh b/src/libstore/include/nix/store/filetransfer.hh similarity index 96% rename from src/libstore/filetransfer.hh rename to src/libstore/include/nix/store/filetransfer.hh index 0ecc7f376..217c52d77 100644 --- a/src/libstore/filetransfer.hh +++ b/src/libstore/include/nix/store/filetransfer.hh @@ -4,11 +4,11 @@ #include #include -#include "logging.hh" -#include "types.hh" -#include "ref.hh" -#include "config.hh" -#include "serialise.hh" +#include "nix/util/logging.hh" +#include "nix/util/types.hh" +#include "nix/util/ref.hh" +#include "nix/util/configuration.hh" +#include "nix/util/serialise.hh" namespace nix { diff --git a/src/libstore/gc-store.hh b/src/libstore/include/nix/store/gc-store.hh similarity index 99% rename from src/libstore/gc-store.hh rename to src/libstore/include/nix/store/gc-store.hh index 020f770b0..cef6e8776 100644 --- a/src/libstore/gc-store.hh +++ b/src/libstore/include/nix/store/gc-store.hh @@ -3,7 +3,7 @@ #include -#include "store-api.hh" +#include "nix/store/store-api.hh" namespace nix { diff --git a/src/libstore/globals.hh b/src/libstore/include/nix/store/globals.hh similarity index 99% rename from src/libstore/globals.hh rename to src/libstore/include/nix/store/globals.hh index f52b5c4dd..c35b911cf 100644 --- a/src/libstore/globals.hh +++ b/src/libstore/include/nix/store/globals.hh @@ -1,17 +1,19 @@ #pragma once ///@file -#include "types.hh" -#include "config.hh" -#include "environment-variables.hh" -#include "experimental-features.hh" -#include "users.hh" - #include #include #include +#include "nix/util/types.hh" +#include "nix/util/configuration.hh" +#include "nix/util/environment-variables.hh" +#include "nix/util/experimental-features.hh" +#include "nix/util/users.hh" + +#include "nix/store/config.hh" + namespace nix { typedef enum { smEnabled, smRelaxed, smDisabled } SandboxMode; @@ -32,7 +34,7 @@ struct MaxBuildJobsSetting : public BaseSetting }; const uint32_t maxIdsPerBuild = - #if __linux__ + #ifdef __linux__ 1 << 16 #else 1 @@ -181,7 +183,7 @@ public: bool readOnlyMode = false; Setting thisSystem{ - this, SYSTEM, "system", + this, NIX_LOCAL_SYSTEM, "system", R"( The system type of the current Nix installation. Nix will only build a given [store derivation](@docroot@/glossary.md#gloss-store-derivation) locally when its `system` attribute equals any of the values specified here or in [`extra-platforms`](#conf-extra-platforms). @@ -465,7 +467,7 @@ public: )", {}, true, Xp::AutoAllocateUids}; Setting startId{this, - #if __linux__ + #ifdef __linux__ 0x34000000, #else 56930, @@ -474,7 +476,7 @@ public: "The first UID and GID to use for dynamic ID allocation."}; Setting uidCount{this, - #if __linux__ + #ifdef __linux__ maxIdsPerBuild * 128, #else 128, @@ -482,7 +484,7 @@ public: "id-count", "The number of UIDs/GIDs to use for dynamic ID allocation."}; - #if __linux__ + #ifdef __linux__ Setting useCgroups{ this, false, "use-cgroups", R"( @@ -594,7 +596,7 @@ public: Setting sandboxMode{ this, - #if __linux__ + #ifdef __linux__ smEnabled #else smDisabled @@ -669,7 +671,7 @@ public: )"}; #endif -#if __linux__ +#ifdef __linux__ Setting sandboxShmSize{ this, "50%", "sandbox-dev-shm-size", R"( @@ -706,7 +708,7 @@ public: Setting allowedImpureHostPrefixes{this, {}, "allowed-impure-host-deps", "Which prefixes to allow derivations to ask for access to (primarily for Darwin)."}; -#if __APPLE__ +#ifdef __APPLE__ Setting darwinLogSandboxViolations{this, false, "darwin-log-sandbox-violations", "Whether to log Darwin sandbox access violations to the system log."}; #endif @@ -1064,7 +1066,7 @@ public: // Don't document the machine-specific default value false}; -#if __linux__ +#ifdef __linux__ Setting filterSyscalls{ this, true, "filter-syscalls", R"( @@ -1089,7 +1091,7 @@ public: )"}; #endif -#if HAVE_ACL_SUPPORT +#if NIX_SUPPORT_ACL Setting ignoredAcls{ this, {"security.selinux", "system.nfs4_acl", "security.csm"}, "ignored-acls", R"( diff --git a/src/libstore/http-binary-cache-store.hh b/src/libstore/include/nix/store/http-binary-cache-store.hh similarity index 93% rename from src/libstore/http-binary-cache-store.hh rename to src/libstore/include/nix/store/http-binary-cache-store.hh index d2fc43210..aaec3116d 100644 --- a/src/libstore/http-binary-cache-store.hh +++ b/src/libstore/include/nix/store/http-binary-cache-store.hh @@ -1,4 +1,4 @@ -#include "binary-cache-store.hh" +#include "nix/store/binary-cache-store.hh" namespace nix { diff --git a/src/libstore/indirect-root-store.hh b/src/libstore/include/nix/store/indirect-root-store.hh similarity index 98% rename from src/libstore/indirect-root-store.hh rename to src/libstore/include/nix/store/indirect-root-store.hh index b74ebc1ee..bbdad83f3 100644 --- a/src/libstore/indirect-root-store.hh +++ b/src/libstore/include/nix/store/indirect-root-store.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "local-fs-store.hh" +#include "nix/store/local-fs-store.hh" namespace nix { diff --git a/src/libstore/keys.hh b/src/libstore/include/nix/store/keys.hh similarity index 64% rename from src/libstore/keys.hh rename to src/libstore/include/nix/store/keys.hh index 3da19493f..77aec6bb2 100644 --- a/src/libstore/keys.hh +++ b/src/libstore/include/nix/store/keys.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "signature/local-keys.hh" +#include "nix/util/signature/local-keys.hh" namespace nix { diff --git a/src/libstore/legacy-ssh-store.hh b/src/libstore/include/nix/store/legacy-ssh-store.hh similarity index 96% rename from src/libstore/legacy-ssh-store.hh rename to src/libstore/include/nix/store/legacy-ssh-store.hh index 92aa4ae56..a1fbf3f1e 100644 --- a/src/libstore/legacy-ssh-store.hh +++ b/src/libstore/include/nix/store/legacy-ssh-store.hh @@ -1,12 +1,12 @@ #pragma once ///@file -#include "common-ssh-store-config.hh" -#include "store-api.hh" -#include "ssh.hh" -#include "callback.hh" -#include "pool.hh" -#include "serve-protocol.hh" +#include "nix/store/common-ssh-store-config.hh" +#include "nix/store/store-api.hh" +#include "nix/store/ssh.hh" +#include "nix/util/callback.hh" +#include "nix/util/pool.hh" +#include "nix/store/serve-protocol.hh" namespace nix { diff --git a/src/libstore/length-prefixed-protocol-helper.hh b/src/libstore/include/nix/store/length-prefixed-protocol-helper.hh similarity index 99% rename from src/libstore/length-prefixed-protocol-helper.hh rename to src/libstore/include/nix/store/length-prefixed-protocol-helper.hh index 7e977bbf1..664841aae 100644 --- a/src/libstore/length-prefixed-protocol-helper.hh +++ b/src/libstore/include/nix/store/length-prefixed-protocol-helper.hh @@ -8,7 +8,7 @@ * Used by both the Worker and Serve protocols. */ -#include "types.hh" +#include "nix/util/types.hh" namespace nix { diff --git a/src/libstore/local-binary-cache-store.hh b/src/libstore/include/nix/store/local-binary-cache-store.hh similarity index 91% rename from src/libstore/local-binary-cache-store.hh rename to src/libstore/include/nix/store/local-binary-cache-store.hh index 997e8ecbb..dde4701da 100644 --- a/src/libstore/local-binary-cache-store.hh +++ b/src/libstore/include/nix/store/local-binary-cache-store.hh @@ -1,4 +1,4 @@ -#include "binary-cache-store.hh" +#include "nix/store/binary-cache-store.hh" namespace nix { diff --git a/src/libstore/local-fs-store.hh b/src/libstore/include/nix/store/local-fs-store.hh similarity index 96% rename from src/libstore/local-fs-store.hh rename to src/libstore/include/nix/store/local-fs-store.hh index 9bb569f0b..6d5afcb08 100644 --- a/src/libstore/local-fs-store.hh +++ b/src/libstore/include/nix/store/local-fs-store.hh @@ -1,9 +1,9 @@ #pragma once ///@file -#include "store-api.hh" -#include "gc-store.hh" -#include "log-store.hh" +#include "nix/store/store-api.hh" +#include "nix/store/gc-store.hh" +#include "nix/store/log-store.hh" namespace nix { diff --git a/src/libstore/local-overlay-store.hh b/src/libstore/include/nix/store/local-overlay-store.hh similarity index 99% rename from src/libstore/local-overlay-store.hh rename to src/libstore/include/nix/store/local-overlay-store.hh index 63628abed..825214cb6 100644 --- a/src/libstore/local-overlay-store.hh +++ b/src/libstore/include/nix/store/local-overlay-store.hh @@ -1,4 +1,4 @@ -#include "local-store.hh" +#include "nix/store/local-store.hh" namespace nix { diff --git a/src/libstore/local-store.hh b/src/libstore/include/nix/store/local-store.hh similarity index 98% rename from src/libstore/local-store.hh rename to src/libstore/include/nix/store/local-store.hh index 83154d651..3691fb4b6 100644 --- a/src/libstore/local-store.hh +++ b/src/libstore/include/nix/store/local-store.hh @@ -1,12 +1,12 @@ #pragma once ///@file -#include "sqlite.hh" +#include "nix/store/sqlite.hh" -#include "pathlocks.hh" -#include "store-api.hh" -#include "indirect-root-store.hh" -#include "sync.hh" +#include "nix/store/pathlocks.hh" +#include "nix/store/store-api.hh" +#include "nix/store/indirect-root-store.hh" +#include "nix/util/sync.hh" #include #include diff --git a/src/libstore/log-store.hh b/src/libstore/include/nix/store/log-store.hh similarity index 94% rename from src/libstore/log-store.hh rename to src/libstore/include/nix/store/log-store.hh index a84f7dbeb..fc12b0c47 100644 --- a/src/libstore/log-store.hh +++ b/src/libstore/include/nix/store/log-store.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "store-api.hh" +#include "nix/store/store-api.hh" namespace nix { diff --git a/src/libstore/machines.hh b/src/libstore/include/nix/store/machines.hh similarity index 97% rename from src/libstore/machines.hh rename to src/libstore/include/nix/store/machines.hh index b70ab9078..f07d6b63b 100644 --- a/src/libstore/machines.hh +++ b/src/libstore/include/nix/store/machines.hh @@ -1,8 +1,8 @@ #pragma once ///@file -#include "ref.hh" -#include "store-reference.hh" +#include "nix/util/ref.hh" +#include "nix/store/store-reference.hh" namespace nix { diff --git a/src/libstore/make-content-addressed.hh b/src/libstore/include/nix/store/make-content-addressed.hh similarity index 93% rename from src/libstore/make-content-addressed.hh rename to src/libstore/include/nix/store/make-content-addressed.hh index 60bb2b477..3881b6d40 100644 --- a/src/libstore/make-content-addressed.hh +++ b/src/libstore/include/nix/store/make-content-addressed.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "store-api.hh" +#include "nix/store/store-api.hh" namespace nix { diff --git a/src/libstore/include/nix/store/meson.build b/src/libstore/include/nix/store/meson.build new file mode 100644 index 000000000..312fd5e87 --- /dev/null +++ b/src/libstore/include/nix/store/meson.build @@ -0,0 +1,81 @@ +# Public headers directory + +include_dirs = [ + include_directories('../..'), +] + +config_pub_h = configure_file( + configuration : configdata_pub, + output : 'config.hh', +) + +headers = [config_pub_h] + files( + 'binary-cache-store.hh', + 'build-result.hh', + 'build/derivation-goal.hh', + 'build/drv-output-substitution-goal.hh', + 'build/goal.hh', + 'build/substitution-goal.hh', + 'build/worker.hh', + 'builtins.hh', + 'builtins/buildenv.hh', + 'common-protocol-impl.hh', + 'common-protocol.hh', + 'common-ssh-store-config.hh', + 'content-address.hh', + 'daemon.hh', + 'derivations.hh', + 'derivation-options.hh', + 'derived-path-map.hh', + 'derived-path.hh', + 'downstream-placeholder.hh', + 'filetransfer.hh', + 'gc-store.hh', + 'globals.hh', + 'http-binary-cache-store.hh', + 'indirect-root-store.hh', + 'keys.hh', + 'legacy-ssh-store.hh', + 'length-prefixed-protocol-helper.hh', + 'local-binary-cache-store.hh', + 'local-fs-store.hh', + 'local-overlay-store.hh', + 'local-store.hh', + 'log-store.hh', + 'machines.hh', + 'make-content-addressed.hh', + 'names.hh', + 'nar-accessor.hh', + 'nar-info-disk-cache.hh', + 'nar-info.hh', + 'outputs-spec.hh', + 'parsed-derivations.hh', + 'path-info.hh', + 'path-references.hh', + 'path-regex.hh', + 'path-with-outputs.hh', + 'path.hh', + 'pathlocks.hh', + 'posix-fs-canonicalise.hh', + 'profiles.hh', + 'realisation.hh', + 'remote-fs-accessor.hh', + 'remote-store-connection.hh', + 'remote-store.hh', + 's3-binary-cache-store.hh', + 's3.hh', + 'ssh-store.hh', + 'serve-protocol-connection.hh', + 'serve-protocol-impl.hh', + 'serve-protocol.hh', + 'sqlite.hh', + 'ssh.hh', + 'store-api.hh', + 'store-cast.hh', + 'store-dir-config.hh', + 'store-reference.hh', + 'uds-remote-store.hh', + 'worker-protocol-connection.hh', + 'worker-protocol-impl.hh', + 'worker-protocol.hh', +) diff --git a/src/libstore/names.hh b/src/libstore/include/nix/store/names.hh similarity index 95% rename from src/libstore/names.hh rename to src/libstore/include/nix/store/names.hh index a6909d545..ab315de63 100644 --- a/src/libstore/names.hh +++ b/src/libstore/include/nix/store/names.hh @@ -3,7 +3,7 @@ #include -#include "types.hh" +#include "nix/util/types.hh" namespace nix { diff --git a/src/libstore/nar-accessor.hh b/src/libstore/include/nix/store/nar-accessor.hh similarity index 95% rename from src/libstore/nar-accessor.hh rename to src/libstore/include/nix/store/nar-accessor.hh index 0043897c6..199d525cb 100644 --- a/src/libstore/nar-accessor.hh +++ b/src/libstore/include/nix/store/nar-accessor.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "source-accessor.hh" +#include "nix/util/source-accessor.hh" #include diff --git a/src/libstore/nar-info-disk-cache.hh b/src/libstore/include/nix/store/nar-info-disk-cache.hh similarity index 93% rename from src/libstore/nar-info-disk-cache.hh rename to src/libstore/include/nix/store/nar-info-disk-cache.hh index bbd1d05d5..a7fde1fbf 100644 --- a/src/libstore/nar-info-disk-cache.hh +++ b/src/libstore/include/nix/store/nar-info-disk-cache.hh @@ -1,9 +1,9 @@ #pragma once ///@file -#include "ref.hh" -#include "nar-info.hh" -#include "realisation.hh" +#include "nix/util/ref.hh" +#include "nix/store/nar-info.hh" +#include "nix/store/realisation.hh" namespace nix { diff --git a/src/libstore/nar-info.hh b/src/libstore/include/nix/store/nar-info.hh similarity index 92% rename from src/libstore/nar-info.hh rename to src/libstore/include/nix/store/nar-info.hh index 561c9a863..d66b6e058 100644 --- a/src/libstore/nar-info.hh +++ b/src/libstore/include/nix/store/nar-info.hh @@ -1,9 +1,9 @@ #pragma once ///@file -#include "types.hh" -#include "hash.hh" -#include "path-info.hh" +#include "nix/util/types.hh" +#include "nix/util/hash.hh" +#include "nix/store/path-info.hh" namespace nix { diff --git a/src/libstore/outputs-spec.hh b/src/libstore/include/nix/store/outputs-spec.hh similarity index 97% rename from src/libstore/outputs-spec.hh rename to src/libstore/include/nix/store/outputs-spec.hh index 30d15311d..b89f425c2 100644 --- a/src/libstore/outputs-spec.hh +++ b/src/libstore/include/nix/store/outputs-spec.hh @@ -6,8 +6,8 @@ #include #include -#include "json-impls.hh" -#include "variant-wrapper.hh" +#include "nix/util/json-impls.hh" +#include "nix/util/variant-wrapper.hh" namespace nix { diff --git a/src/libstore/parsed-derivations.hh b/src/libstore/include/nix/store/parsed-derivations.hh similarity index 94% rename from src/libstore/parsed-derivations.hh rename to src/libstore/include/nix/store/parsed-derivations.hh index 51992fa84..d65db6133 100644 --- a/src/libstore/parsed-derivations.hh +++ b/src/libstore/include/nix/store/parsed-derivations.hh @@ -1,8 +1,8 @@ #pragma once ///@file -#include "derivations.hh" -#include "store-api.hh" +#include "nix/store/derivations.hh" +#include "nix/store/store-api.hh" #include diff --git a/src/libstore/path-info.hh b/src/libstore/include/nix/store/path-info.hh similarity index 97% rename from src/libstore/path-info.hh rename to src/libstore/include/nix/store/path-info.hh index 9a4c466a8..9bd493422 100644 --- a/src/libstore/path-info.hh +++ b/src/libstore/include/nix/store/path-info.hh @@ -1,10 +1,10 @@ #pragma once ///@file -#include "signature/signer.hh" -#include "path.hh" -#include "hash.hh" -#include "content-address.hh" +#include "nix/util/signature/signer.hh" +#include "nix/store/path.hh" +#include "nix/util/hash.hh" +#include "nix/store/content-address.hh" #include #include diff --git a/src/libstore/path-references.hh b/src/libstore/include/nix/store/path-references.hh similarity index 89% rename from src/libstore/path-references.hh rename to src/libstore/include/nix/store/path-references.hh index 0553003f8..b8d0b4dd0 100644 --- a/src/libstore/path-references.hh +++ b/src/libstore/include/nix/store/path-references.hh @@ -1,8 +1,8 @@ #pragma once ///@file -#include "references.hh" -#include "path.hh" +#include "nix/util/references.hh" +#include "nix/store/path.hh" namespace nix { diff --git a/src/libstore/path-regex.hh b/src/libstore/include/nix/store/path-regex.hh similarity index 100% rename from src/libstore/path-regex.hh rename to src/libstore/include/nix/store/path-regex.hh diff --git a/src/libstore/path-with-outputs.hh b/src/libstore/include/nix/store/path-with-outputs.hh similarity index 95% rename from src/libstore/path-with-outputs.hh rename to src/libstore/include/nix/store/path-with-outputs.hh index 5f76a583a..76c1f9f8f 100644 --- a/src/libstore/path-with-outputs.hh +++ b/src/libstore/include/nix/store/path-with-outputs.hh @@ -1,8 +1,8 @@ #pragma once ///@file -#include "path.hh" -#include "derived-path.hh" +#include "nix/store/path.hh" +#include "nix/store/derived-path.hh" namespace nix { diff --git a/src/libstore/path.hh b/src/libstore/include/nix/store/path.hh similarity index 98% rename from src/libstore/path.hh rename to src/libstore/include/nix/store/path.hh index 902262362..279e9dba4 100644 --- a/src/libstore/path.hh +++ b/src/libstore/include/nix/store/path.hh @@ -3,7 +3,7 @@ #include -#include "types.hh" +#include "nix/util/types.hh" namespace nix { diff --git a/src/libstore/pathlocks.hh b/src/libstore/include/nix/store/pathlocks.hh similarity index 96% rename from src/libstore/pathlocks.hh rename to src/libstore/include/nix/store/pathlocks.hh index 42a84a1a3..33cad7868 100644 --- a/src/libstore/pathlocks.hh +++ b/src/libstore/include/nix/store/pathlocks.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "file-descriptor.hh" +#include "nix/util/file-descriptor.hh" namespace nix { diff --git a/src/libstore/posix-fs-canonicalise.hh b/src/libstore/include/nix/store/posix-fs-canonicalise.hh similarity index 95% rename from src/libstore/posix-fs-canonicalise.hh rename to src/libstore/include/nix/store/posix-fs-canonicalise.hh index 45a4f3f20..1d6696023 100644 --- a/src/libstore/posix-fs-canonicalise.hh +++ b/src/libstore/include/nix/store/posix-fs-canonicalise.hh @@ -4,8 +4,8 @@ #include #include -#include "types.hh" -#include "error.hh" +#include "nix/util/types.hh" +#include "nix/util/error.hh" namespace nix { diff --git a/src/libstore/profiles.hh b/src/libstore/include/nix/store/profiles.hh similarity index 99% rename from src/libstore/profiles.hh rename to src/libstore/include/nix/store/profiles.hh index 33fcf04b3..804c6e2b7 100644 --- a/src/libstore/profiles.hh +++ b/src/libstore/include/nix/store/profiles.hh @@ -7,8 +7,8 @@ * See the manual for additional information. */ -#include "types.hh" -#include "pathlocks.hh" +#include "nix/util/types.hh" +#include "nix/store/pathlocks.hh" #include #include diff --git a/src/libstore/realisation.hh b/src/libstore/include/nix/store/realisation.hh similarity index 96% rename from src/libstore/realisation.hh rename to src/libstore/include/nix/store/realisation.hh index ddb4af770..b93ae37b6 100644 --- a/src/libstore/realisation.hh +++ b/src/libstore/include/nix/store/realisation.hh @@ -3,12 +3,12 @@ #include -#include "hash.hh" -#include "path.hh" -#include "derived-path.hh" +#include "nix/util/hash.hh" +#include "nix/store/path.hh" +#include "nix/store/derived-path.hh" #include -#include "comparator.hh" -#include "signature/signer.hh" +#include "nix/util/comparator.hh" +#include "nix/util/signature/signer.hh" namespace nix { diff --git a/src/libstore/remote-fs-accessor.hh b/src/libstore/include/nix/store/remote-fs-accessor.hh similarity index 90% rename from src/libstore/remote-fs-accessor.hh rename to src/libstore/include/nix/store/remote-fs-accessor.hh index d09762a53..75a840fb0 100644 --- a/src/libstore/remote-fs-accessor.hh +++ b/src/libstore/include/nix/store/remote-fs-accessor.hh @@ -1,9 +1,9 @@ #pragma once ///@file -#include "source-accessor.hh" -#include "ref.hh" -#include "store-api.hh" +#include "nix/util/source-accessor.hh" +#include "nix/util/ref.hh" +#include "nix/store/store-api.hh" namespace nix { diff --git a/src/libstore/remote-store-connection.hh b/src/libstore/include/nix/store/remote-store-connection.hh similarity index 90% rename from src/libstore/remote-store-connection.hh rename to src/libstore/include/nix/store/remote-store-connection.hh index f8549d0b2..33ec265c2 100644 --- a/src/libstore/remote-store-connection.hh +++ b/src/libstore/include/nix/store/remote-store-connection.hh @@ -1,10 +1,10 @@ #pragma once ///@file -#include "remote-store.hh" -#include "worker-protocol.hh" -#include "worker-protocol-connection.hh" -#include "pool.hh" +#include "nix/store/remote-store.hh" +#include "nix/store/worker-protocol.hh" +#include "nix/store/worker-protocol-connection.hh" +#include "nix/util/pool.hh" namespace nix { diff --git a/src/libstore/remote-store.hh b/src/libstore/include/nix/store/remote-store.hh similarity index 98% rename from src/libstore/remote-store.hh rename to src/libstore/include/nix/store/remote-store.hh index ea6cd471e..ecf18bd76 100644 --- a/src/libstore/remote-store.hh +++ b/src/libstore/include/nix/store/remote-store.hh @@ -4,9 +4,9 @@ #include #include -#include "store-api.hh" -#include "gc-store.hh" -#include "log-store.hh" +#include "nix/store/store-api.hh" +#include "nix/store/gc-store.hh" +#include "nix/store/log-store.hh" namespace nix { diff --git a/src/libstore/s3-binary-cache-store.hh b/src/libstore/include/nix/store/s3-binary-cache-store.hh similarity index 96% rename from src/libstore/s3-binary-cache-store.hh rename to src/libstore/include/nix/store/s3-binary-cache-store.hh index 7d303a115..7bc04aa4a 100644 --- a/src/libstore/s3-binary-cache-store.hh +++ b/src/libstore/include/nix/store/s3-binary-cache-store.hh @@ -1,9 +1,13 @@ #pragma once ///@file -#include "binary-cache-store.hh" +#include "nix/store/config.hh" -#include +#if NIX_WITH_S3_SUPPORT + +# include "nix/store/binary-cache-store.hh" + +# include namespace nix { @@ -125,3 +129,5 @@ public: }; } + +#endif diff --git a/src/libstore/s3.hh b/src/libstore/include/nix/store/s3.hh similarity index 90% rename from src/libstore/s3.hh rename to src/libstore/include/nix/store/s3.hh index 18de115ae..9c159ba0f 100644 --- a/src/libstore/s3.hh +++ b/src/libstore/include/nix/store/s3.hh @@ -1,9 +1,9 @@ #pragma once ///@file +#include "store-config-private.hh" +#if NIX_WITH_S3_SUPPORT -#if ENABLE_S3 - -#include "ref.hh" +#include "nix/util/ref.hh" #include #include diff --git a/src/libstore/serve-protocol-connection.hh b/src/libstore/include/nix/store/serve-protocol-connection.hh similarity index 97% rename from src/libstore/serve-protocol-connection.hh rename to src/libstore/include/nix/store/serve-protocol-connection.hh index 73bf71443..5822b4990 100644 --- a/src/libstore/serve-protocol-connection.hh +++ b/src/libstore/include/nix/store/serve-protocol-connection.hh @@ -1,8 +1,8 @@ #pragma once ///@file -#include "serve-protocol.hh" -#include "store-api.hh" +#include "nix/store/serve-protocol.hh" +#include "nix/store/store-api.hh" namespace nix { diff --git a/src/libstore/serve-protocol-impl.hh b/src/libstore/include/nix/store/serve-protocol-impl.hh similarity index 94% rename from src/libstore/serve-protocol-impl.hh rename to src/libstore/include/nix/store/serve-protocol-impl.hh index 099eade64..769b9ae2b 100644 --- a/src/libstore/serve-protocol-impl.hh +++ b/src/libstore/include/nix/store/serve-protocol-impl.hh @@ -8,8 +8,8 @@ * contributing guide. */ -#include "serve-protocol.hh" -#include "length-prefixed-protocol-helper.hh" +#include "nix/store/serve-protocol.hh" +#include "nix/store/length-prefixed-protocol-helper.hh" namespace nix { diff --git a/src/libstore/serve-protocol.hh b/src/libstore/include/nix/store/serve-protocol.hh similarity index 99% rename from src/libstore/serve-protocol.hh rename to src/libstore/include/nix/store/serve-protocol.hh index 8c112bb74..76f0ecd49 100644 --- a/src/libstore/serve-protocol.hh +++ b/src/libstore/include/nix/store/serve-protocol.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "common-protocol.hh" +#include "nix/store/common-protocol.hh" namespace nix { diff --git a/src/libstore/sqlite.hh b/src/libstore/include/nix/store/sqlite.hh similarity index 99% rename from src/libstore/sqlite.hh rename to src/libstore/include/nix/store/sqlite.hh index 037380b71..266930d75 100644 --- a/src/libstore/sqlite.hh +++ b/src/libstore/include/nix/store/sqlite.hh @@ -4,7 +4,7 @@ #include #include -#include "error.hh" +#include "nix/util/error.hh" struct sqlite3; struct sqlite3_stmt; diff --git a/src/libstore/ssh-store.hh b/src/libstore/include/nix/store/ssh-store.hh similarity index 89% rename from src/libstore/ssh-store.hh rename to src/libstore/include/nix/store/ssh-store.hh index 29a2a8b2c..76e8e33a4 100644 --- a/src/libstore/ssh-store.hh +++ b/src/libstore/include/nix/store/ssh-store.hh @@ -1,10 +1,10 @@ #pragma once ///@file -#include "common-ssh-store-config.hh" -#include "store-api.hh" -#include "local-fs-store.hh" -#include "remote-store.hh" +#include "nix/store/common-ssh-store-config.hh" +#include "nix/store/store-api.hh" +#include "nix/store/local-fs-store.hh" +#include "nix/store/remote-store.hh" namespace nix { diff --git a/src/libstore/ssh.hh b/src/libstore/include/nix/store/ssh.hh similarity index 95% rename from src/libstore/ssh.hh rename to src/libstore/include/nix/store/ssh.hh index eb05df011..40f2189d8 100644 --- a/src/libstore/ssh.hh +++ b/src/libstore/include/nix/store/ssh.hh @@ -1,9 +1,9 @@ #pragma once ///@file -#include "sync.hh" -#include "processes.hh" -#include "file-system.hh" +#include "nix/util/sync.hh" +#include "nix/util/processes.hh" +#include "nix/util/file-system.hh" namespace nix { diff --git a/src/libstore/store-api.hh b/src/libstore/include/nix/store/store-api.hh similarity index 98% rename from src/libstore/store-api.hh rename to src/libstore/include/nix/store/store-api.hh index 2eba88ea0..cee1dba6e 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/include/nix/store/store-api.hh @@ -1,20 +1,20 @@ #pragma once ///@file -#include "path.hh" -#include "derived-path.hh" -#include "hash.hh" -#include "content-address.hh" -#include "serialise.hh" -#include "lru-cache.hh" -#include "sync.hh" -#include "globals.hh" -#include "config.hh" -#include "path-info.hh" -#include "repair-flag.hh" -#include "store-dir-config.hh" -#include "store-reference.hh" -#include "source-path.hh" +#include "nix/store/path.hh" +#include "nix/store/derived-path.hh" +#include "nix/util/hash.hh" +#include "nix/store/content-address.hh" +#include "nix/util/serialise.hh" +#include "nix/util/lru-cache.hh" +#include "nix/util/sync.hh" +#include "nix/store/globals.hh" +#include "nix/util/configuration.hh" +#include "nix/store/path-info.hh" +#include "nix/util/repair-flag.hh" +#include "nix/store/store-dir-config.hh" +#include "nix/store/store-reference.hh" +#include "nix/util/source-path.hh" #include #include diff --git a/src/libstore/store-cast.hh b/src/libstore/include/nix/store/store-cast.hh similarity index 93% rename from src/libstore/store-cast.hh rename to src/libstore/include/nix/store/store-cast.hh index 2473e72c5..0bf61bb77 100644 --- a/src/libstore/store-cast.hh +++ b/src/libstore/include/nix/store/store-cast.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "store-api.hh" +#include "nix/store/store-api.hh" namespace nix { diff --git a/src/libstore/store-dir-config.hh b/src/libstore/include/nix/store/store-dir-config.hh similarity index 94% rename from src/libstore/store-dir-config.hh rename to src/libstore/include/nix/store/store-dir-config.hh index fd4332b91..845a003f5 100644 --- a/src/libstore/store-dir-config.hh +++ b/src/libstore/include/nix/store/store-dir-config.hh @@ -1,10 +1,10 @@ #pragma once -#include "path.hh" -#include "hash.hh" -#include "content-address.hh" -#include "globals.hh" -#include "config.hh" +#include "nix/store/path.hh" +#include "nix/util/hash.hh" +#include "nix/store/content-address.hh" +#include "nix/store/globals.hh" +#include "nix/util/configuration.hh" #include #include diff --git a/src/libstore/store-reference.hh b/src/libstore/include/nix/store/store-reference.hh similarity index 98% rename from src/libstore/store-reference.hh rename to src/libstore/include/nix/store/store-reference.hh index 7100a1db0..433a347aa 100644 --- a/src/libstore/store-reference.hh +++ b/src/libstore/include/nix/store/store-reference.hh @@ -3,7 +3,7 @@ #include -#include "types.hh" +#include "nix/util/types.hh" namespace nix { diff --git a/src/libstore/uds-remote-store.hh b/src/libstore/include/nix/store/uds-remote-store.hh similarity index 94% rename from src/libstore/uds-remote-store.hh rename to src/libstore/include/nix/store/uds-remote-store.hh index a8e571664..f7ef76058 100644 --- a/src/libstore/uds-remote-store.hh +++ b/src/libstore/include/nix/store/uds-remote-store.hh @@ -1,9 +1,9 @@ #pragma once ///@file -#include "remote-store.hh" -#include "remote-store-connection.hh" -#include "indirect-root-store.hh" +#include "nix/store/remote-store.hh" +#include "nix/store/remote-store-connection.hh" +#include "nix/store/indirect-root-store.hh" namespace nix { diff --git a/src/libstore/worker-protocol-connection.hh b/src/libstore/include/nix/store/worker-protocol-connection.hh similarity index 98% rename from src/libstore/worker-protocol-connection.hh rename to src/libstore/include/nix/store/worker-protocol-connection.hh index c2f446db1..df2fe0ec2 100644 --- a/src/libstore/worker-protocol-connection.hh +++ b/src/libstore/include/nix/store/worker-protocol-connection.hh @@ -1,8 +1,8 @@ #pragma once ///@file -#include "worker-protocol.hh" -#include "store-api.hh" +#include "nix/store/worker-protocol.hh" +#include "nix/store/store-api.hh" namespace nix { diff --git a/src/libstore/worker-protocol-impl.hh b/src/libstore/include/nix/store/worker-protocol-impl.hh similarity index 94% rename from src/libstore/worker-protocol-impl.hh rename to src/libstore/include/nix/store/worker-protocol-impl.hh index 87398df90..337c245e2 100644 --- a/src/libstore/worker-protocol-impl.hh +++ b/src/libstore/include/nix/store/worker-protocol-impl.hh @@ -8,8 +8,8 @@ * contributing guide. */ -#include "worker-protocol.hh" -#include "length-prefixed-protocol-helper.hh" +#include "nix/store/worker-protocol.hh" +#include "nix/store/length-prefixed-protocol-helper.hh" namespace nix { diff --git a/src/libstore/worker-protocol.hh b/src/libstore/include/nix/store/worker-protocol.hh similarity index 99% rename from src/libstore/worker-protocol.hh rename to src/libstore/include/nix/store/worker-protocol.hh index c356fa1bf..3060681b8 100644 --- a/src/libstore/worker-protocol.hh +++ b/src/libstore/include/nix/store/worker-protocol.hh @@ -3,7 +3,7 @@ #include -#include "common-protocol.hh" +#include "nix/store/common-protocol.hh" namespace nix { diff --git a/src/libstore/indirect-root-store.cc b/src/libstore/indirect-root-store.cc index 844d0d6ed..e23c01e5d 100644 --- a/src/libstore/indirect-root-store.cc +++ b/src/libstore/indirect-root-store.cc @@ -1,4 +1,4 @@ -#include "indirect-root-store.hh" +#include "nix/store/indirect-root-store.hh" namespace nix { diff --git a/src/libstore/keys.cc b/src/libstore/keys.cc index 668725fc7..9abea9520 100644 --- a/src/libstore/keys.cc +++ b/src/libstore/keys.cc @@ -1,6 +1,6 @@ -#include "file-system.hh" -#include "globals.hh" -#include "keys.hh" +#include "nix/util/file-system.hh" +#include "nix/store/globals.hh" +#include "nix/store/keys.hh" namespace nix { diff --git a/src/libstore/legacy-ssh-store.cc b/src/libstore/legacy-ssh-store.cc index 480f41059..1512a7944 100644 --- a/src/libstore/legacy-ssh-store.cc +++ b/src/libstore/legacy-ssh-store.cc @@ -1,17 +1,17 @@ -#include "legacy-ssh-store.hh" -#include "common-ssh-store-config.hh" -#include "archive.hh" -#include "pool.hh" -#include "remote-store.hh" -#include "serve-protocol.hh" -#include "serve-protocol-connection.hh" -#include "serve-protocol-impl.hh" -#include "build-result.hh" -#include "store-api.hh" -#include "path-with-outputs.hh" -#include "ssh.hh" -#include "derivations.hh" -#include "callback.hh" +#include "nix/store/legacy-ssh-store.hh" +#include "nix/store/common-ssh-store-config.hh" +#include "nix/util/archive.hh" +#include "nix/util/pool.hh" +#include "nix/store/remote-store.hh" +#include "nix/store/serve-protocol.hh" +#include "nix/store/serve-protocol-connection.hh" +#include "nix/store/serve-protocol-impl.hh" +#include "nix/store/build-result.hh" +#include "nix/store/store-api.hh" +#include "nix/store/path-with-outputs.hh" +#include "nix/store/ssh.hh" +#include "nix/store/derivations.hh" +#include "nix/util/callback.hh" namespace nix { diff --git a/src/libstore/linux/fchmodat2-compat.hh b/src/libstore/linux/include/nix/store/fchmodat2-compat.hh similarity index 97% rename from src/libstore/linux/fchmodat2-compat.hh rename to src/libstore/linux/include/nix/store/fchmodat2-compat.hh index fd03b9ed5..42b3f3a35 100644 --- a/src/libstore/linux/fchmodat2-compat.hh +++ b/src/libstore/linux/include/nix/store/fchmodat2-compat.hh @@ -1,3 +1,5 @@ +#include "store-config-private.hh" + /* * Determine the syscall number for `fchmodat2`. * diff --git a/src/libstore/linux/include/nix/store/meson.build b/src/libstore/linux/include/nix/store/meson.build new file mode 100644 index 000000000..fd05fcaea --- /dev/null +++ b/src/libstore/linux/include/nix/store/meson.build @@ -0,0 +1,6 @@ +include_dirs += include_directories('../..') + +headers += files( + 'fchmodat2-compat.hh', + 'personality.hh', +) diff --git a/src/libstore/linux/personality.hh b/src/libstore/linux/include/nix/store/personality.hh similarity index 100% rename from src/libstore/linux/personality.hh rename to src/libstore/linux/include/nix/store/personality.hh diff --git a/src/libstore/linux/meson.build b/src/libstore/linux/meson.build index 0c494b5d6..6fc193cf8 100644 --- a/src/libstore/linux/meson.build +++ b/src/libstore/linux/meson.build @@ -2,9 +2,4 @@ sources += files( 'personality.cc', ) -include_dirs += include_directories('.') - -headers += files( - 'fchmodat2-compat.hh', - 'personality.hh', -) +subdir('include/nix/store') diff --git a/src/libstore/linux/personality.cc b/src/libstore/linux/personality.cc index 255d174a6..e87006d86 100644 --- a/src/libstore/linux/personality.cc +++ b/src/libstore/linux/personality.cc @@ -1,5 +1,5 @@ -#include "personality.hh" -#include "globals.hh" +#include "nix/store/personality.hh" +#include "nix/store/globals.hh" #include #include @@ -15,7 +15,7 @@ void setPersonality(std::string_view system) struct utsname utsbuf; uname(&utsbuf); if ((system == "i686-linux" - && (std::string_view(SYSTEM) == "x86_64-linux" + && (std::string_view(NIX_LOCAL_SYSTEM) == "x86_64-linux" || (!strcmp(utsbuf.sysname, "Linux") && !strcmp(utsbuf.machine, "x86_64")))) || system == "armv7l-linux" || system == "armv6l-linux" diff --git a/src/libstore/local-binary-cache-store.cc b/src/libstore/local-binary-cache-store.cc index dcc6affe4..212eacc8c 100644 --- a/src/libstore/local-binary-cache-store.cc +++ b/src/libstore/local-binary-cache-store.cc @@ -1,7 +1,7 @@ -#include "local-binary-cache-store.hh" -#include "globals.hh" -#include "nar-info-disk-cache.hh" -#include "signals.hh" +#include "nix/store/local-binary-cache-store.hh" +#include "nix/store/globals.hh" +#include "nix/store/nar-info-disk-cache.hh" +#include "nix/util/signals.hh" #include diff --git a/src/libstore/local-fs-store.cc b/src/libstore/local-fs-store.cc index 5449b20eb..599765ced 100644 --- a/src/libstore/local-fs-store.cc +++ b/src/libstore/local-fs-store.cc @@ -1,10 +1,10 @@ -#include "archive.hh" -#include "posix-source-accessor.hh" -#include "store-api.hh" -#include "local-fs-store.hh" -#include "globals.hh" -#include "compression.hh" -#include "derivations.hh" +#include "nix/util/archive.hh" +#include "nix/util/posix-source-accessor.hh" +#include "nix/store/store-api.hh" +#include "nix/store/local-fs-store.hh" +#include "nix/store/globals.hh" +#include "nix/util/compression.hh" +#include "nix/store/derivations.hh" namespace nix { diff --git a/src/libstore/local-overlay-store.cc b/src/libstore/local-overlay-store.cc index 56ff6bef3..38fa634ca 100644 --- a/src/libstore/local-overlay-store.cc +++ b/src/libstore/local-overlay-store.cc @@ -1,8 +1,8 @@ -#include "local-overlay-store.hh" -#include "callback.hh" -#include "realisation.hh" -#include "processes.hh" -#include "url.hh" +#include "nix/store/local-overlay-store.hh" +#include "nix/util/callback.hh" +#include "nix/store/realisation.hh" +#include "nix/util/processes.hh" +#include "nix/util/url.hh" #include namespace nix { diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 67d5a1dcb..949f0f74f 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -1,22 +1,22 @@ -#include "local-store.hh" -#include "globals.hh" -#include "git.hh" -#include "archive.hh" -#include "pathlocks.hh" -#include "worker-protocol.hh" -#include "derivations.hh" -#include "realisation.hh" -#include "nar-info.hh" -#include "references.hh" -#include "callback.hh" -#include "topo-sort.hh" -#include "finally.hh" -#include "compression.hh" -#include "signals.hh" -#include "posix-fs-canonicalise.hh" -#include "posix-source-accessor.hh" -#include "keys.hh" -#include "users.hh" +#include "nix/store/local-store.hh" +#include "nix/store/globals.hh" +#include "nix/util/git.hh" +#include "nix/util/archive.hh" +#include "nix/store/pathlocks.hh" +#include "nix/store/worker-protocol.hh" +#include "nix/store/derivations.hh" +#include "nix/store/realisation.hh" +#include "nix/store/nar-info.hh" +#include "nix/util/references.hh" +#include "nix/util/callback.hh" +#include "nix/util/topo-sort.hh" +#include "nix/util/finally.hh" +#include "nix/util/compression.hh" +#include "nix/util/signals.hh" +#include "nix/store/posix-fs-canonicalise.hh" +#include "nix/util/posix-source-accessor.hh" +#include "nix/store/keys.hh" +#include "nix/util/users.hh" #include #include @@ -38,7 +38,7 @@ # include #endif -#if __linux__ +#ifdef __linux__ # include # include # include @@ -52,7 +52,9 @@ #include -#include "strings.hh" +#include "nix/util/strings.hh" + +#include "store-config-private.hh" namespace nix { @@ -116,7 +118,7 @@ LocalStore::LocalStore( state->stmts = std::make_unique(); /* Create missing state directories if they don't already exist. */ - createDirs(realStoreDir); + createDirs(realStoreDir.get()); if (readOnly) { experimentalFeatureSettings.require(Xp::ReadOnlyLocalStore); } else { @@ -247,7 +249,7 @@ LocalStore::LocalStore( else if (curSchema == 0) { /* new store */ curSchema = nixSchemaVersion; openDB(*state, true); - writeFile(schemaPath, fmt("%1%", nixSchemaVersion), 0666, true); + writeFile(schemaPath, fmt("%1%", curSchema), 0666, true); } else if (curSchema < nixSchemaVersion) { @@ -573,7 +575,7 @@ void LocalStore::upgradeDBSchema(State & state) bind mount. So make the Nix store writable for this process. */ void LocalStore::makeStoreWritable() { -#if __linux__ +#ifdef __linux__ if (!isRootUser()) return; /* Check if /nix/store is on a read-only mount. */ struct statvfs stat; diff --git a/src/libstore/log-store.cc b/src/libstore/log-store.cc index 8a26832ab..2ef791e19 100644 --- a/src/libstore/log-store.cc +++ b/src/libstore/log-store.cc @@ -1,4 +1,4 @@ -#include "log-store.hh" +#include "nix/store/log-store.hh" namespace nix { diff --git a/src/libstore/machines.cc b/src/libstore/machines.cc index eb729b697..7c077239d 100644 --- a/src/libstore/machines.cc +++ b/src/libstore/machines.cc @@ -1,6 +1,6 @@ -#include "machines.hh" -#include "globals.hh" -#include "store-api.hh" +#include "nix/store/machines.hh" +#include "nix/store/globals.hh" +#include "nix/store/store-api.hh" #include diff --git a/src/libstore/make-content-addressed.cc b/src/libstore/make-content-addressed.cc index a3130d7cc..606d72866 100644 --- a/src/libstore/make-content-addressed.cc +++ b/src/libstore/make-content-addressed.cc @@ -1,5 +1,5 @@ -#include "make-content-addressed.hh" -#include "references.hh" +#include "nix/store/make-content-addressed.hh" +#include "nix/util/references.hh" namespace nix { diff --git a/src/libstore/meson.build b/src/libstore/meson.build index 063bc43a5..112a8ef7b 100644 --- a/src/libstore/meson.build +++ b/src/libstore/meson.build @@ -17,14 +17,22 @@ cxx = meson.get_compiler('cpp') subdir('nix-meson-build-support/deps-lists') -configdata = configuration_data() +configdata_pub = configuration_data() +configdata_priv = configuration_data() # TODO rename, because it will conflict with downstream projects -configdata.set_quoted('PACKAGE_VERSION', meson.project_version()) +configdata_priv.set_quoted('PACKAGE_VERSION', meson.project_version()) -configdata.set_quoted('DETERMINATE_NIX_VERSION', fs.read('../../.version-determinate').strip()) +configdata_priv.set_quoted('DETERMINATE_NIX_VERSION', fs.read('../../.version-determinate').strip()) -configdata.set_quoted('SYSTEM', host_machine.cpu_family() + '-' + host_machine.system()) +# Used in public header. +configdata_pub.set_quoted( + 'NIX_LOCAL_SYSTEM', + host_machine.cpu_family() + '-' + host_machine.system(), + description : + 'This is the system name Nix expects for local running instance of Nix.\n\n' + + 'See the "system" setting for additional details', +) deps_private_maybe_subproject = [ ] @@ -51,27 +59,30 @@ run_command('rm', '-f', check : true, ) summary('can hardlink to symlink', can_link_symlink, bool_yn : true) -configdata.set('CAN_LINK_SYMLINK', can_link_symlink.to_int()) +configdata_priv.set('CAN_LINK_SYMLINK', can_link_symlink.to_int()) # Check for each of these functions, and create a define like `#define HAVE_LCHOWN 1`. -# -# Only need to do functions that deps (like `libnixutil`) didn't already -# check for. check_funcs = [ # Optionally used for canonicalising files from the build 'lchown', + 'posix_fallocate', 'statvfs', ] foreach funcspec : check_funcs define_name = 'HAVE_' + funcspec.underscorify().to_upper() define_value = cxx.has_function(funcspec).to_int() - configdata.set(define_name, define_value) + configdata_priv.set(define_name, define_value) endforeach has_acl_support = cxx.has_header('sys/xattr.h') \ and cxx.has_function('llistxattr') \ and cxx.has_function('lremovexattr') -configdata.set('HAVE_ACL_SUPPORT', has_acl_support.to_int()) +# Used in public header. Affects ABI! +configdata_pub.set( + 'NIX_SUPPORT_ACL', + has_acl_support.to_int(), + description : 'FIXME: It\'s a bit peculiar that this needs to be exposed. The reason is that that it effects whether the settings struct in a header has a particular field. This is also odd, because it means when there is no ACL support one will just get an "unknown setting" warning from their configuration.', +) if host_machine.system() == 'darwin' sandbox = cxx.find_library('sandbox') @@ -107,7 +118,7 @@ seccomp = dependency('libseccomp', 'seccomp', required : seccomp_required, versi if is_linux and not seccomp.found() warning('Sandbox security is reduced because libseccomp has not been found! Please provide libseccomp if it supports your CPU architecture.') endif -configdata.set('HAVE_SECCOMP', seccomp.found().to_int()) +configdata_priv.set('HAVE_SECCOMP', seccomp.found().to_int()) deps_private += seccomp nlohmann_json = dependency('nlohmann_json', version : '>= 3.9') @@ -116,9 +127,11 @@ deps_public += nlohmann_json sqlite = dependency('sqlite3', 'sqlite', version : '>=3.6.19') deps_private += sqlite -# AWS C++ SDK has bad pkg-config +# AWS C++ SDK has bad pkg-config. See +# https://github.com/aws/aws-sdk-cpp/issues/2673 for details. aws_s3 = dependency('aws-cpp-sdk-s3', required : false) -configdata.set('ENABLE_S3', aws_s3.found().to_int()) +# The S3 store definitions in the header will be hidden based on this variables. +configdata_pub.set('NIX_WITH_S3_SUPPORT', aws_s3.found().to_int()) if aws_s3.found() aws_s3 = declare_dependency( include_directories: include_directories(aws_s3.get_variable('includedir')), @@ -145,12 +158,15 @@ endforeach busybox = find_program(get_option('sandbox-shell'), required : false) +configdata_priv.set('HAVE_EMBEDDED_SANDBOX_SHELL', get_option('embedded-sandbox-shell').to_int()) + +if get_option('embedded-sandbox-shell') + configdata_priv.set_quoted('SANDBOX_SHELL', '__embedded_sandbox_shell__') +elif busybox.found() + configdata_priv.set_quoted('SANDBOX_SHELL', busybox.full_path()) +endif + if get_option('embedded-sandbox-shell') - # This one goes in config.h - # The path to busybox is passed as a -D flag when compiling this_library. - # This solution is inherited from the old make buildsystem - # TODO: do this differently? - configdata.set('HAVE_EMBEDDED_SANDBOX_SHELL', 1) hexdump = find_program('hexdump', native : true) embedded_sandbox_shell_gen = custom_target( 'embedded-sandbox-shell.gen.hh', @@ -168,17 +184,67 @@ if get_option('embedded-sandbox-shell') generated_headers += embedded_sandbox_shell_gen endif -config_h = configure_file( - configuration : configdata, - output : 'config-store.hh', +prefix = get_option('prefix') +# For each of these paths, assume that it is relative to the prefix unless +# it is already an absolute path (which is the default for store-dir, localstatedir, and log-dir). +path_opts = [ + # Meson built-ins. + 'datadir', + 'mandir', + 'libdir', + 'includedir', + 'libexecdir', + # Homecooked Nix directories. + 'store-dir', + 'localstatedir', + 'log-dir', +] +# For your grepping pleasure, this loop sets the following variables that aren't mentioned +# literally above: +# store_dir +# localstatedir +# log_dir +# profile_dir +foreach optname : path_opts + varname = optname.replace('-', '_') + path = get_option(optname) + if fs.is_absolute(path) + set_variable(varname, path) + else + set_variable(varname, prefix / path) + endif +endforeach + +# sysconfdir doesn't get anything installed to directly, and is only used to +# tell Nix where to look for nix.conf, so it doesn't get appended to prefix. +sysconfdir = get_option('sysconfdir') +if not fs.is_absolute(sysconfdir) + sysconfdir = '/' / sysconfdir +endif + +# Aside from prefix itself, each of these was made into an absolute path +# by joining it with prefix, unless it was already an absolute path +# (which is the default for store-dir, localstatedir, and log-dir). +configdata_priv.set_quoted('NIX_PREFIX', prefix) +configdata_priv.set_quoted('NIX_STORE_DIR', store_dir) +configdata_priv.set_quoted('NIX_DATA_DIR', datadir) +configdata_priv.set_quoted('NIX_STATE_DIR', localstatedir / 'nix') +configdata_priv.set_quoted('NIX_LOG_DIR', log_dir) +configdata_priv.set_quoted('NIX_CONF_DIR', sysconfdir / 'nix') +configdata_priv.set_quoted('NIX_MAN_DIR', mandir) + +lsof = find_program('lsof', required : false) +configdata_priv.set_quoted( + 'LSOF', + lsof.found() + ? lsof.full_path() + # Just look up on the PATH + : 'lsof', ) -add_project_arguments( - # TODO(Qyriad): Yes this is how the autoconf+Make system did it. - # It would be nice for our headers to be idempotent instead. - '-include', 'config-util.hh', - '-include', 'config-store.hh', - language : 'cpp', +config_priv_h = configure_file( + configuration : configdata_priv, + output : 'store-config-private.hh', ) subdir('nix-meson-build-support/common') @@ -251,81 +317,7 @@ sources = files( 'worker-protocol.cc', ) -include_dirs = [ - include_directories('.'), - include_directories('build'), -] - -headers = [config_h] + files( - 'binary-cache-store.hh', - 'build-result.hh', - 'build/derivation-goal.hh', - 'build/drv-output-substitution-goal.hh', - 'build/goal.hh', - 'build/substitution-goal.hh', - 'build/worker.hh', - 'builtins.hh', - 'builtins/buildenv.hh', - 'common-protocol-impl.hh', - 'common-protocol.hh', - 'common-ssh-store-config.hh', - 'content-address.hh', - 'daemon.hh', - 'derivations.hh', - 'derivation-options.hh', - 'derived-path-map.hh', - 'derived-path.hh', - 'downstream-placeholder.hh', - 'filetransfer.hh', - 'gc-store.hh', - 'globals.hh', - 'http-binary-cache-store.hh', - 'indirect-root-store.hh', - 'keys.hh', - 'legacy-ssh-store.hh', - 'length-prefixed-protocol-helper.hh', - 'local-binary-cache-store.hh', - 'local-fs-store.hh', - 'local-overlay-store.hh', - 'local-store.hh', - 'log-store.hh', - 'machines.hh', - 'make-content-addressed.hh', - 'names.hh', - 'nar-accessor.hh', - 'nar-info-disk-cache.hh', - 'nar-info.hh', - 'outputs-spec.hh', - 'parsed-derivations.hh', - 'path-info.hh', - 'path-references.hh', - 'path-regex.hh', - 'path-with-outputs.hh', - 'path.hh', - 'pathlocks.hh', - 'posix-fs-canonicalise.hh', - 'profiles.hh', - 'realisation.hh', - 'remote-fs-accessor.hh', - 'remote-store-connection.hh', - 'remote-store.hh', - 's3-binary-cache-store.hh', - 's3.hh', - 'ssh-store.hh', - 'serve-protocol-connection.hh', - 'serve-protocol-impl.hh', - 'serve-protocol.hh', - 'sqlite.hh', - 'ssh.hh', - 'store-api.hh', - 'store-cast.hh', - 'store-dir-config.hh', - 'store-reference.hh', - 'uds-remote-store.hh', - 'worker-protocol-connection.hh', - 'worker-protocol-impl.hh', - 'worker-protocol.hh', -) +subdir('include/nix/store') if host_machine.system() == 'linux' subdir('linux') @@ -337,87 +329,6 @@ else subdir('unix') endif -prefix = get_option('prefix') -# For each of these paths, assume that it is relative to the prefix unless -# it is already an absolute path (which is the default for store-dir, localstatedir, and log-dir). -path_opts = [ - # Meson built-ins. - 'datadir', - 'mandir', - 'libdir', - 'includedir', - 'libexecdir', - # Homecooked Nix directories. - 'store-dir', - 'localstatedir', - 'log-dir', -] -# For your grepping pleasure, this loop sets the following variables that aren't mentioned -# literally above: -# store_dir -# localstatedir -# log_dir -# profile_dir -foreach optname : path_opts - varname = optname.replace('-', '_') - path = get_option(optname) - if fs.is_absolute(path) - set_variable(varname, path) - else - set_variable(varname, prefix / path) - endif -endforeach - -# sysconfdir doesn't get anything installed to directly, and is only used to -# tell Nix where to look for nix.conf, so it doesn't get appended to prefix. -sysconfdir = get_option('sysconfdir') -if not fs.is_absolute(sysconfdir) - sysconfdir = '/' / sysconfdir -endif - -lsof = find_program('lsof', required : false) - -# Aside from prefix itself, each of these was made into an absolute path -# by joining it with prefix, unless it was already an absolute path -# (which is the default for store-dir, localstatedir, and log-dir). -cpp_str_defines = { - 'NIX_PREFIX': prefix, - 'NIX_STORE_DIR': store_dir, - 'NIX_DATA_DIR': datadir, - 'NIX_STATE_DIR': localstatedir / 'nix', - 'NIX_LOG_DIR': log_dir, - 'NIX_CONF_DIR': sysconfdir / 'nix', - 'NIX_MAN_DIR': mandir, -} - -if lsof.found() - lsof_path = lsof.full_path() -else - # Just look up on the PATH - lsof_path = 'lsof' -endif -cpp_str_defines += { - 'LSOF': lsof_path -} - -if get_option('embedded-sandbox-shell') - cpp_str_defines += { - 'SANDBOX_SHELL': '__embedded_sandbox_shell__' - } -elif busybox.found() - cpp_str_defines += { - 'SANDBOX_SHELL': busybox.full_path() - } -endif - -cpp_args = [] - -foreach name, value : cpp_str_defines - cpp_args += [ - '-D' + name + '=' + '"' + value + '"' - ] -endforeach - subdir('nix-meson-build-support/export-all-symbols') subdir('nix-meson-build-support/windows-version') @@ -425,15 +336,15 @@ this_library = library( 'nixstore', generated_headers, sources, + config_priv_h, dependencies : deps_public + deps_private + deps_other, include_directories : include_dirs, - cpp_args : cpp_args, link_args: linker_export_flags, prelink : true, # For C++ static initializers install : true, ) -install_headers(headers, subdir : 'nix', preserve_path : true) +install_headers(headers, subdir : 'nix/store', preserve_path : true) libraries_private = [] diff --git a/src/libstore/misc.cc b/src/libstore/misc.cc index 9d3b24326..0e2b62db5 100644 --- a/src/libstore/misc.cc +++ b/src/libstore/misc.cc @@ -1,17 +1,17 @@ #include -#include "derivations.hh" -#include "parsed-derivations.hh" -#include "derivation-options.hh" -#include "globals.hh" -#include "store-api.hh" -#include "thread-pool.hh" -#include "realisation.hh" -#include "topo-sort.hh" -#include "callback.hh" -#include "closure.hh" -#include "filetransfer.hh" -#include "strings.hh" +#include "nix/store/derivations.hh" +#include "nix/store/parsed-derivations.hh" +#include "nix/store/derivation-options.hh" +#include "nix/store/globals.hh" +#include "nix/store/store-api.hh" +#include "nix/util/thread-pool.hh" +#include "nix/store/realisation.hh" +#include "nix/util/topo-sort.hh" +#include "nix/util/callback.hh" +#include "nix/util/closure.hh" +#include "nix/store/filetransfer.hh" +#include "nix/util/strings.hh" namespace nix { diff --git a/src/libstore/names.cc b/src/libstore/names.cc index c0e1b1022..998b9356a 100644 --- a/src/libstore/names.cc +++ b/src/libstore/names.cc @@ -1,5 +1,5 @@ -#include "names.hh" -#include "util.hh" +#include "nix/store/names.hh" +#include "nix/util/util.hh" #include diff --git a/src/libstore/nar-accessor.cc b/src/libstore/nar-accessor.cc index c4e0b137b..6aba68a36 100644 --- a/src/libstore/nar-accessor.cc +++ b/src/libstore/nar-accessor.cc @@ -1,5 +1,5 @@ -#include "nar-accessor.hh" -#include "archive.hh" +#include "nix/store/nar-accessor.hh" +#include "nix/util/archive.hh" #include #include diff --git a/src/libstore/nar-info-disk-cache.cc b/src/libstore/nar-info-disk-cache.cc index 80e8d3414..5d72ba8ae 100644 --- a/src/libstore/nar-info-disk-cache.cc +++ b/src/libstore/nar-info-disk-cache.cc @@ -1,13 +1,13 @@ -#include "nar-info-disk-cache.hh" -#include "users.hh" -#include "sync.hh" -#include "sqlite.hh" -#include "globals.hh" +#include "nix/store/nar-info-disk-cache.hh" +#include "nix/util/users.hh" +#include "nix/util/sync.hh" +#include "nix/store/sqlite.hh" +#include "nix/store/globals.hh" #include #include -#include "strings.hh" +#include "nix/util/strings.hh" namespace nix { diff --git a/src/libstore/nar-info.cc b/src/libstore/nar-info.cc index 27fcc2864..ba80652d0 100644 --- a/src/libstore/nar-info.cc +++ b/src/libstore/nar-info.cc @@ -1,8 +1,8 @@ -#include "globals.hh" -#include "nar-info.hh" -#include "store-api.hh" -#include "strings.hh" -#include "json-utils.hh" +#include "nix/store/globals.hh" +#include "nix/store/nar-info.hh" +#include "nix/store/store-api.hh" +#include "nix/util/strings.hh" +#include "nix/util/json-utils.hh" namespace nix { diff --git a/src/libstore/optimise-store.cc b/src/libstore/optimise-store.cc index aeff24c64..277795053 100644 --- a/src/libstore/optimise-store.cc +++ b/src/libstore/optimise-store.cc @@ -1,8 +1,8 @@ -#include "local-store.hh" -#include "globals.hh" -#include "signals.hh" -#include "posix-fs-canonicalise.hh" -#include "posix-source-accessor.hh" +#include "nix/store/local-store.hh" +#include "nix/store/globals.hh" +#include "nix/util/signals.hh" +#include "nix/store/posix-fs-canonicalise.hh" +#include "nix/util/posix-source-accessor.hh" #include #include @@ -13,6 +13,7 @@ #include #include +#include "store-config-private.hh" namespace nix { @@ -96,7 +97,7 @@ void LocalStore::optimisePath_(Activity * act, OptimiseStats & stats, auto st = lstat(path); -#if __APPLE__ +#ifdef __APPLE__ /* HFS/macOS has some undocumented security feature disabling hardlinking for special files within .app dirs. Known affected paths include *.app/Contents/{PkgInfo,Resources/\*.lproj,_CodeSignature} and .DS_Store. diff --git a/src/libstore/outputs-spec.cc b/src/libstore/outputs-spec.cc index b623a975c..28fe45de9 100644 --- a/src/libstore/outputs-spec.cc +++ b/src/libstore/outputs-spec.cc @@ -1,11 +1,11 @@ #include #include -#include "util.hh" -#include "regex-combinators.hh" -#include "outputs-spec.hh" -#include "path-regex.hh" -#include "strings-inline.hh" +#include "nix/util/util.hh" +#include "nix/util/regex-combinators.hh" +#include "nix/store/outputs-spec.hh" +#include "nix/store/path-regex.hh" +#include "nix/util/strings-inline.hh" namespace nix { diff --git a/src/libstore/package.nix b/src/libstore/package.nix index 847e61d09..20478d9d3 100644 --- a/src/libstore/package.nix +++ b/src/libstore/package.nix @@ -21,6 +21,10 @@ version, embeddedSandboxShell ? stdenv.hostPlatform.isStatic, + + withAWS ? + # Default is this way because there have been issues building this dependency + stdenv.hostPlatform == stdenv.buildPlatform && (stdenv.isLinux || stdenv.isDarwin), }: let @@ -41,8 +45,11 @@ mkMesonLibrary (finalAttrs: { ../../.version-determinate ./meson.build ./meson.options + ./include/nix/store/meson.build ./linux/meson.build + ./linux/include/nix/store/meson.build ./unix/meson.build + ./unix/include/nix/store/meson.build ./windows/meson.build (fileset.fileFilter (file: file.hasExt "cc") ./.) (fileset.fileFilter (file: file.hasExt "hh") ./.) @@ -62,9 +69,7 @@ mkMesonLibrary (finalAttrs: { ++ lib.optional stdenv.hostPlatform.isLinux libseccomp # There have been issues building these dependencies ++ lib.optional stdenv.hostPlatform.isDarwin darwin.apple_sdk.libs.sandbox - ++ lib.optional ( - stdenv.hostPlatform == stdenv.buildPlatform && (stdenv.isLinux || stdenv.isDarwin) - ) aws-sdk-cpp; + ++ lib.optional withAWS aws-sdk-cpp; propagatedBuildInputs = [ nix-util @@ -80,13 +85,6 @@ mkMesonLibrary (finalAttrs: { (lib.mesonOption "sandbox-shell" "${busybox-sandbox-shell}/bin/busybox") ]; - env = { - # Needed for Meson to find Boost. - # https://github.com/NixOS/nixpkgs/issues/86131. - BOOST_INCLUDEDIR = "${lib.getDev boost}/include"; - BOOST_LIBRARYDIR = "${lib.getLib boost}/lib"; - }; - meta = { platforms = lib.platforms.unix ++ lib.platforms.windows; }; diff --git a/src/libstore/parsed-derivations.cc b/src/libstore/parsed-derivations.cc index b26c36efe..cc7203c6b 100644 --- a/src/libstore/parsed-derivations.cc +++ b/src/libstore/parsed-derivations.cc @@ -1,4 +1,4 @@ -#include "parsed-derivations.hh" +#include "nix/store/parsed-derivations.hh" #include #include diff --git a/src/libstore/path-info.cc b/src/libstore/path-info.cc index 6e87e60f4..df20edb3b 100644 --- a/src/libstore/path-info.cc +++ b/src/libstore/path-info.cc @@ -1,10 +1,10 @@ #include -#include "path-info.hh" -#include "store-api.hh" -#include "json-utils.hh" -#include "comparator.hh" -#include "strings.hh" +#include "nix/store/path-info.hh" +#include "nix/store/store-api.hh" +#include "nix/util/json-utils.hh" +#include "nix/util/comparator.hh" +#include "nix/util/strings.hh" namespace nix { diff --git a/src/libstore/path-references.cc b/src/libstore/path-references.cc index 15f52ec9d..c06647eb1 100644 --- a/src/libstore/path-references.cc +++ b/src/libstore/path-references.cc @@ -1,6 +1,6 @@ -#include "path-references.hh" -#include "hash.hh" -#include "archive.hh" +#include "nix/store/path-references.hh" +#include "nix/util/hash.hh" +#include "nix/util/archive.hh" #include #include diff --git a/src/libstore/path-with-outputs.cc b/src/libstore/path-with-outputs.cc index e526b1ff6..9fbbc8f46 100644 --- a/src/libstore/path-with-outputs.cc +++ b/src/libstore/path-with-outputs.cc @@ -1,8 +1,8 @@ #include -#include "path-with-outputs.hh" -#include "store-api.hh" -#include "strings.hh" +#include "nix/store/path-with-outputs.hh" +#include "nix/store/store-api.hh" +#include "nix/util/strings.hh" namespace nix { diff --git a/src/libstore/path.cc b/src/libstore/path.cc index 3e9d05477..5dd1a1699 100644 --- a/src/libstore/path.cc +++ b/src/libstore/path.cc @@ -1,4 +1,4 @@ -#include "store-dir-config.hh" +#include "nix/store/store-dir-config.hh" namespace nix { diff --git a/src/libstore/pathlocks.cc b/src/libstore/pathlocks.cc index c855e797f..34acfb02d 100644 --- a/src/libstore/pathlocks.cc +++ b/src/libstore/pathlocks.cc @@ -1,7 +1,7 @@ -#include "pathlocks.hh" -#include "util.hh" -#include "sync.hh" -#include "signals.hh" +#include "nix/store/pathlocks.hh" +#include "nix/util/util.hh" +#include "nix/util/sync.hh" +#include "nix/util/signals.hh" #include #include diff --git a/src/libstore/posix-fs-canonicalise.cc b/src/libstore/posix-fs-canonicalise.cc index 46a78cc86..aeb35eab5 100644 --- a/src/libstore/posix-fs-canonicalise.cc +++ b/src/libstore/posix-fs-canonicalise.cc @@ -1,14 +1,16 @@ -#if HAVE_ACL_SUPPORT +#include "nix/store/posix-fs-canonicalise.hh" +#include "nix/util/file-system.hh" +#include "nix/util/signals.hh" +#include "nix/util/util.hh" +#include "nix/store/globals.hh" +#include "nix/store/store-api.hh" + +#include "store-config-private.hh" + +#if NIX_SUPPORT_ACL # include #endif -#include "posix-fs-canonicalise.hh" -#include "file-system.hh" -#include "signals.hh" -#include "util.hh" -#include "globals.hh" -#include "store-api.hh" - namespace nix { const time_t mtimeStore = 1; /* 1 second into the epoch */ @@ -56,7 +58,7 @@ static void canonicalisePathMetaData_( { checkInterrupt(); -#if __APPLE__ +#ifdef __APPLE__ /* Remove flags, in particular UF_IMMUTABLE which would prevent the file from being garbage-collected. FIXME: Use setattrlist() to remove other attributes as well. */ @@ -72,7 +74,7 @@ static void canonicalisePathMetaData_( if (!(S_ISREG(st.st_mode) || S_ISDIR(st.st_mode) || S_ISLNK(st.st_mode))) throw Error("file '%1%' has an unsupported type", path); -#if HAVE_ACL_SUPPORT +#if NIX_SUPPORT_ACL /* Remove extended attributes / ACLs. */ ssize_t eaSize = llistxattr(path.c_str(), nullptr, 0); diff --git a/src/libstore/profiles.cc b/src/libstore/profiles.cc index 46efedfe3..bd24332cb 100644 --- a/src/libstore/profiles.cc +++ b/src/libstore/profiles.cc @@ -1,8 +1,8 @@ -#include "profiles.hh" -#include "signals.hh" -#include "store-api.hh" -#include "local-fs-store.hh" -#include "users.hh" +#include "nix/store/profiles.hh" +#include "nix/util/signals.hh" +#include "nix/store/store-api.hh" +#include "nix/store/local-fs-store.hh" +#include "nix/util/users.hh" #include #include diff --git a/src/libstore/realisation.cc b/src/libstore/realisation.cc index 86bfdd1a8..635fb6946 100644 --- a/src/libstore/realisation.cc +++ b/src/libstore/realisation.cc @@ -1,7 +1,7 @@ -#include "realisation.hh" -#include "store-api.hh" -#include "closure.hh" -#include "signature/local-keys.hh" +#include "nix/store/realisation.hh" +#include "nix/store/store-api.hh" +#include "nix/util/closure.hh" +#include "nix/util/signature/local-keys.hh" #include namespace nix { diff --git a/src/libstore/remote-fs-accessor.cc b/src/libstore/remote-fs-accessor.cc index 7e360b5fe..340e7ee2e 100644 --- a/src/libstore/remote-fs-accessor.cc +++ b/src/libstore/remote-fs-accessor.cc @@ -1,6 +1,6 @@ #include -#include "remote-fs-accessor.hh" -#include "nar-accessor.hh" +#include "nix/store/remote-fs-accessor.hh" +#include "nix/store/nar-accessor.hh" #include #include diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index 533ea557d..0533b7c8a 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -1,23 +1,23 @@ -#include "serialise.hh" -#include "util.hh" -#include "path-with-outputs.hh" -#include "gc-store.hh" -#include "remote-fs-accessor.hh" -#include "build-result.hh" -#include "remote-store.hh" -#include "remote-store-connection.hh" -#include "worker-protocol.hh" -#include "worker-protocol-impl.hh" -#include "archive.hh" -#include "globals.hh" -#include "derivations.hh" -#include "pool.hh" -#include "finally.hh" -#include "git.hh" -#include "logging.hh" -#include "callback.hh" -#include "filetransfer.hh" -#include "signals.hh" +#include "nix/util/serialise.hh" +#include "nix/util/util.hh" +#include "nix/store/path-with-outputs.hh" +#include "nix/store/gc-store.hh" +#include "nix/store/remote-fs-accessor.hh" +#include "nix/store/build-result.hh" +#include "nix/store/remote-store.hh" +#include "nix/store/remote-store-connection.hh" +#include "nix/store/worker-protocol.hh" +#include "nix/store/worker-protocol-impl.hh" +#include "nix/util/archive.hh" +#include "nix/store/globals.hh" +#include "nix/store/derivations.hh" +#include "nix/util/pool.hh" +#include "nix/util/finally.hh" +#include "nix/util/git.hh" +#include "nix/util/logging.hh" +#include "nix/util/callback.hh" +#include "nix/store/filetransfer.hh" +#include "nix/util/signals.hh" #include diff --git a/src/libstore/s3-binary-cache-store.cc b/src/libstore/s3-binary-cache-store.cc index cfa713b00..87f5feb45 100644 --- a/src/libstore/s3-binary-cache-store.cc +++ b/src/libstore/s3-binary-cache-store.cc @@ -1,15 +1,16 @@ -#if ENABLE_S3 +#include "nix/store/s3-binary-cache-store.hh" + +#if NIX_WITH_S3_SUPPORT #include -#include "s3.hh" -#include "s3-binary-cache-store.hh" -#include "nar-info.hh" -#include "nar-info-disk-cache.hh" -#include "globals.hh" -#include "compression.hh" -#include "filetransfer.hh" -#include "signals.hh" +#include "nix/store/s3.hh" +#include "nix/store/nar-info.hh" +#include "nix/store/nar-info-disk-cache.hh" +#include "nix/store/globals.hh" +#include "nix/util/compression.hh" +#include "nix/store/filetransfer.hh" +#include "nix/util/signals.hh" #include #include diff --git a/src/libstore/serve-protocol-connection.cc b/src/libstore/serve-protocol-connection.cc index 07379999b..276086f6f 100644 --- a/src/libstore/serve-protocol-connection.cc +++ b/src/libstore/serve-protocol-connection.cc @@ -1,7 +1,7 @@ -#include "serve-protocol-connection.hh" -#include "serve-protocol-impl.hh" -#include "build-result.hh" -#include "derivations.hh" +#include "nix/store/serve-protocol-connection.hh" +#include "nix/store/serve-protocol-impl.hh" +#include "nix/store/build-result.hh" +#include "nix/store/derivations.hh" namespace nix { diff --git a/src/libstore/serve-protocol.cc b/src/libstore/serve-protocol.cc index 08bfad9e4..520c37951 100644 --- a/src/libstore/serve-protocol.cc +++ b/src/libstore/serve-protocol.cc @@ -1,11 +1,11 @@ -#include "serialise.hh" -#include "path-with-outputs.hh" -#include "store-api.hh" -#include "build-result.hh" -#include "serve-protocol.hh" -#include "serve-protocol-impl.hh" -#include "archive.hh" -#include "path-info.hh" +#include "nix/util/serialise.hh" +#include "nix/store/path-with-outputs.hh" +#include "nix/store/store-api.hh" +#include "nix/store/build-result.hh" +#include "nix/store/serve-protocol.hh" +#include "nix/store/serve-protocol-impl.hh" +#include "nix/util/archive.hh" +#include "nix/store/path-info.hh" #include diff --git a/src/libstore/sqlite.cc b/src/libstore/sqlite.cc index f02e472fd..55b967ed6 100644 --- a/src/libstore/sqlite.cc +++ b/src/libstore/sqlite.cc @@ -1,8 +1,8 @@ -#include "sqlite.hh" -#include "globals.hh" -#include "util.hh" -#include "url.hh" -#include "signals.hh" +#include "nix/store/sqlite.hh" +#include "nix/store/globals.hh" +#include "nix/util/util.hh" +#include "nix/util/url.hh" +#include "nix/util/signals.hh" #include diff --git a/src/libstore/ssh-store.cc b/src/libstore/ssh-store.cc index 954a97467..45ea05ffc 100644 --- a/src/libstore/ssh-store.cc +++ b/src/libstore/ssh-store.cc @@ -1,12 +1,12 @@ -#include "ssh-store.hh" -#include "local-fs-store.hh" -#include "remote-store-connection.hh" -#include "source-accessor.hh" -#include "archive.hh" -#include "worker-protocol.hh" -#include "worker-protocol-impl.hh" -#include "pool.hh" -#include "ssh.hh" +#include "nix/store/ssh-store.hh" +#include "nix/store/local-fs-store.hh" +#include "nix/store/remote-store-connection.hh" +#include "nix/util/source-accessor.hh" +#include "nix/util/archive.hh" +#include "nix/store/worker-protocol.hh" +#include "nix/store/worker-protocol-impl.hh" +#include "nix/util/pool.hh" +#include "nix/store/ssh.hh" namespace nix { diff --git a/src/libstore/ssh.cc b/src/libstore/ssh.cc index 70e6d5dfe..97b75cba1 100644 --- a/src/libstore/ssh.cc +++ b/src/libstore/ssh.cc @@ -1,9 +1,9 @@ -#include "ssh.hh" -#include "finally.hh" -#include "current-process.hh" -#include "environment-variables.hh" -#include "util.hh" -#include "exec.hh" +#include "nix/store/ssh.hh" +#include "nix/util/finally.hh" +#include "nix/util/current-process.hh" +#include "nix/util/environment-variables.hh" +#include "nix/util/util.hh" +#include "nix/util/exec.hh" namespace nix { diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index fc3fbcc0f..d3bccd7af 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -1,28 +1,28 @@ -#include "signature/local-keys.hh" -#include "source-accessor.hh" -#include "globals.hh" -#include "derived-path.hh" -#include "realisation.hh" -#include "derivations.hh" -#include "store-api.hh" -#include "util.hh" -#include "nar-info-disk-cache.hh" -#include "thread-pool.hh" -#include "references.hh" -#include "archive.hh" -#include "callback.hh" -#include "git.hh" -#include "posix-source-accessor.hh" +#include "nix/util/signature/local-keys.hh" +#include "nix/util/source-accessor.hh" +#include "nix/store/globals.hh" +#include "nix/store/derived-path.hh" +#include "nix/store/realisation.hh" +#include "nix/store/derivations.hh" +#include "nix/store/store-api.hh" +#include "nix/util/util.hh" +#include "nix/store/nar-info-disk-cache.hh" +#include "nix/util/thread-pool.hh" +#include "nix/util/references.hh" +#include "nix/util/archive.hh" +#include "nix/util/callback.hh" +#include "nix/util/git.hh" +#include "nix/util/posix-source-accessor.hh" // FIXME this should not be here, see TODO below on // `addMultipleToStore`. -#include "worker-protocol.hh" -#include "signals.hh" -#include "users.hh" +#include "nix/store/worker-protocol.hh" +#include "nix/util/signals.hh" +#include "nix/util/users.hh" #include #include -#include "strings.hh" +#include "nix/util/strings.hh" using json = nlohmann::json; @@ -1277,8 +1277,8 @@ Derivation Store::readInvalidDerivation(const StorePath & drvPath) } -#include "local-store.hh" -#include "uds-remote-store.hh" +#include "nix/store/local-store.hh" +#include "nix/store/uds-remote-store.hh" namespace nix { @@ -1300,7 +1300,7 @@ ref openStore(StoreReference && storeURI) return std::make_shared(params); else if (pathExists(settings.nixDaemonSocketFile)) return std::make_shared(params); - #if __linux__ + #ifdef __linux__ else if (!pathExists(stateDir) && params.empty() && !isRootUser() diff --git a/src/libstore/store-reference.cc b/src/libstore/store-reference.cc index b4968dfad..cb4e2cfb8 100644 --- a/src/libstore/store-reference.cc +++ b/src/libstore/store-reference.cc @@ -1,10 +1,10 @@ #include -#include "error.hh" -#include "url.hh" -#include "store-reference.hh" -#include "file-system.hh" -#include "util.hh" +#include "nix/util/error.hh" +#include "nix/util/url.hh" +#include "nix/store/store-reference.hh" +#include "nix/util/file-system.hh" +#include "nix/util/util.hh" namespace nix { diff --git a/src/libstore/uds-remote-store.cc b/src/libstore/uds-remote-store.cc index 93c48c0e6..b58dd4783 100644 --- a/src/libstore/uds-remote-store.cc +++ b/src/libstore/uds-remote-store.cc @@ -1,6 +1,6 @@ -#include "uds-remote-store.hh" -#include "unix-domain-socket.hh" -#include "worker-protocol.hh" +#include "nix/store/uds-remote-store.hh" +#include "nix/util/unix-domain-socket.hh" +#include "nix/store/worker-protocol.hh" #include #include diff --git a/src/libstore/unix/build/child.cc b/src/libstore/unix/build/child.cc index aa31c3caf..a21fddf51 100644 --- a/src/libstore/unix/build/child.cc +++ b/src/libstore/unix/build/child.cc @@ -1,6 +1,6 @@ -#include "child.hh" -#include "current-process.hh" -#include "logging.hh" +#include "nix/store/build/child.hh" +#include "nix/util/current-process.hh" +#include "nix/util/logging.hh" #include #include diff --git a/src/libstore/unix/build/hook-instance.cc b/src/libstore/unix/build/hook-instance.cc index 79eb25a91..3713f7c86 100644 --- a/src/libstore/unix/build/hook-instance.cc +++ b/src/libstore/unix/build/hook-instance.cc @@ -1,10 +1,10 @@ -#include "globals.hh" -#include "config-global.hh" -#include "hook-instance.hh" -#include "file-system.hh" -#include "child.hh" -#include "strings.hh" -#include "executable-path.hh" +#include "nix/store/globals.hh" +#include "nix/util/config-global.hh" +#include "nix/store/build/hook-instance.hh" +#include "nix/util/file-system.hh" +#include "nix/store/build/child.hh" +#include "nix/util/strings.hh" +#include "nix/util/executable-path.hh" namespace nix { diff --git a/src/libstore/unix/build/local-derivation-goal.cc b/src/libstore/unix/build/local-derivation-goal.cc index 4cd79f897..ce0664b1c 100644 --- a/src/libstore/unix/build/local-derivation-goal.cc +++ b/src/libstore/unix/build/local-derivation-goal.cc @@ -1,24 +1,27 @@ -#include "local-derivation-goal.hh" -#include "indirect-root-store.hh" -#include "hook-instance.hh" -#include "worker.hh" -#include "builtins.hh" -#include "builtins/buildenv.hh" -#include "path-references.hh" -#include "finally.hh" -#include "util.hh" -#include "archive.hh" -#include "git.hh" -#include "compression.hh" -#include "daemon.hh" -#include "topo-sort.hh" -#include "callback.hh" -#include "json-utils.hh" -#include "current-process.hh" -#include "child.hh" -#include "unix-domain-socket.hh" -#include "posix-fs-canonicalise.hh" -#include "posix-source-accessor.hh" +#include "nix/store/build/local-derivation-goal.hh" +#include "nix/store/local-store.hh" +#include "nix/util/processes.hh" +#include "nix/store/indirect-root-store.hh" +#include "nix/store/build/hook-instance.hh" +#include "nix/store/build/worker.hh" +#include "nix/store/builtins.hh" +#include "nix/store/builtins/buildenv.hh" +#include "nix/store/path-references.hh" +#include "nix/util/finally.hh" +#include "nix/util/util.hh" +#include "nix/util/archive.hh" +#include "nix/util/git.hh" +#include "nix/util/compression.hh" +#include "nix/store/daemon.hh" +#include "nix/util/topo-sort.hh" +#include "nix/util/callback.hh" +#include "nix/util/json-utils.hh" +#include "nix/util/current-process.hh" +#include "nix/store/build/child.hh" +#include "nix/util/unix-domain-socket.hh" +#include "nix/store/posix-fs-canonicalise.hh" +#include "nix/util/posix-source-accessor.hh" +#include "nix/store/config.hh" #include #include @@ -31,13 +34,15 @@ #include #include +#include "store-config-private.hh" + #if HAVE_STATVFS #include #endif /* Includes required for chroot support. */ -#if __linux__ -# include "fchmodat2-compat.hh" +#ifdef __linux__ +# include "nix/store/fchmodat2-compat.hh" # include # include # include @@ -46,16 +51,16 @@ # include # include # include -# include "namespaces.hh" +# include "nix/util/namespaces.hh" # if HAVE_SECCOMP # include # endif # define pivot_root(new_root, put_old) (syscall(SYS_pivot_root, new_root, put_old)) -# include "cgroup.hh" -# include "personality.hh" +# include "nix/util/cgroup.hh" +# include "nix/store/personality.hh" #endif -#if __APPLE__ +#ifdef __APPLE__ #include #include #include @@ -68,8 +73,10 @@ extern "C" int sandbox_init_with_parameters(const char *profile, uint64_t flags, #include #include -#include "strings.hh" -#include "signals.hh" +#include "nix/util/strings.hh" +#include "nix/util/signals.hh" + +#include "store-config-private.hh" namespace nix { @@ -122,7 +129,7 @@ LocalDerivationGoal::~LocalDerivationGoal() inline bool LocalDerivationGoal::needsHashRewrite() { -#if __linux__ +#ifdef __linux__ return !useChroot; #else /* Darwin requires hash rewriting even when sandboxing is enabled. */ @@ -163,7 +170,7 @@ void LocalDerivationGoal::killChild() void LocalDerivationGoal::killSandbox(bool getStats) { if (cgroup) { - #if __linux__ + #ifdef __linux__ auto stats = destroyCgroup(*cgroup); if (getStats) { buildResult.cpuUser = stats.cpuUser; @@ -200,7 +207,7 @@ Goal::Co LocalDerivationGoal::tryLocalBuild() if (drvOptions->noChroot) throw Error("derivation '%s' has '__noChroot' set, " "but that's not allowed when 'sandbox' is 'true'", worker.store.printStorePath(drvPath)); -#if __APPLE__ +#ifdef __APPLE__ if (drvOptions->additionalSandboxProfile != "") throw Error("derivation '%s' specifies a sandbox profile, " "but this is only allowed when 'sandbox' is 'relaxed'", worker.store.printStorePath(drvPath)); @@ -215,14 +222,14 @@ Goal::Co LocalDerivationGoal::tryLocalBuild() auto & localStore = getLocalStore(); if (localStore.storeDir != localStore.realStoreDir.get()) { - #if __linux__ + #ifdef __linux__ useChroot = true; #else throw Error("building using a diverted store is not supported on this platform"); #endif } - #if __linux__ + #ifdef __linux__ if (useChroot) { if (!mountAndPidNamespacesSupported()) { if (!settings.sandboxFallback) @@ -398,7 +405,7 @@ void LocalDerivationGoal::cleanupPostOutputsRegisteredModeNonCheck() cleanupPostOutputsRegisteredModeCheck(); } -#if __linux__ +#ifdef __linux__ static void doBind(const Path & source, const Path & target, bool optional = false) { debug("bind mounting '%1%' to '%2%'", source, target); @@ -471,12 +478,12 @@ static void handleChildException(bool sendException) void LocalDerivationGoal::startBuilder() { if ((buildUser && buildUser->getUIDCount() != 1) - #if __linux__ + #ifdef __linux__ || settings.useCgroups #endif ) { - #if __linux__ + #ifdef __linux__ experimentalFeatureSettings.require(Xp::Cgroups); /* If we're running from the daemon, then this will return the @@ -543,7 +550,7 @@ void LocalDerivationGoal::startBuilder() /* Create a temporary directory where the build will take place. */ topTmpDir = createTempDir(settings.buildDir.get().value_or(""), "nix-build-" + std::string(drvPath.name()), false, false, 0700); -#if __APPLE__ +#ifdef __APPLE__ if (false) { #else if (useChroot) { @@ -722,7 +729,7 @@ void LocalDerivationGoal::startBuilder() pathsInChroot[i] = {i, true}; } -#if __linux__ +#ifdef __linux__ /* Create a temporary directory in which we set up the chroot environment using bind-mounts. We put it in the Nix store so that the build outputs can be moved efficiently from the @@ -821,7 +828,7 @@ void LocalDerivationGoal::startBuilder() #else if (drvOptions->useUidRange(*drv)) throw Error("feature 'uid-range' is not supported on this platform"); - #if __APPLE__ + #ifdef __APPLE__ /* We don't really have any parent prep work to do (yet?) All work happens in the child, instead. */ #else @@ -901,7 +908,7 @@ void LocalDerivationGoal::startBuilder() if (chown(slaveName.c_str(), buildUser->getUID(), 0)) throw SysError("changing owner of pseudoterminal slave"); } -#if __APPLE__ +#ifdef __APPLE__ else { if (grantpt(builderOut.get())) throw SysError("granting access to pseudoterminal slave"); @@ -936,7 +943,7 @@ void LocalDerivationGoal::startBuilder() /* Fork a child to build the package. */ -#if __linux__ +#ifdef __linux__ if (useChroot) { /* Set up private namespaces for the build: @@ -1136,7 +1143,7 @@ void LocalDerivationGoal::initTmpDir() { /* In a sandbox, for determinism, always use the same temporary directory. */ -#if __linux__ +#ifdef __linux__ tmpDirInSandbox = useChroot ? settings.sandboxBuildDir : tmpDir; #else tmpDirInSandbox = tmpDir; @@ -1639,7 +1646,7 @@ void LocalDerivationGoal::addDependency(const StorePath & path) debug("materialising '%s' in the sandbox", worker.store.printStorePath(path)); - #if __linux__ + #ifdef __linux__ Path source = worker.store.Store::toRealPath(path); Path target = chrootRootDir + worker.store.printStorePath(path); @@ -1689,7 +1696,7 @@ void LocalDerivationGoal::chownToBuilder(const Path & path) void setupSeccomp() { -#if __linux__ +#ifdef __linux__ if (!settings.filterSyscalls) return; #if HAVE_SECCOMP scmp_filter_ctx ctx; @@ -1701,7 +1708,7 @@ void setupSeccomp() seccomp_release(ctx); }); - constexpr std::string_view nativeSystem = SYSTEM; + constexpr std::string_view nativeSystem = NIX_LOCAL_SYSTEM; if (nativeSystem == "x86_64-linux" && seccomp_arch_add(ctx, SCMP_ARCH_X86) != 0) @@ -1809,7 +1816,7 @@ void LocalDerivationGoal::runChild() } catch (SystemError &) { } } -#if __linux__ +#ifdef __linux__ if (useChroot) { userNamespaceSync.writeSide = -1; @@ -2043,7 +2050,7 @@ void LocalDerivationGoal::runChild() /* Close all other file descriptors. */ unix::closeExtraFDs(); -#if __linux__ +#ifdef __linux__ linux::setPersonality(drv->platform); #endif @@ -2082,7 +2089,7 @@ void LocalDerivationGoal::runChild() throw SysError("setuid failed"); } -#if __APPLE__ +#ifdef __APPLE__ /* This has to appear before import statements. */ std::string sandboxProfile = "(version 1)\n"; @@ -2253,7 +2260,7 @@ void LocalDerivationGoal::runChild() for (auto & i : drv->args) args.push_back(rewriteStrings(i, inputRewrites)); -#if __APPLE__ +#ifdef __APPLE__ posix_spawnattr_t attrp; if (posix_spawnattr_init(&attrp)) @@ -2926,8 +2933,12 @@ void LocalDerivationGoal::checkOutputs(const std::mappath); - else - throw BuildError("derivation contains an illegal reference specifier '%s'", i); + else { + std::string outputsListing = concatMapStringsSep(", ", outputs, [](auto & o) { return o.first; }); + throw BuildError("derivation '%s' output check for '%s' contains an illegal reference specifier '%s'," + " expected store path or output name (one of [%s])", + worker.store.printStorePath(drvPath), outputName, i, outputsListing); + } } auto used = recursive diff --git a/src/libstore/unix/build/child.hh b/src/libstore/unix/include/nix/store/build/child.hh similarity index 100% rename from src/libstore/unix/build/child.hh rename to src/libstore/unix/include/nix/store/build/child.hh diff --git a/src/libstore/unix/build/hook-instance.hh b/src/libstore/unix/include/nix/store/build/hook-instance.hh similarity index 83% rename from src/libstore/unix/build/hook-instance.hh rename to src/libstore/unix/include/nix/store/build/hook-instance.hh index 61cf534f4..ff205ff76 100644 --- a/src/libstore/unix/build/hook-instance.hh +++ b/src/libstore/unix/include/nix/store/build/hook-instance.hh @@ -1,9 +1,9 @@ #pragma once ///@file -#include "logging.hh" -#include "serialise.hh" -#include "processes.hh" +#include "nix/util/logging.hh" +#include "nix/util/serialise.hh" +#include "nix/util/processes.hh" namespace nix { diff --git a/src/libstore/unix/build/local-derivation-goal.hh b/src/libstore/unix/include/nix/store/build/local-derivation-goal.hh similarity index 98% rename from src/libstore/unix/build/local-derivation-goal.hh rename to src/libstore/unix/include/nix/store/build/local-derivation-goal.hh index c7a129f90..795286a01 100644 --- a/src/libstore/unix/build/local-derivation-goal.hh +++ b/src/libstore/unix/include/nix/store/build/local-derivation-goal.hh @@ -1,9 +1,9 @@ #pragma once ///@file -#include "derivation-goal.hh" -#include "local-store.hh" -#include "processes.hh" +#include "nix/store/build/derivation-goal.hh" +#include "nix/store/local-store.hh" +#include "nix/util/processes.hh" namespace nix { diff --git a/src/libstore/unix/include/nix/store/meson.build b/src/libstore/unix/include/nix/store/meson.build new file mode 100644 index 000000000..9f12440cd --- /dev/null +++ b/src/libstore/unix/include/nix/store/meson.build @@ -0,0 +1,8 @@ +include_dirs += include_directories('../..') + +headers += files( + 'build/child.hh', + 'build/hook-instance.hh', + 'build/local-derivation-goal.hh', + 'user-lock.hh', +) diff --git a/src/libstore/unix/user-lock.hh b/src/libstore/unix/include/nix/store/user-lock.hh similarity index 100% rename from src/libstore/unix/user-lock.hh rename to src/libstore/unix/include/nix/store/user-lock.hh diff --git a/src/libstore/unix/meson.build b/src/libstore/unix/meson.build index d9d190131..f06c9aa95 100644 --- a/src/libstore/unix/meson.build +++ b/src/libstore/unix/meson.build @@ -6,14 +6,4 @@ sources += files( 'user-lock.cc', ) -include_dirs += include_directories( - '.', - 'build', -) - -headers += files( - 'build/child.hh', - 'build/hook-instance.hh', - 'build/local-derivation-goal.hh', - 'user-lock.hh', -) +subdir('include/nix/store') diff --git a/src/libstore/unix/pathlocks.cc b/src/libstore/unix/pathlocks.cc index 1ec4579ec..58d047f4e 100644 --- a/src/libstore/unix/pathlocks.cc +++ b/src/libstore/unix/pathlocks.cc @@ -1,7 +1,7 @@ -#include "pathlocks.hh" -#include "util.hh" -#include "sync.hh" -#include "signals.hh" +#include "nix/store/pathlocks.hh" +#include "nix/util/util.hh" +#include "nix/util/sync.hh" +#include "nix/util/signals.hh" #include #include diff --git a/src/libstore/unix/user-lock.cc b/src/libstore/unix/user-lock.cc index 29f4b2cb3..2bee277f9 100644 --- a/src/libstore/unix/user-lock.cc +++ b/src/libstore/unix/user-lock.cc @@ -2,15 +2,15 @@ #include #include -#include "user-lock.hh" -#include "file-system.hh" -#include "globals.hh" -#include "pathlocks.hh" -#include "users.hh" +#include "nix/store/user-lock.hh" +#include "nix/util/file-system.hh" +#include "nix/store/globals.hh" +#include "nix/store/pathlocks.hh" +#include "nix/util/users.hh" namespace nix { -#if __linux__ +#ifdef __linux__ static std::vector get_group_list(const char *username, gid_t group_id) { @@ -94,7 +94,7 @@ struct SimpleUserLock : UserLock if (lock->uid == getuid() || lock->uid == geteuid()) throw Error("the Nix user should not be a member of '%s'", settings.buildUsersGroup); - #if __linux__ + #ifdef __linux__ /* Get the list of supplementary groups of this user. This is * usually either empty or contains a group such as "kvm". */ @@ -193,10 +193,10 @@ std::unique_ptr acquireUserLock(uid_t nrIds, bool useUserNamespace) bool useBuildUsers() { - #if __linux__ + #ifdef __linux__ static bool b = (settings.buildUsersGroup != "" || settings.autoAllocateUids) && isRootUser(); return b; - #elif __APPLE__ + #elif defined(__APPLE__) static bool b = settings.buildUsersGroup != "" && isRootUser(); return b; #else diff --git a/src/libstore/windows/pathlocks.cc b/src/libstore/windows/pathlocks.cc index 29a98d8e2..0ba75853b 100644 --- a/src/libstore/windows/pathlocks.cc +++ b/src/libstore/windows/pathlocks.cc @@ -1,13 +1,13 @@ -#include "logging.hh" -#include "pathlocks.hh" -#include "signals.hh" -#include "util.hh" +#include "nix/util/logging.hh" +#include "nix/store/pathlocks.hh" +#include "nix/util/signals.hh" +#include "nix/util/util.hh" #ifdef _WIN32 # include # include # include -# include "windows-error.hh" +# include "nix/util/windows-error.hh" namespace nix { diff --git a/src/libstore/worker-protocol-connection.cc b/src/libstore/worker-protocol-connection.cc index 6585df4be..d83be10e6 100644 --- a/src/libstore/worker-protocol-connection.cc +++ b/src/libstore/worker-protocol-connection.cc @@ -1,7 +1,7 @@ -#include "worker-protocol-connection.hh" -#include "worker-protocol-impl.hh" -#include "build-result.hh" -#include "derivations.hh" +#include "nix/store/worker-protocol-connection.hh" +#include "nix/store/worker-protocol-impl.hh" +#include "nix/store/build-result.hh" +#include "nix/store/derivations.hh" namespace nix { diff --git a/src/libstore/worker-protocol.cc b/src/libstore/worker-protocol.cc index f06fb2893..21b21a347 100644 --- a/src/libstore/worker-protocol.cc +++ b/src/libstore/worker-protocol.cc @@ -1,11 +1,11 @@ -#include "serialise.hh" -#include "path-with-outputs.hh" -#include "store-api.hh" -#include "build-result.hh" -#include "worker-protocol.hh" -#include "worker-protocol-impl.hh" -#include "archive.hh" -#include "path-info.hh" +#include "nix/util/serialise.hh" +#include "nix/store/path-with-outputs.hh" +#include "nix/store/store-api.hh" +#include "nix/store/build-result.hh" +#include "nix/store/worker-protocol.hh" +#include "nix/store/worker-protocol-impl.hh" +#include "nix/util/archive.hh" +#include "nix/store/path-info.hh" #include #include diff --git a/src/libutil-c/meson.build b/src/libutil-c/meson.build index ac1297665..3414a6d31 100644 --- a/src/libutil-c/meson.build +++ b/src/libutil-c/meson.build @@ -23,24 +23,11 @@ deps_public_maybe_subproject = [ ] subdir('nix-meson-build-support/subprojects') -# TODO rename, because it will conflict with downstream projects configdata.set_quoted('PACKAGE_VERSION', meson.project_version()) -config_h = configure_file( +config_priv_h = configure_file( configuration : configdata, - output : 'config-util.h', -) - -add_project_arguments( - # TODO(Qyriad): Yes this is how the autoconf+Make system did it. - # It would be nice for our headers to be idempotent instead. - - # From C++ libraries, only for internals - '-include', 'config-util.hh', - - # From C libraries, for our public, installed headers too - '-include', 'config-util.h', - language : 'cpp', + output : 'nix_api_util_config.h', ) subdir('nix-meson-build-support/common') @@ -51,7 +38,7 @@ sources = files( include_dirs = [include_directories('.')] -headers = [config_h] + files( +headers = files( 'nix_api_util.h', ) @@ -64,6 +51,7 @@ subdir('nix-meson-build-support/windows-version') this_library = library( 'nixutilc', sources, + config_priv_h, dependencies : deps_public + deps_private + deps_other, include_directories : include_dirs, link_args: linker_export_flags, @@ -71,7 +59,7 @@ this_library = library( install : true, ) -install_headers(headers, subdir : 'nix', preserve_path : true) +install_headers(headers, preserve_path : true) libraries_private = [] diff --git a/src/libutil-c/nix_api_util.cc b/src/libutil-c/nix_api_util.cc index 992ea0a2a..2254f18fa 100644 --- a/src/libutil-c/nix_api_util.cc +++ b/src/libutil-c/nix_api_util.cc @@ -1,12 +1,14 @@ #include "nix_api_util.h" -#include "config-global.hh" -#include "error.hh" +#include "nix/util/config-global.hh" +#include "nix/util/error.hh" #include "nix_api_util_internal.h" -#include "util.hh" +#include "nix/util/util.hh" #include #include +#include "nix_api_util_config.h" + nix_c_context * nix_c_context_create() { return new nix_c_context(); diff --git a/src/libutil-c/nix_api_util_internal.h b/src/libutil-c/nix_api_util_internal.h index 7fa4252ac..8fbf3d91a 100644 --- a/src/libutil-c/nix_api_util_internal.h +++ b/src/libutil-c/nix_api_util_internal.h @@ -4,7 +4,7 @@ #include #include -#include "error.hh" +#include "nix/util/error.hh" #include "nix_api_util.h" struct nix_c_context diff --git a/src/libutil-test-support/tests/hash.cc b/src/libutil-test-support/hash.cc similarity index 89% rename from src/libutil-test-support/tests/hash.cc rename to src/libutil-test-support/hash.cc index 51b9663b4..d047f4073 100644 --- a/src/libutil-test-support/tests/hash.cc +++ b/src/libutil-test-support/hash.cc @@ -2,9 +2,9 @@ #include -#include "hash.hh" +#include "nix/util/hash.hh" -#include "tests/hash.hh" +#include "nix/util/tests/hash.hh" namespace rc { using namespace nix; diff --git a/src/libutil-test-support/tests/characterization.hh b/src/libutil-test-support/include/nix/util/tests/characterization.hh similarity index 95% rename from src/libutil-test-support/tests/characterization.hh rename to src/libutil-test-support/include/nix/util/tests/characterization.hh index 5e790e75b..3e8effe8b 100644 --- a/src/libutil-test-support/tests/characterization.hh +++ b/src/libutil-test-support/include/nix/util/tests/characterization.hh @@ -3,9 +3,9 @@ #include -#include "types.hh" -#include "environment-variables.hh" -#include "file-system.hh" +#include "nix/util/types.hh" +#include "nix/util/environment-variables.hh" +#include "nix/util/file-system.hh" namespace nix { diff --git a/src/libutil-test-support/tests/gtest-with-params.hh b/src/libutil-test-support/include/nix/util/tests/gtest-with-params.hh similarity index 100% rename from src/libutil-test-support/tests/gtest-with-params.hh rename to src/libutil-test-support/include/nix/util/tests/gtest-with-params.hh diff --git a/src/libutil-test-support/tests/hash.hh b/src/libutil-test-support/include/nix/util/tests/hash.hh similarity index 86% rename from src/libutil-test-support/tests/hash.hh rename to src/libutil-test-support/include/nix/util/tests/hash.hh index 1f9fa59ae..de832c12f 100644 --- a/src/libutil-test-support/tests/hash.hh +++ b/src/libutil-test-support/include/nix/util/tests/hash.hh @@ -3,7 +3,7 @@ #include -#include +#include "nix/util/hash.hh" namespace rc { using namespace nix; diff --git a/src/libutil-test-support/include/nix/util/tests/meson.build b/src/libutil-test-support/include/nix/util/tests/meson.build new file mode 100644 index 000000000..f77dedff7 --- /dev/null +++ b/src/libutil-test-support/include/nix/util/tests/meson.build @@ -0,0 +1,11 @@ +# Public headers directory + +include_dirs = [include_directories('../../..')] + +headers = files( + 'characterization.hh', + 'gtest-with-params.hh', + 'hash.hh', + 'nix_api_util.hh', + 'string_callback.hh', +) diff --git a/src/libutil-test-support/tests/nix_api_util.hh b/src/libutil-test-support/include/nix/util/tests/nix_api_util.hh similarity index 100% rename from src/libutil-test-support/tests/nix_api_util.hh rename to src/libutil-test-support/include/nix/util/tests/nix_api_util.hh diff --git a/src/libutil-test-support/tests/string_callback.hh b/src/libutil-test-support/include/nix/util/tests/string_callback.hh similarity index 100% rename from src/libutil-test-support/tests/string_callback.hh rename to src/libutil-test-support/include/nix/util/tests/string_callback.hh diff --git a/src/libutil-test-support/tests/tracing-file-system-object-sink.hh b/src/libutil-test-support/include/nix/util/tests/tracing-file-system-object-sink.hh similarity index 97% rename from src/libutil-test-support/tests/tracing-file-system-object-sink.hh rename to src/libutil-test-support/include/nix/util/tests/tracing-file-system-object-sink.hh index 895ac3664..d721c13af 100644 --- a/src/libutil-test-support/tests/tracing-file-system-object-sink.hh +++ b/src/libutil-test-support/include/nix/util/tests/tracing-file-system-object-sink.hh @@ -1,5 +1,5 @@ #pragma once -#include "fs-sink.hh" +#include "nix/util/fs-sink.hh" namespace nix::test { diff --git a/src/libutil-test-support/meson.build b/src/libutil-test-support/meson.build index db944cf06..ec6bc15d9 100644 --- a/src/libutil-test-support/meson.build +++ b/src/libutil-test-support/meson.build @@ -25,29 +25,14 @@ subdir('nix-meson-build-support/subprojects') rapidcheck = dependency('rapidcheck') deps_public += rapidcheck -add_project_arguments( - # TODO(Qyriad): Yes this is how the autoconf+Make system did it. - # It would be nice for our headers to be idempotent instead. - '-include', 'config-util.hh', - language : 'cpp', -) - subdir('nix-meson-build-support/common') sources = files( - 'tests/hash.cc', - 'tests/string_callback.cc', + 'hash.cc', + 'string_callback.cc', ) -include_dirs = [include_directories('.')] - -headers = files( - 'tests/characterization.hh', - 'tests/gtest-with-params.hh', - 'tests/hash.hh', - 'tests/nix_api_util.hh', - 'tests/string_callback.hh', -) +subdir('include/nix/util/tests') subdir('nix-meson-build-support/export-all-symbols') subdir('nix-meson-build-support/windows-version') @@ -64,7 +49,7 @@ this_library = library( install : true, ) -install_headers(headers, subdir : 'nix', preserve_path : true) +install_headers(headers, subdir : 'nix/util/tests', preserve_path : true) libraries_private = [] diff --git a/src/libutil-test-support/package.nix b/src/libutil-test-support/package.nix index 3b094ac29..40ff65d61 100644 --- a/src/libutil-test-support/package.nix +++ b/src/libutil-test-support/package.nix @@ -28,6 +28,7 @@ mkMesonLibrary (finalAttrs: { ./.version ./meson.build # ./meson.options + ./include/nix/util/tests/meson.build (fileset.fileFilter (file: file.hasExt "cc") ./.) (fileset.fileFilter (file: file.hasExt "hh") ./.) ]; diff --git a/src/libutil-test-support/tests/string_callback.cc b/src/libutil-test-support/string_callback.cc similarity index 83% rename from src/libutil-test-support/tests/string_callback.cc rename to src/libutil-test-support/string_callback.cc index 7a13bd4ff..4f6a9cf40 100644 --- a/src/libutil-test-support/tests/string_callback.cc +++ b/src/libutil-test-support/string_callback.cc @@ -1,4 +1,4 @@ -#include "string_callback.hh" +#include "nix/util/tests/string_callback.hh" namespace nix::testing { diff --git a/src/libutil-test-support/tests/tracing-file-system-object-sink.cc b/src/libutil-test-support/tracing-file-system-object-sink.cc similarity index 95% rename from src/libutil-test-support/tests/tracing-file-system-object-sink.cc rename to src/libutil-test-support/tracing-file-system-object-sink.cc index 122a09dcb..52b081fb8 100644 --- a/src/libutil-test-support/tests/tracing-file-system-object-sink.cc +++ b/src/libutil-test-support/tracing-file-system-object-sink.cc @@ -1,5 +1,5 @@ #include -#include "tracing-file-system-object-sink.hh" +#include "nix/tracing-file-system-object-sink.hh" namespace nix::test { diff --git a/src/libutil-tests/args.cc b/src/libutil-tests/args.cc index 950224430..2cc1a3438 100644 --- a/src/libutil-tests/args.cc +++ b/src/libutil-tests/args.cc @@ -1,5 +1,5 @@ -#include "args.hh" -#include "fs-sink.hh" +#include "nix/util/args.hh" +#include "nix/util/fs-sink.hh" #include #include diff --git a/src/libutil-tests/canon-path.cc b/src/libutil-tests/canon-path.cc index 7f91308af..c6808bf66 100644 --- a/src/libutil-tests/canon-path.cc +++ b/src/libutil-tests/canon-path.cc @@ -1,4 +1,4 @@ -#include "canon-path.hh" +#include "nix/util/canon-path.hh" #include diff --git a/src/libutil-tests/checked-arithmetic.cc b/src/libutil-tests/checked-arithmetic.cc index 75018660d..8056a430a 100644 --- a/src/libutil-tests/checked-arithmetic.cc +++ b/src/libutil-tests/checked-arithmetic.cc @@ -5,9 +5,9 @@ #include #include -#include +#include "nix/util/checked-arithmetic.hh" -#include "tests/gtest-with-params.hh" +#include "nix/util/tests/gtest-with-params.hh" namespace rc { using namespace nix; diff --git a/src/libutil-tests/chunked-vector.cc b/src/libutil-tests/chunked-vector.cc index 868d11f6f..658581c2a 100644 --- a/src/libutil-tests/chunked-vector.cc +++ b/src/libutil-tests/chunked-vector.cc @@ -1,4 +1,4 @@ -#include "chunked-vector.hh" +#include "nix/util/chunked-vector.hh" #include diff --git a/src/libutil-tests/closure.cc b/src/libutil-tests/closure.cc index 7597e7807..6bbc128c2 100644 --- a/src/libutil-tests/closure.cc +++ b/src/libutil-tests/closure.cc @@ -1,4 +1,4 @@ -#include "closure.hh" +#include "nix/util/closure.hh" #include namespace nix { diff --git a/src/libutil-tests/compression.cc b/src/libutil-tests/compression.cc index bbbf3500f..de0c7cdb6 100644 --- a/src/libutil-tests/compression.cc +++ b/src/libutil-tests/compression.cc @@ -1,4 +1,4 @@ -#include "compression.hh" +#include "nix/util/compression.hh" #include namespace nix { diff --git a/src/libutil-tests/config.cc b/src/libutil-tests/config.cc index f3dc2876a..28b680d9c 100644 --- a/src/libutil-tests/config.cc +++ b/src/libutil-tests/config.cc @@ -1,5 +1,5 @@ -#include "config.hh" -#include "args.hh" +#include "nix/util/configuration.hh" +#include "nix/util/args.hh" #include #include diff --git a/src/libutil-tests/executable-path.cc b/src/libutil-tests/executable-path.cc index 8d182357d..7229b14e6 100644 --- a/src/libutil-tests/executable-path.cc +++ b/src/libutil-tests/executable-path.cc @@ -1,6 +1,6 @@ #include -#include "executable-path.hh" +#include "nix/util/executable-path.hh" namespace nix { diff --git a/src/libutil-tests/file-content-address.cc b/src/libutil-tests/file-content-address.cc index 27d926a87..5cdf94edc 100644 --- a/src/libutil-tests/file-content-address.cc +++ b/src/libutil-tests/file-content-address.cc @@ -1,6 +1,6 @@ #include -#include "file-content-address.hh" +#include "nix/util/file-content-address.hh" namespace nix { diff --git a/src/libutil-tests/file-system.cc b/src/libutil-tests/file-system.cc index 2c10d4869..8c9eccc11 100644 --- a/src/libutil-tests/file-system.cc +++ b/src/libutil-tests/file-system.cc @@ -1,9 +1,9 @@ -#include "util.hh" -#include "types.hh" -#include "file-system.hh" -#include "processes.hh" -#include "terminal.hh" -#include "strings.hh" +#include "nix/util/util.hh" +#include "nix/util/types.hh" +#include "nix/util/file-system.hh" +#include "nix/util/processes.hh" +#include "nix/util/terminal.hh" +#include "nix/util/strings.hh" #include #include diff --git a/src/libutil-tests/git.cc b/src/libutil-tests/git.cc index 048956a58..91432b76b 100644 --- a/src/libutil-tests/git.cc +++ b/src/libutil-tests/git.cc @@ -1,9 +1,9 @@ #include -#include "git.hh" -#include "memory-source-accessor.hh" +#include "nix/util/git.hh" +#include "nix/util/memory-source-accessor.hh" -#include "tests/characterization.hh" +#include "nix/util/tests/characterization.hh" namespace nix { diff --git a/src/libutil-tests/hash.cc b/src/libutil-tests/hash.cc index 3a639aef9..3c71b0486 100644 --- a/src/libutil-tests/hash.cc +++ b/src/libutil-tests/hash.cc @@ -2,7 +2,7 @@ #include -#include "hash.hh" +#include "nix/util/hash.hh" namespace nix { diff --git a/src/libutil-tests/hilite.cc b/src/libutil-tests/hilite.cc index 5ef581888..98773afcf 100644 --- a/src/libutil-tests/hilite.cc +++ b/src/libutil-tests/hilite.cc @@ -1,4 +1,4 @@ -#include "hilite.hh" +#include "nix/util/hilite.hh" #include diff --git a/src/libutil-tests/json-utils.cc b/src/libutil-tests/json-utils.cc index 704a4acb0..051d86ec7 100644 --- a/src/libutil-tests/json-utils.cc +++ b/src/libutil-tests/json-utils.cc @@ -3,8 +3,8 @@ #include -#include "error.hh" -#include "json-utils.hh" +#include "nix/util/error.hh" +#include "nix/util/json-utils.hh" namespace nix { diff --git a/src/libutil-tests/logging.cc b/src/libutil-tests/logging.cc index 1d7304f05..494e9ce4c 100644 --- a/src/libutil-tests/logging.cc +++ b/src/libutil-tests/logging.cc @@ -1,7 +1,7 @@ #if 0 -#include "logging.hh" -#include "nixexpr.hh" +#include "nix/util/logging.hh" +#include "nix/expr/nixexpr.hh" #include #include diff --git a/src/libutil-tests/lru-cache.cc b/src/libutil-tests/lru-cache.cc index 091d3d5ed..daa2a91fe 100644 --- a/src/libutil-tests/lru-cache.cc +++ b/src/libutil-tests/lru-cache.cc @@ -1,4 +1,4 @@ -#include "lru-cache.hh" +#include "nix/util/lru-cache.hh" #include namespace nix { diff --git a/src/libutil-tests/meson.build b/src/libutil-tests/meson.build index ad2c61711..8f9c18eed 100644 --- a/src/libutil-tests/meson.build +++ b/src/libutil-tests/meson.build @@ -32,12 +32,12 @@ deps_private += rapidcheck gtest = dependency('gtest', main : true) deps_private += gtest -add_project_arguments( - # TODO(Qyriad): Yes this is how the autoconf+Make system did it. - # It would be nice for our headers to be idempotent instead. - '-include', 'config-util.hh', - '-include', 'config-util.h', - language : 'cpp', +configdata = configuration_data() +configdata.set_quoted('PACKAGE_VERSION', meson.project_version()) + +config_priv_h = configure_file( + configuration : configdata, + output : 'util-tests-config.hh', ) subdir('nix-meson-build-support/common') @@ -79,6 +79,7 @@ include_dirs = [include_directories('.')] this_exe = executable( meson.project_name(), sources, + config_priv_h, dependencies : deps_private_subproject + deps_private + deps_other, include_directories : include_dirs, # TODO: -lrapidcheck, see ../libutil-support/build.meson diff --git a/src/libutil-tests/nix_api_util.cc b/src/libutil-tests/nix_api_util.cc index 7b77bd87f..baaaa81fc 100644 --- a/src/libutil-tests/nix_api_util.cc +++ b/src/libutil-tests/nix_api_util.cc @@ -1,14 +1,16 @@ -#include "config-global.hh" -#include "args.hh" +#include "nix/util/config-global.hh" +#include "nix/util/args.hh" #include "nix_api_util.h" #include "nix_api_util_internal.h" -#include "tests/nix_api_util.hh" -#include "tests/string_callback.hh" +#include "nix/util/tests/nix_api_util.hh" +#include "nix/util/tests/string_callback.hh" #include #include +#include "util-tests-config.hh" + namespace nixC { TEST_F(nix_api_util_context, nix_context_error) diff --git a/src/libutil-tests/pool.cc b/src/libutil-tests/pool.cc index 127e42dda..c9f31f9a0 100644 --- a/src/libutil-tests/pool.cc +++ b/src/libutil-tests/pool.cc @@ -1,4 +1,4 @@ -#include "pool.hh" +#include "nix/util/pool.hh" #include namespace nix { diff --git a/src/libutil-tests/position.cc b/src/libutil-tests/position.cc index 484ecc247..fd65acd03 100644 --- a/src/libutil-tests/position.cc +++ b/src/libutil-tests/position.cc @@ -1,6 +1,6 @@ #include -#include "position.hh" +#include "nix/util/position.hh" namespace nix { diff --git a/src/libutil-tests/processes.cc b/src/libutil-tests/processes.cc index 9033595e8..eb7561393 100644 --- a/src/libutil-tests/processes.cc +++ b/src/libutil-tests/processes.cc @@ -1,4 +1,4 @@ -#include "processes.hh" +#include "nix/util/processes.hh" #include diff --git a/src/libutil-tests/references.cc b/src/libutil-tests/references.cc index c3efa6d51..622b3c35a 100644 --- a/src/libutil-tests/references.cc +++ b/src/libutil-tests/references.cc @@ -1,4 +1,4 @@ -#include "references.hh" +#include "nix/util/references.hh" #include namespace nix { diff --git a/src/libutil-tests/spawn.cc b/src/libutil-tests/spawn.cc index c617acae0..594bced59 100644 --- a/src/libutil-tests/spawn.cc +++ b/src/libutil-tests/spawn.cc @@ -1,6 +1,6 @@ #include -#include "processes.hh" +#include "nix/util/processes.hh" namespace nix { diff --git a/src/libutil-tests/strings.cc b/src/libutil-tests/strings.cc index 206890bcf..f5af4e0ff 100644 --- a/src/libutil-tests/strings.cc +++ b/src/libutil-tests/strings.cc @@ -1,8 +1,8 @@ #include #include -#include "strings.hh" -#include "error.hh" +#include "nix/util/strings.hh" +#include "nix/util/error.hh" namespace nix { @@ -80,6 +80,42 @@ TEST(concatStringsSep, buildSingleString) ASSERT_EQ(concatStringsSep(",", strings), "this"); } +TEST(concatMapStringsSep, empty) +{ + Strings strings; + + ASSERT_EQ(concatMapStringsSep(",", strings, [](const std::string & s) { return s; }), ""); +} + +TEST(concatMapStringsSep, justOne) +{ + Strings strings; + strings.push_back("this"); + + ASSERT_EQ(concatMapStringsSep(",", strings, [](const std::string & s) { return s; }), "this"); +} + +TEST(concatMapStringsSep, two) +{ + Strings strings; + strings.push_back("this"); + strings.push_back("that"); + + ASSERT_EQ(concatMapStringsSep(",", strings, [](const std::string & s) { return s; }), "this,that"); +} + +TEST(concatMapStringsSep, map) +{ + std::map strings; + strings["this"] = "that"; + strings["1"] = "one"; + + ASSERT_EQ( + concatMapStringsSep( + ", ", strings, [](const std::pair & s) { return s.first + " -> " + s.second; }), + "1 -> one, this -> that"); +} + /* ---------------------------------------------------------------------------- * dropEmptyInitThenConcatStringsSep * --------------------------------------------------------------------------*/ diff --git a/src/libutil-tests/suggestions.cc b/src/libutil-tests/suggestions.cc index 279994abc..c58f033da 100644 --- a/src/libutil-tests/suggestions.cc +++ b/src/libutil-tests/suggestions.cc @@ -1,4 +1,4 @@ -#include "suggestions.hh" +#include "nix/util/suggestions.hh" #include namespace nix { diff --git a/src/libutil-tests/terminal.cc b/src/libutil-tests/terminal.cc index f4fc6e770..329c1a186 100644 --- a/src/libutil-tests/terminal.cc +++ b/src/libutil-tests/terminal.cc @@ -1,7 +1,7 @@ -#include "util.hh" -#include "types.hh" -#include "terminal.hh" -#include "strings.hh" +#include "nix/util/util.hh" +#include "nix/util/types.hh" +#include "nix/util/terminal.hh" +#include "nix/util/strings.hh" #include #include diff --git a/src/libutil-tests/url.cc b/src/libutil-tests/url.cc index 7e1d2aa15..4c089c106 100644 --- a/src/libutil-tests/url.cc +++ b/src/libutil-tests/url.cc @@ -1,4 +1,4 @@ -#include "url.hh" +#include "nix/util/url.hh" #include namespace nix { diff --git a/src/libutil-tests/util.cc b/src/libutil-tests/util.cc index a3f7c720a..954867be8 100644 --- a/src/libutil-tests/util.cc +++ b/src/libutil-tests/util.cc @@ -1,8 +1,8 @@ -#include "util.hh" -#include "types.hh" -#include "file-system.hh" -#include "terminal.hh" -#include "strings.hh" +#include "nix/util/util.hh" +#include "nix/util/types.hh" +#include "nix/util/file-system.hh" +#include "nix/util/terminal.hh" +#include "nix/util/strings.hh" #include #include diff --git a/src/libutil-tests/xml-writer.cc b/src/libutil-tests/xml-writer.cc index adcde25c9..000af700c 100644 --- a/src/libutil-tests/xml-writer.cc +++ b/src/libutil-tests/xml-writer.cc @@ -1,4 +1,4 @@ -#include "xml-writer.hh" +#include "nix/util/xml-writer.hh" #include #include diff --git a/src/libutil/archive.cc b/src/libutil/archive.cc index 20d8a1e09..487873ce6 100644 --- a/src/libutil/archive.cc +++ b/src/libutil/archive.cc @@ -5,19 +5,19 @@ #include // for strcasecmp -#include "archive.hh" -#include "config-global.hh" -#include "posix-source-accessor.hh" -#include "source-path.hh" -#include "file-system.hh" -#include "signals.hh" +#include "nix/util/archive.hh" +#include "nix/util/config-global.hh" +#include "nix/util/posix-source-accessor.hh" +#include "nix/util/source-path.hh" +#include "nix/util/file-system.hh" +#include "nix/util/signals.hh" namespace nix { struct ArchiveSettings : Config { Setting useCaseHack{this, - #if __APPLE__ + #ifdef __APPLE__ true, #else false, diff --git a/src/libutil/args.cc b/src/libutil/args.cc index 2022ca9ae..39d66b3ec 100644 --- a/src/libutil/args.cc +++ b/src/libutil/args.cc @@ -1,10 +1,10 @@ -#include "args.hh" -#include "args/root.hh" -#include "hash.hh" -#include "environment-variables.hh" -#include "signals.hh" -#include "users.hh" -#include "json-utils.hh" +#include "nix/util/args.hh" +#include "nix/util/args/root.hh" +#include "nix/util/hash.hh" +#include "nix/util/environment-variables.hh" +#include "nix/util/signals.hh" +#include "nix/util/users.hh" +#include "nix/util/json-utils.hh" #include #include diff --git a/src/libutil/canon-path.cc b/src/libutil/canon-path.cc index 03db6378a..33ac700f0 100644 --- a/src/libutil/canon-path.cc +++ b/src/libutil/canon-path.cc @@ -1,7 +1,7 @@ -#include "canon-path.hh" -#include "util.hh" -#include "file-path-impl.hh" -#include "strings-inline.hh" +#include "nix/util/canon-path.hh" +#include "nix/util/util.hh" +#include "nix/util/file-path-impl.hh" +#include "nix/util/strings-inline.hh" namespace nix { diff --git a/src/libutil/compression.cc b/src/libutil/compression.cc index d27028565..0e38620d4 100644 --- a/src/libutil/compression.cc +++ b/src/libutil/compression.cc @@ -1,8 +1,8 @@ -#include "compression.hh" -#include "signals.hh" -#include "tarfile.hh" -#include "finally.hh" -#include "logging.hh" +#include "nix/util/compression.hh" +#include "nix/util/signals.hh" +#include "nix/util/tarfile.hh" +#include "nix/util/finally.hh" +#include "nix/util/logging.hh" #include #include diff --git a/src/libutil/compute-levels.cc b/src/libutil/compute-levels.cc index 19eaedfa8..c80b99404 100644 --- a/src/libutil/compute-levels.cc +++ b/src/libutil/compute-levels.cc @@ -1,4 +1,6 @@ -#include "types.hh" +#include "nix/util/types.hh" + +#include "util-config-private.hh" #if HAVE_LIBCPUID #include diff --git a/src/libutil/config-global.cc b/src/libutil/config-global.cc index 3ed1dd1d3..10d176c51 100644 --- a/src/libutil/config-global.cc +++ b/src/libutil/config-global.cc @@ -1,4 +1,4 @@ -#include "config-global.hh" +#include "nix/util/config-global.hh" #include diff --git a/src/libutil/config.cc b/src/libutil/configuration.cc similarity index 97% rename from src/libutil/config.cc rename to src/libutil/configuration.cc index c9ced6b2b..08e5919e0 100644 --- a/src/libutil/config.cc +++ b/src/libutil/configuration.cc @@ -1,16 +1,16 @@ -#include "config.hh" -#include "args.hh" -#include "abstract-setting-to-json.hh" -#include "environment-variables.hh" -#include "experimental-features.hh" -#include "util.hh" -#include "file-system.hh" +#include "nix/util/configuration.hh" +#include "nix/util/args.hh" +#include "nix/util/abstract-setting-to-json.hh" +#include "nix/util/environment-variables.hh" +#include "nix/util/experimental-features.hh" +#include "nix/util/util.hh" +#include "nix/util/file-system.hh" -#include "config-impl.hh" +#include "nix/util/config-impl.hh" #include -#include "strings.hh" +#include "nix/util/strings.hh" namespace nix { diff --git a/src/libutil/current-process.cc b/src/libutil/current-process.cc index 255ae2cf5..926714ae8 100644 --- a/src/libutil/current-process.cc +++ b/src/libutil/current-process.cc @@ -1,29 +1,29 @@ #include #include -#include "current-process.hh" -#include "util.hh" -#include "finally.hh" -#include "file-system.hh" -#include "processes.hh" -#include "signals.hh" +#include "nix/util/current-process.hh" +#include "nix/util/util.hh" +#include "nix/util/finally.hh" +#include "nix/util/file-system.hh" +#include "nix/util/processes.hh" +#include "nix/util/signals.hh" #include #ifdef __APPLE__ # include #endif -#if __linux__ +#ifdef __linux__ # include -# include "cgroup.hh" -# include "namespaces.hh" +# include "nix/util/cgroup.hh" +# include "nix/util/namespaces.hh" #endif namespace nix { unsigned int getMaxCPU() { - #if __linux__ + #ifdef __linux__ try { auto cgroupFS = getCgroupFS(); if (!cgroupFS) return 0; @@ -82,7 +82,7 @@ void restoreProcessContext(bool restoreMounts) unix::restoreSignals(); #endif if (restoreMounts) { - #if __linux__ + #ifdef __linux__ restoreMountNamespace(); #endif } @@ -106,9 +106,9 @@ std::optional getSelfExe() { static auto cached = []() -> std::optional { - #if __linux__ || __GNU__ + #if defined(__linux__) || defined(__GNU__) return readLink("/proc/self/exe"); - #elif __APPLE__ + #elif defined(__APPLE__) char buf[1024]; uint32_t size = sizeof(buf); if (_NSGetExecutablePath(buf, &size) == 0) diff --git a/src/libutil/english.cc b/src/libutil/english.cc index 8c93c9156..e697b8c30 100644 --- a/src/libutil/english.cc +++ b/src/libutil/english.cc @@ -1,4 +1,4 @@ -#include "english.hh" +#include "nix/util/english.hh" namespace nix { diff --git a/src/libutil/environment-variables.cc b/src/libutil/environment-variables.cc index 5947cf742..0b668f125 100644 --- a/src/libutil/environment-variables.cc +++ b/src/libutil/environment-variables.cc @@ -1,5 +1,5 @@ -#include "util.hh" -#include "environment-variables.hh" +#include "nix/util/util.hh" +#include "nix/util/environment-variables.hh" extern char ** environ __attribute__((weak)); diff --git a/src/libutil/error.cc b/src/libutil/error.cc index ccd008c7c..0ceaa4e76 100644 --- a/src/libutil/error.cc +++ b/src/libutil/error.cc @@ -1,14 +1,14 @@ #include -#include "error.hh" -#include "environment-variables.hh" -#include "signals.hh" -#include "terminal.hh" -#include "position.hh" +#include "nix/util/error.hh" +#include "nix/util/environment-variables.hh" +#include "nix/util/signals.hh" +#include "nix/util/terminal.hh" +#include "nix/util/position.hh" #include #include -#include "serialise.hh" +#include "nix/util/serialise.hh" #include namespace nix { diff --git a/src/libutil/executable-path.cc b/src/libutil/executable-path.cc index 8d665c7df..ed1ac49ce 100644 --- a/src/libutil/executable-path.cc +++ b/src/libutil/executable-path.cc @@ -1,8 +1,8 @@ -#include "environment-variables.hh" -#include "executable-path.hh" -#include "strings-inline.hh" -#include "util.hh" -#include "file-path-impl.hh" +#include "nix/util/environment-variables.hh" +#include "nix/util/executable-path.hh" +#include "nix/util/strings-inline.hh" +#include "nix/util/util.hh" +#include "nix/util/file-path-impl.hh" namespace nix { diff --git a/src/libutil/exit.cc b/src/libutil/exit.cc index 73cd8b04e..3c59e46af 100644 --- a/src/libutil/exit.cc +++ b/src/libutil/exit.cc @@ -1,4 +1,4 @@ -#include "exit.hh" +#include "nix/util/exit.hh" namespace nix { diff --git a/src/libutil/experimental-features.cc b/src/libutil/experimental-features.cc index b7b8d9c6f..14116aa0c 100644 --- a/src/libutil/experimental-features.cc +++ b/src/libutil/experimental-features.cc @@ -1,8 +1,8 @@ -#include "experimental-features.hh" -#include "fmt.hh" -#include "util.hh" +#include "nix/util/experimental-features.hh" +#include "nix/util/fmt.hh" +#include "nix/util/util.hh" -#include "nlohmann/json.hpp" +#include namespace nix { diff --git a/src/libutil/file-content-address.cc b/src/libutil/file-content-address.cc index 69301d9c8..673e1dff1 100644 --- a/src/libutil/file-content-address.cc +++ b/src/libutil/file-content-address.cc @@ -1,7 +1,7 @@ -#include "file-content-address.hh" -#include "archive.hh" -#include "git.hh" -#include "source-path.hh" +#include "nix/util/file-content-address.hh" +#include "nix/util/archive.hh" +#include "nix/util/git.hh" +#include "nix/util/source-path.hh" namespace nix { diff --git a/src/libutil/file-descriptor.cc b/src/libutil/file-descriptor.cc index 707c0f882..9e0827442 100644 --- a/src/libutil/file-descriptor.cc +++ b/src/libutil/file-descriptor.cc @@ -1,12 +1,12 @@ -#include "serialise.hh" -#include "util.hh" +#include "nix/util/serialise.hh" +#include "nix/util/util.hh" #include #include #ifdef _WIN32 # include # include -# include "windows-error.hh" +# include "nix/util/windows-error.hh" #endif namespace nix { @@ -98,7 +98,7 @@ void AutoCloseFD::fsync() const result = #ifdef _WIN32 ::FlushFileBuffers(fd) -#elif __APPLE__ +#elif defined(__APPLE__) ::fcntl(fd, F_FULLFSYNC) #else ::fsync(fd) @@ -113,7 +113,7 @@ void AutoCloseFD::fsync() const void AutoCloseFD::startFsync() const { -#if __linux__ +#ifdef __linux__ if (fd != -1) { /* Ignore failure, since fsync must be run later anyway. This is just a performance optimization. */ ::sync_file_range(fd, 0, 0, SYNC_FILE_RANGE_WRITE); diff --git a/src/libutil/file-system.cc b/src/libutil/file-system.cc index 6fe93b63a..c7cea4b58 100644 --- a/src/libutil/file-system.cc +++ b/src/libutil/file-system.cc @@ -1,11 +1,11 @@ -#include "environment-variables.hh" -#include "file-system.hh" -#include "file-path.hh" -#include "file-path-impl.hh" -#include "signals.hh" -#include "finally.hh" -#include "serialise.hh" -#include "util.hh" +#include "nix/util/environment-variables.hh" +#include "nix/util/file-system.hh" +#include "nix/util/file-path.hh" +#include "nix/util/file-path-impl.hh" +#include "nix/util/signals.hh" +#include "nix/util/finally.hh" +#include "nix/util/serialise.hh" +#include "nix/util/util.hh" #include #include @@ -25,11 +25,23 @@ # include #endif -#include "strings-inline.hh" +#include "nix/util/strings-inline.hh" + +#include "util-config-private.hh" namespace nix { -namespace fs { using namespace std::filesystem; } +namespace fs { + using namespace std::filesystem; + + bool symlink_exists(const std::filesystem::path & path) { + try { + return std::filesystem::exists(std::filesystem::symlink_status(path)); + } catch (const std::filesystem::filesystem_error & e) { + throw SysError("cannot check existence of %1%", path); + } + } +} bool isAbsolute(PathView path) { @@ -475,12 +487,12 @@ void createDir(const Path & path, mode_t mode) throw SysError("creating directory '%1%'", path); } -void createDirs(const Path & path) +void createDirs(const fs::path & path) { try { fs::create_directories(path); } catch (fs::filesystem_error & e) { - throw SysError("creating directory '%1%'", path); + throw SysError("creating directory '%1%'", path.string()); } } @@ -562,7 +574,7 @@ Path createTempDir(const Path & tmpRoot, const Path & prefix, , mode #endif ) == 0) { -#if __FreeBSD__ +#ifdef __FreeBSD__ /* Explicitly set the group of the directory. This is to work around around problems caused by BSD's group ownership semantics (directories inherit the group of @@ -630,62 +642,6 @@ void replaceSymlink(const fs::path & target, const fs::path & link) } } -void setWriteTime( - const fs::path & path, - time_t accessedTime, - time_t modificationTime, - std::optional optIsSymlink) -{ -#ifdef _WIN32 - // FIXME use `fs::last_write_time`. - // - // Would be nice to use std::filesystem unconditionally, but - // doesn't support access time just modification time. - // - // System clock vs File clock issues also make that annoying. - warn("Changing file times is not yet implemented on Windows, path is %s", path); -#elif HAVE_UTIMENSAT && HAVE_DECL_AT_SYMLINK_NOFOLLOW - struct timespec times[2] = { - { - .tv_sec = accessedTime, - .tv_nsec = 0, - }, - { - .tv_sec = modificationTime, - .tv_nsec = 0, - }, - }; - if (utimensat(AT_FDCWD, path.c_str(), times, AT_SYMLINK_NOFOLLOW) == -1) - throw SysError("changing modification time of %s (using `utimensat`)", path); -#else - struct timeval times[2] = { - { - .tv_sec = accessedTime, - .tv_usec = 0, - }, - { - .tv_sec = modificationTime, - .tv_usec = 0, - }, - }; -#if HAVE_LUTIMES - if (lutimes(path.c_str(), times) == -1) - throw SysError("changing modification time of %s", path); -#else - bool isSymlink = optIsSymlink - ? *optIsSymlink - : fs::is_symlink(path); - - if (!isSymlink) { - if (utimes(path.c_str(), times) == -1) - throw SysError("changing modification time of %s (not a symlink)", path); - } else { - throw Error("Cannot modification time of symlink %s", path); - } -#endif -#endif -} - void setWriteTime(const fs::path & path, const struct stat & st) { setWriteTime(path, st.st_atime, st.st_mtime, S_ISLNK(st.st_mode)); diff --git a/src/libutil/fs-sink.cc b/src/libutil/fs-sink.cc index fadba5972..7b8fc3b2a 100644 --- a/src/libutil/fs-sink.cc +++ b/src/libutil/fs-sink.cc @@ -1,15 +1,17 @@ #include -#include "error.hh" -#include "config-global.hh" -#include "fs-sink.hh" +#include "nix/util/error.hh" +#include "nix/util/config-global.hh" +#include "nix/util/fs-sink.hh" -#if _WIN32 +#ifdef _WIN32 # include -# include "file-path.hh" -# include "windows-error.hh" +# include "nix/util/file-path.hh" +# include "nix/util/windows-error.hh" #endif +#include "util-config-private.hh" + namespace nix { void copyRecursive( diff --git a/src/libutil/git.cc b/src/libutil/git.cc index 3303dbc32..45cda1c2c 100644 --- a/src/libutil/git.cc +++ b/src/libutil/git.cc @@ -5,12 +5,12 @@ #include #include // for strcasecmp -#include "signals.hh" -#include "config.hh" -#include "hash.hh" +#include "nix/util/signals.hh" +#include "nix/util/configuration.hh" +#include "nix/util/hash.hh" -#include "git.hh" -#include "serialise.hh" +#include "nix/util/git.hh" +#include "nix/util/serialise.hh" namespace nix::git { @@ -33,7 +33,7 @@ std::optional decodeMode(RawMode m) { static std::string getStringUntil(Source & source, char byte) { std::string s; - char n[1]; + char n[1] = { 0 }; source(std::string_view { n, 1 }); while (*n != byte) { s += *n; diff --git a/src/libutil/hash.cc b/src/libutil/hash.cc index a248ba14c..b0f09583b 100644 --- a/src/libutil/hash.cc +++ b/src/libutil/hash.cc @@ -6,11 +6,11 @@ #include #include -#include "args.hh" -#include "hash.hh" -#include "archive.hh" -#include "config.hh" -#include "split.hh" +#include "nix/util/args.hh" +#include "nix/util/hash.hh" +#include "nix/util/archive.hh" +#include "nix/util/configuration.hh" +#include "nix/util/split.hh" #include #include diff --git a/src/libutil/hilite.cc b/src/libutil/hilite.cc index e5088230d..cfadd6af9 100644 --- a/src/libutil/hilite.cc +++ b/src/libutil/hilite.cc @@ -1,4 +1,4 @@ -#include "hilite.hh" +#include "nix/util/hilite.hh" namespace nix { diff --git a/src/libutil/abstract-setting-to-json.hh b/src/libutil/include/nix/util/abstract-setting-to-json.hh similarity index 83% rename from src/libutil/abstract-setting-to-json.hh rename to src/libutil/include/nix/util/abstract-setting-to-json.hh index eea687d8a..2848f8afe 100644 --- a/src/libutil/abstract-setting-to-json.hh +++ b/src/libutil/include/nix/util/abstract-setting-to-json.hh @@ -2,8 +2,8 @@ ///@file #include -#include "config.hh" -#include "json-utils.hh" +#include "nix/util/configuration.hh" +#include "nix/util/json-utils.hh" namespace nix { template diff --git a/src/libutil/ansicolor.hh b/src/libutil/include/nix/util/ansicolor.hh similarity index 100% rename from src/libutil/ansicolor.hh rename to src/libutil/include/nix/util/ansicolor.hh diff --git a/src/libutil/archive.hh b/src/libutil/include/nix/util/archive.hh similarity index 95% rename from src/libutil/archive.hh rename to src/libutil/include/nix/util/archive.hh index c38fa8a46..ae3274fa6 100644 --- a/src/libutil/archive.hh +++ b/src/libutil/include/nix/util/archive.hh @@ -1,9 +1,9 @@ #pragma once ///@file -#include "types.hh" -#include "serialise.hh" -#include "fs-sink.hh" +#include "nix/util/types.hh" +#include "nix/util/serialise.hh" +#include "nix/util/fs-sink.hh" namespace nix { diff --git a/src/libutil/args.hh b/src/libutil/include/nix/util/args.hh similarity index 99% rename from src/libutil/args.hh rename to src/libutil/include/nix/util/args.hh index c30d6cef8..77c4fb5b6 100644 --- a/src/libutil/args.hh +++ b/src/libutil/include/nix/util/args.hh @@ -9,9 +9,9 @@ #include -#include "types.hh" -#include "experimental-features.hh" -#include "ref.hh" +#include "nix/util/types.hh" +#include "nix/util/experimental-features.hh" +#include "nix/util/ref.hh" namespace nix { diff --git a/src/libutil/args/root.hh b/src/libutil/include/nix/util/args/root.hh similarity index 98% rename from src/libutil/args/root.hh rename to src/libutil/include/nix/util/args/root.hh index 34a43b538..cdc9be613 100644 --- a/src/libutil/args/root.hh +++ b/src/libutil/include/nix/util/args/root.hh @@ -1,6 +1,6 @@ #pragma once -#include "args.hh" +#include "nix/util/args.hh" namespace nix { diff --git a/src/libutil/callback.hh b/src/libutil/include/nix/util/callback.hh similarity index 100% rename from src/libutil/callback.hh rename to src/libutil/include/nix/util/callback.hh diff --git a/src/libutil/canon-path.hh b/src/libutil/include/nix/util/canon-path.hh similarity index 100% rename from src/libutil/canon-path.hh rename to src/libutil/include/nix/util/canon-path.hh diff --git a/src/libutil/checked-arithmetic.hh b/src/libutil/include/nix/util/checked-arithmetic.hh similarity index 100% rename from src/libutil/checked-arithmetic.hh rename to src/libutil/include/nix/util/checked-arithmetic.hh diff --git a/src/libutil/chunked-vector.hh b/src/libutil/include/nix/util/chunked-vector.hh similarity index 98% rename from src/libutil/chunked-vector.hh rename to src/libutil/include/nix/util/chunked-vector.hh index 4709679a6..96a717556 100644 --- a/src/libutil/chunked-vector.hh +++ b/src/libutil/include/nix/util/chunked-vector.hh @@ -6,7 +6,7 @@ #include #include -#include "error.hh" +#include "nix/util/error.hh" namespace nix { diff --git a/src/libutil/closure.hh b/src/libutil/include/nix/util/closure.hh similarity index 98% rename from src/libutil/closure.hh rename to src/libutil/include/nix/util/closure.hh index 16e3b93e4..54b18ab3d 100644 --- a/src/libutil/closure.hh +++ b/src/libutil/include/nix/util/closure.hh @@ -3,7 +3,7 @@ #include #include -#include "sync.hh" +#include "nix/util/sync.hh" using std::set; diff --git a/src/libutil/comparator.hh b/src/libutil/include/nix/util/comparator.hh similarity index 100% rename from src/libutil/comparator.hh rename to src/libutil/include/nix/util/comparator.hh diff --git a/src/libutil/compression.hh b/src/libutil/include/nix/util/compression.hh similarity index 89% rename from src/libutil/compression.hh rename to src/libutil/include/nix/util/compression.hh index e0c531b1f..15d869e88 100644 --- a/src/libutil/compression.hh +++ b/src/libutil/include/nix/util/compression.hh @@ -1,9 +1,9 @@ #pragma once ///@file -#include "ref.hh" -#include "types.hh" -#include "serialise.hh" +#include "nix/util/ref.hh" +#include "nix/util/types.hh" +#include "nix/util/serialise.hh" #include diff --git a/src/libutil/compute-levels.hh b/src/libutil/include/nix/util/compute-levels.hh similarity index 71% rename from src/libutil/compute-levels.hh rename to src/libutil/include/nix/util/compute-levels.hh index 093e7a915..401547793 100644 --- a/src/libutil/compute-levels.hh +++ b/src/libutil/include/nix/util/compute-levels.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "types.hh" +#include "nix/util/types.hh" namespace nix { diff --git a/src/libutil/config-global.hh b/src/libutil/include/nix/util/config-global.hh similarity index 94% rename from src/libutil/config-global.hh rename to src/libutil/include/nix/util/config-global.hh index 2caf51524..b47ee0ad1 100644 --- a/src/libutil/config-global.hh +++ b/src/libutil/include/nix/util/config-global.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "config.hh" +#include "nix/util/configuration.hh" namespace nix { diff --git a/src/libutil/config-impl.hh b/src/libutil/include/nix/util/config-impl.hh similarity index 98% rename from src/libutil/config-impl.hh rename to src/libutil/include/nix/util/config-impl.hh index 94c2cb2e4..15e0c9554 100644 --- a/src/libutil/config-impl.hh +++ b/src/libutil/include/nix/util/config-impl.hh @@ -12,8 +12,8 @@ * instantiation. */ -#include "config.hh" -#include "args.hh" +#include "nix/util/configuration.hh" +#include "nix/util/args.hh" namespace nix { diff --git a/src/libutil/config.hh b/src/libutil/include/nix/util/configuration.hh similarity index 99% rename from src/libutil/config.hh rename to src/libutil/include/nix/util/configuration.hh index 5cf146187..cf51d4818 100644 --- a/src/libutil/config.hh +++ b/src/libutil/include/nix/util/configuration.hh @@ -7,8 +7,8 @@ #include -#include "types.hh" -#include "experimental-features.hh" +#include "nix/util/types.hh" +#include "nix/util/experimental-features.hh" namespace nix { diff --git a/src/libutil/current-process.hh b/src/libutil/include/nix/util/current-process.hh similarity index 96% rename from src/libutil/current-process.hh rename to src/libutil/include/nix/util/current-process.hh index 660dcfe0b..b2c92a34c 100644 --- a/src/libutil/current-process.hh +++ b/src/libutil/include/nix/util/current-process.hh @@ -7,7 +7,7 @@ # include #endif -#include "types.hh" +#include "nix/util/types.hh" namespace nix { diff --git a/src/libutil/english.hh b/src/libutil/include/nix/util/english.hh similarity index 100% rename from src/libutil/english.hh rename to src/libutil/include/nix/util/english.hh diff --git a/src/libutil/environment-variables.hh b/src/libutil/include/nix/util/environment-variables.hh similarity index 95% rename from src/libutil/environment-variables.hh rename to src/libutil/include/nix/util/environment-variables.hh index 1a95f5c97..d6c7472fc 100644 --- a/src/libutil/environment-variables.hh +++ b/src/libutil/include/nix/util/environment-variables.hh @@ -8,8 +8,8 @@ #include -#include "types.hh" -#include "file-path.hh" +#include "nix/util/types.hh" +#include "nix/util/file-path.hh" namespace nix { diff --git a/src/libutil/error.hh b/src/libutil/include/nix/util/error.hh similarity index 98% rename from src/libutil/error.hh rename to src/libutil/include/nix/util/error.hh index 04fa18e35..fa60d4c61 100644 --- a/src/libutil/error.hh +++ b/src/libutil/include/nix/util/error.hh @@ -15,8 +15,8 @@ * See libutil/tests/logging.cc for usage examples. */ -#include "suggestions.hh" -#include "fmt.hh" +#include "nix/util/suggestions.hh" +#include "nix/util/fmt.hh" #include #include @@ -51,7 +51,7 @@ struct LinesOfCode { }; /* NOTE: position.hh recursively depends on source-path.hh -> source-accessor.hh - -> hash.hh -> config.hh -> experimental-features.hh -> error.hh -> Pos. + -> hash.hh -> configuration.hh -> experimental-features.hh -> error.hh -> Pos. There are other such cycles. Thus, Pos has to be an incomplete type in this header. But since ErrorInfo/Trace have to refer to Pos, they have to use pointer indirection via std::shared_ptr diff --git a/src/libutil/exec.hh b/src/libutil/include/nix/util/exec.hh similarity index 89% rename from src/libutil/exec.hh rename to src/libutil/include/nix/util/exec.hh index cbbe80c4e..a362cef35 100644 --- a/src/libutil/exec.hh +++ b/src/libutil/include/nix/util/exec.hh @@ -1,6 +1,6 @@ #pragma once -#include "os-string.hh" +#include "nix/util/os-string.hh" namespace nix { diff --git a/src/libutil/executable-path.hh b/src/libutil/include/nix/util/executable-path.hh similarity index 98% rename from src/libutil/executable-path.hh rename to src/libutil/include/nix/util/executable-path.hh index c5cfa1c39..700d296d5 100644 --- a/src/libutil/executable-path.hh +++ b/src/libutil/include/nix/util/executable-path.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "file-system.hh" +#include "nix/util/file-system.hh" namespace nix { diff --git a/src/libutil/exit.hh b/src/libutil/include/nix/util/exit.hh similarity index 100% rename from src/libutil/exit.hh rename to src/libutil/include/nix/util/exit.hh diff --git a/src/libutil/experimental-features.hh b/src/libutil/include/nix/util/experimental-features.hh similarity index 97% rename from src/libutil/experimental-features.hh rename to src/libutil/include/nix/util/experimental-features.hh index e349b5031..24cee610b 100644 --- a/src/libutil/experimental-features.hh +++ b/src/libutil/include/nix/util/experimental-features.hh @@ -1,8 +1,8 @@ #pragma once ///@file -#include "error.hh" -#include "types.hh" +#include "nix/util/error.hh" +#include "nix/util/types.hh" #include diff --git a/src/libutil/file-content-address.hh b/src/libutil/include/nix/util/file-content-address.hh similarity index 99% rename from src/libutil/file-content-address.hh rename to src/libutil/include/nix/util/file-content-address.hh index 226068387..0922604f8 100644 --- a/src/libutil/file-content-address.hh +++ b/src/libutil/include/nix/util/file-content-address.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "source-accessor.hh" +#include "nix/util/source-accessor.hh" namespace nix { diff --git a/src/libutil/file-descriptor.hh b/src/libutil/include/nix/util/file-descriptor.hh similarity index 98% rename from src/libutil/file-descriptor.hh rename to src/libutil/include/nix/util/file-descriptor.hh index fde362999..4f13a9a8f 100644 --- a/src/libutil/file-descriptor.hh +++ b/src/libutil/include/nix/util/file-descriptor.hh @@ -1,8 +1,8 @@ #pragma once ///@file -#include "types.hh" -#include "error.hh" +#include "nix/util/types.hh" +#include "nix/util/error.hh" #ifdef _WIN32 # define WIN32_LEAN_AND_MEAN @@ -18,7 +18,7 @@ struct Source; * Operating System capability */ using Descriptor = -#if _WIN32 +#ifdef _WIN32 HANDLE #else int @@ -26,7 +26,7 @@ using Descriptor = ; const Descriptor INVALID_DESCRIPTOR = -#if _WIN32 +#ifdef _WIN32 INVALID_HANDLE_VALUE #else -1 diff --git a/src/libutil/file-path-impl.hh b/src/libutil/include/nix/util/file-path-impl.hh similarity index 100% rename from src/libutil/file-path-impl.hh rename to src/libutil/include/nix/util/file-path-impl.hh diff --git a/src/libutil/file-path.hh b/src/libutil/include/nix/util/file-path.hh similarity index 93% rename from src/libutil/file-path.hh rename to src/libutil/include/nix/util/file-path.hh index 8e4a88b9d..deff076f1 100644 --- a/src/libutil/file-path.hh +++ b/src/libutil/include/nix/util/file-path.hh @@ -3,8 +3,8 @@ #include -#include "types.hh" -#include "os-string.hh" +#include "nix/util/types.hh" +#include "nix/util/os-string.hh" namespace nix { diff --git a/src/libutil/file-system.hh b/src/libutil/include/nix/util/file-system.hh similarity index 95% rename from src/libutil/file-system.hh rename to src/libutil/include/nix/util/file-system.hh index 204907339..acae88306 100644 --- a/src/libutil/file-system.hh +++ b/src/libutil/include/nix/util/file-system.hh @@ -5,11 +5,11 @@ * Utiltities for working with the file sytem and file paths. */ -#include "types.hh" -#include "error.hh" -#include "logging.hh" -#include "file-descriptor.hh" -#include "file-path.hh" +#include "nix/util/types.hh" +#include "nix/util/error.hh" +#include "nix/util/logging.hh" +#include "nix/util/file-descriptor.hh" +#include "nix/util/file-path.hh" #include #include @@ -134,6 +134,7 @@ bool pathExists(const Path & path); namespace fs { /** + * TODO: we may actually want to use pathExists instead of this function * ``` * symlink_exists(p) = std::filesystem::exists(std::filesystem::symlink_status(p)) * ``` @@ -142,9 +143,7 @@ namespace fs { * std::filesystem::exists(p) = std::filesystem::exists(std::filesystem::status(p)) * ``` */ -inline bool symlink_exists(const std::filesystem::path & path) { - return std::filesystem::exists(std::filesystem::symlink_status(path)); -} +bool symlink_exists(const std::filesystem::path & path); } // namespace fs @@ -231,14 +230,9 @@ void deletePath(const std::filesystem::path & path, uint64_t & bytesFreed); /** * Create a directory and all its parents, if necessary. * - * In the process of being deprecated for - * `std::filesystem::create_directories`. + * Wrapper around `std::filesystem::create_directories` to handle exceptions. */ -void createDirs(const Path & path); -inline void createDirs(PathView path) -{ - return createDirs(Path(path)); -} +void createDirs(const std::filesystem::path & path); /** * Create a single directory. diff --git a/src/libutil/finally.hh b/src/libutil/include/nix/util/finally.hh similarity index 100% rename from src/libutil/finally.hh rename to src/libutil/include/nix/util/finally.hh diff --git a/src/libutil/fmt.hh b/src/libutil/include/nix/util/fmt.hh similarity index 99% rename from src/libutil/fmt.hh rename to src/libutil/include/nix/util/fmt.hh index 850b7162d..5435a4ebf 100644 --- a/src/libutil/fmt.hh +++ b/src/libutil/include/nix/util/fmt.hh @@ -3,7 +3,7 @@ #include #include -#include "ansicolor.hh" +#include "nix/util/ansicolor.hh" namespace nix { diff --git a/src/libutil/fs-sink.hh b/src/libutil/include/nix/util/fs-sink.hh similarity index 96% rename from src/libutil/fs-sink.hh rename to src/libutil/include/nix/util/fs-sink.hh index 5c5073731..1c34fba93 100644 --- a/src/libutil/fs-sink.hh +++ b/src/libutil/include/nix/util/fs-sink.hh @@ -1,9 +1,9 @@ #pragma once ///@file -#include "serialise.hh" -#include "source-accessor.hh" -#include "file-system.hh" +#include "nix/util/serialise.hh" +#include "nix/util/source-accessor.hh" +#include "nix/util/file-system.hh" namespace nix { diff --git a/src/libutil/git.hh b/src/libutil/include/nix/util/git.hh similarity index 97% rename from src/libutil/git.hh rename to src/libutil/include/nix/util/git.hh index 1a6a7c333..9bdb30bb9 100644 --- a/src/libutil/git.hh +++ b/src/libutil/include/nix/util/git.hh @@ -5,11 +5,11 @@ #include #include -#include "types.hh" -#include "serialise.hh" -#include "hash.hh" -#include "source-path.hh" -#include "fs-sink.hh" +#include "nix/util/types.hh" +#include "nix/util/serialise.hh" +#include "nix/util/hash.hh" +#include "nix/util/source-path.hh" +#include "nix/util/fs-sink.hh" namespace nix::git { diff --git a/src/libutil/hash.hh b/src/libutil/include/nix/util/hash.hh similarity index 97% rename from src/libutil/hash.hh rename to src/libutil/include/nix/util/hash.hh index c333bd424..12de4a6ac 100644 --- a/src/libutil/hash.hh +++ b/src/libutil/include/nix/util/hash.hh @@ -1,10 +1,10 @@ #pragma once ///@file -#include "config.hh" -#include "types.hh" -#include "serialise.hh" -#include "file-system.hh" +#include "nix/util/configuration.hh" +#include "nix/util/types.hh" +#include "nix/util/serialise.hh" +#include "nix/util/file-system.hh" #include diff --git a/src/libutil/hilite.hh b/src/libutil/include/nix/util/hilite.hh similarity index 100% rename from src/libutil/hilite.hh rename to src/libutil/include/nix/util/hilite.hh diff --git a/src/libutil/json-impls.hh b/src/libutil/include/nix/util/json-impls.hh similarity index 95% rename from src/libutil/json-impls.hh rename to src/libutil/include/nix/util/json-impls.hh index b26163a04..9dd344c50 100644 --- a/src/libutil/json-impls.hh +++ b/src/libutil/include/nix/util/json-impls.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "nlohmann/json_fwd.hpp" +#include // Following https://github.com/nlohmann/json#how-can-i-use-get-for-non-default-constructiblenon-copyable-types #define JSON_IMPL(TYPE) \ diff --git a/src/libutil/json-utils.hh b/src/libutil/include/nix/util/json-utils.hh similarity index 99% rename from src/libutil/json-utils.hh rename to src/libutil/include/nix/util/json-utils.hh index 1afc5d796..9308d4392 100644 --- a/src/libutil/json-utils.hh +++ b/src/libutil/include/nix/util/json-utils.hh @@ -4,7 +4,7 @@ #include #include -#include "types.hh" +#include "nix/util/types.hh" namespace nix { diff --git a/src/libutil/logging.hh b/src/libutil/include/nix/util/logging.hh similarity index 98% rename from src/libutil/logging.hh rename to src/libutil/include/nix/util/logging.hh index 07f49be19..1cb4161d1 100644 --- a/src/libutil/logging.hh +++ b/src/libutil/include/nix/util/logging.hh @@ -1,10 +1,10 @@ #pragma once ///@file -#include "error.hh" -#include "config.hh" -#include "file-descriptor.hh" -#include "finally.hh" +#include "nix/util/error.hh" +#include "nix/util/configuration.hh" +#include "nix/util/file-descriptor.hh" +#include "nix/util/finally.hh" #include diff --git a/src/libutil/lru-cache.hh b/src/libutil/include/nix/util/lru-cache.hh similarity index 100% rename from src/libutil/lru-cache.hh rename to src/libutil/include/nix/util/lru-cache.hh diff --git a/src/libutil/memory-source-accessor.hh b/src/libutil/include/nix/util/memory-source-accessor.hh similarity index 97% rename from src/libutil/memory-source-accessor.hh rename to src/libutil/include/nix/util/memory-source-accessor.hh index 012a388c0..d09ba153d 100644 --- a/src/libutil/memory-source-accessor.hh +++ b/src/libutil/include/nix/util/memory-source-accessor.hh @@ -1,6 +1,6 @@ -#include "source-path.hh" -#include "fs-sink.hh" -#include "variant-wrapper.hh" +#include "nix/util/source-path.hh" +#include "nix/util/fs-sink.hh" +#include "nix/util/variant-wrapper.hh" namespace nix { diff --git a/src/libutil/include/nix/util/meson.build b/src/libutil/include/nix/util/meson.build new file mode 100644 index 000000000..329d40612 --- /dev/null +++ b/src/libutil/include/nix/util/meson.build @@ -0,0 +1,83 @@ +# Public headers directory + +include_dirs = [include_directories('../..')] + +headers = files( + 'abstract-setting-to-json.hh', + 'ansicolor.hh', + 'archive.hh', + 'args.hh', + 'args/root.hh', + 'callback.hh', + 'canon-path.hh', + 'checked-arithmetic.hh', + 'chunked-vector.hh', + 'closure.hh', + 'comparator.hh', + 'compression.hh', + 'compute-levels.hh', + 'config-global.hh', + 'config-impl.hh', + 'configuration.hh', + 'current-process.hh', + 'english.hh', + 'environment-variables.hh', + 'error.hh', + 'exec.hh', + 'executable-path.hh', + 'exit.hh', + 'experimental-features.hh', + 'file-content-address.hh', + 'file-descriptor.hh', + 'file-path-impl.hh', + 'file-path.hh', + 'file-system.hh', + 'finally.hh', + 'fmt.hh', + 'fs-sink.hh', + 'git.hh', + 'hash.hh', + 'hilite.hh', + 'json-impls.hh', + 'json-utils.hh', + 'logging.hh', + 'lru-cache.hh', + 'memory-source-accessor.hh', + 'mounted-source-accessor.hh', + 'muxable-pipe.hh', + 'os-string.hh', + 'pool.hh', + 'pos-idx.hh', + 'pos-table.hh', + 'position.hh', + 'posix-source-accessor.hh', + 'processes.hh', + 'ref.hh', + 'references.hh', + 'regex-combinators.hh', + 'repair-flag.hh', + 'serialise.hh', + 'signals.hh', + 'signature/local-keys.hh', + 'signature/signer.hh', + 'source-accessor.hh', + 'source-path.hh', + 'split.hh', + 'std-hash.hh', + 'strings.hh', + 'strings-inline.hh', + 'suggestions.hh', + 'sync.hh', + 'tarfile.hh', + 'terminal.hh', + 'thread-pool.hh', + 'topo-sort.hh', + 'types.hh', + 'unix-domain-socket.hh', + 'url-parts.hh', + 'url.hh', + 'users.hh', + 'util.hh', + 'variant-wrapper.hh', + 'xml-writer.hh', +) diff --git a/src/libutil/mounted-source-accessor.hh b/src/libutil/include/nix/util/mounted-source-accessor.hh similarity index 100% rename from src/libutil/mounted-source-accessor.hh rename to src/libutil/include/nix/util/mounted-source-accessor.hh diff --git a/src/libutil/muxable-pipe.hh b/src/libutil/include/nix/util/muxable-pipe.hh similarity index 93% rename from src/libutil/muxable-pipe.hh rename to src/libutil/include/nix/util/muxable-pipe.hh index 53ac39170..d912627fb 100644 --- a/src/libutil/muxable-pipe.hh +++ b/src/libutil/include/nix/util/muxable-pipe.hh @@ -1,16 +1,16 @@ #pragma once ///@file -#include "file-descriptor.hh" +#include "nix/util/file-descriptor.hh" #ifdef _WIN32 -# include "windows-async-pipe.hh" +# include "nix/util/windows-async-pipe.hh" #endif #ifndef _WIN32 # include #else # include -# include "windows-error.hh" +# include "nix/util/windows-error.hh" #endif namespace nix { diff --git a/src/libutil/os-string.hh b/src/libutil/include/nix/util/os-string.hh similarity index 100% rename from src/libutil/os-string.hh rename to src/libutil/include/nix/util/os-string.hh diff --git a/src/libutil/pool.hh b/src/libutil/include/nix/util/pool.hh similarity index 98% rename from src/libutil/pool.hh rename to src/libutil/include/nix/util/pool.hh index b2ceb7143..a63db50de 100644 --- a/src/libutil/pool.hh +++ b/src/libutil/include/nix/util/pool.hh @@ -7,8 +7,8 @@ #include #include -#include "sync.hh" -#include "ref.hh" +#include "nix/util/sync.hh" +#include "nix/util/ref.hh" namespace nix { diff --git a/src/libutil/pos-idx.hh b/src/libutil/include/nix/util/pos-idx.hh similarity index 100% rename from src/libutil/pos-idx.hh rename to src/libutil/include/nix/util/pos-idx.hh diff --git a/src/libutil/pos-table.hh b/src/libutil/include/nix/util/pos-table.hh similarity index 96% rename from src/libutil/pos-table.hh rename to src/libutil/include/nix/util/pos-table.hh index a6fe09d79..ef170e0f1 100644 --- a/src/libutil/pos-table.hh +++ b/src/libutil/include/nix/util/pos-table.hh @@ -4,9 +4,9 @@ #include #include -#include "pos-idx.hh" -#include "position.hh" -#include "sync.hh" +#include "nix/util/pos-idx.hh" +#include "nix/util/position.hh" +#include "nix/util/sync.hh" namespace nix { diff --git a/src/libutil/position.hh b/src/libutil/include/nix/util/position.hh similarity index 98% rename from src/libutil/position.hh rename to src/libutil/include/nix/util/position.hh index 07e261c4c..f9c984976 100644 --- a/src/libutil/position.hh +++ b/src/libutil/include/nix/util/position.hh @@ -9,7 +9,7 @@ #include #include -#include "source-path.hh" +#include "nix/util/source-path.hh" namespace nix { diff --git a/src/libutil/posix-source-accessor.hh b/src/libutil/include/nix/util/posix-source-accessor.hh similarity index 98% rename from src/libutil/posix-source-accessor.hh rename to src/libutil/include/nix/util/posix-source-accessor.hh index 5d491e633..ea65b148f 100644 --- a/src/libutil/posix-source-accessor.hh +++ b/src/libutil/include/nix/util/posix-source-accessor.hh @@ -1,6 +1,6 @@ #pragma once -#include "source-accessor.hh" +#include "nix/util/source-accessor.hh" namespace nix { diff --git a/src/libutil/processes.hh b/src/libutil/include/nix/util/processes.hh similarity index 94% rename from src/libutil/processes.hh rename to src/libutil/include/nix/util/processes.hh index bbbe7dcab..ef7bddf2f 100644 --- a/src/libutil/processes.hh +++ b/src/libutil/include/nix/util/processes.hh @@ -1,11 +1,11 @@ #pragma once ///@file -#include "types.hh" -#include "error.hh" -#include "file-descriptor.hh" -#include "logging.hh" -#include "ansicolor.hh" +#include "nix/util/types.hh" +#include "nix/util/error.hh" +#include "nix/util/file-descriptor.hh" +#include "nix/util/logging.hh" +#include "nix/util/ansicolor.hh" #include #include diff --git a/src/libutil/ref.hh b/src/libutil/include/nix/util/ref.hh similarity index 100% rename from src/libutil/ref.hh rename to src/libutil/include/nix/util/ref.hh diff --git a/src/libutil/references.hh b/src/libutil/include/nix/util/references.hh similarity index 97% rename from src/libutil/references.hh rename to src/libutil/include/nix/util/references.hh index 8bc9f7ec9..89a42e009 100644 --- a/src/libutil/references.hh +++ b/src/libutil/include/nix/util/references.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "hash.hh" +#include "nix/util/hash.hh" namespace nix { diff --git a/src/libutil/regex-combinators.hh b/src/libutil/include/nix/util/regex-combinators.hh similarity index 100% rename from src/libutil/regex-combinators.hh rename to src/libutil/include/nix/util/regex-combinators.hh diff --git a/src/libutil/repair-flag.hh b/src/libutil/include/nix/util/repair-flag.hh similarity index 100% rename from src/libutil/repair-flag.hh rename to src/libutil/include/nix/util/repair-flag.hh diff --git a/src/libutil/serialise.hh b/src/libutil/include/nix/util/serialise.hh similarity index 99% rename from src/libutil/serialise.hh rename to src/libutil/include/nix/util/serialise.hh index 14721d069..d28c8e9a6 100644 --- a/src/libutil/serialise.hh +++ b/src/libutil/include/nix/util/serialise.hh @@ -4,9 +4,9 @@ #include #include -#include "types.hh" -#include "util.hh" -#include "file-descriptor.hh" +#include "nix/util/types.hh" +#include "nix/util/util.hh" +#include "nix/util/file-descriptor.hh" namespace boost::context { struct stack_context; } diff --git a/src/libutil/signals.hh b/src/libutil/include/nix/util/signals.hh similarity index 89% rename from src/libutil/signals.hh rename to src/libutil/include/nix/util/signals.hh index 8bff345c3..45130a90c 100644 --- a/src/libutil/signals.hh +++ b/src/libutil/include/nix/util/signals.hh @@ -1,9 +1,9 @@ #pragma once ///@file -#include "types.hh" -#include "error.hh" -#include "logging.hh" +#include "nix/util/types.hh" +#include "nix/util/error.hh" +#include "nix/util/logging.hh" #include @@ -62,4 +62,4 @@ struct ReceiveInterrupts; } -#include "signals-impl.hh" +#include "nix/util/signals-impl.hh" diff --git a/src/libutil/signature/local-keys.hh b/src/libutil/include/nix/util/signature/local-keys.hh similarity index 98% rename from src/libutil/signature/local-keys.hh rename to src/libutil/include/nix/util/signature/local-keys.hh index 9977f0dac..85918f906 100644 --- a/src/libutil/signature/local-keys.hh +++ b/src/libutil/include/nix/util/signature/local-keys.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "types.hh" +#include "nix/util/types.hh" #include diff --git a/src/libutil/signature/signer.hh b/src/libutil/include/nix/util/signature/signer.hh similarity index 94% rename from src/libutil/signature/signer.hh rename to src/libutil/include/nix/util/signature/signer.hh index e50170fe2..ca2905eef 100644 --- a/src/libutil/signature/signer.hh +++ b/src/libutil/include/nix/util/signature/signer.hh @@ -1,7 +1,7 @@ #pragma once -#include "types.hh" -#include "signature/local-keys.hh" +#include "nix/util/types.hh" +#include "nix/util/signature/local-keys.hh" #include #include diff --git a/src/libutil/source-accessor.hh b/src/libutil/include/nix/util/source-accessor.hh similarity index 98% rename from src/libutil/source-accessor.hh rename to src/libutil/include/nix/util/source-accessor.hh index a069e024d..90e39207b 100644 --- a/src/libutil/source-accessor.hh +++ b/src/libutil/include/nix/util/source-accessor.hh @@ -2,9 +2,9 @@ #include -#include "canon-path.hh" -#include "hash.hh" -#include "ref.hh" +#include "nix/util/canon-path.hh" +#include "nix/util/hash.hh" +#include "nix/util/ref.hh" namespace nix { diff --git a/src/libutil/source-path.hh b/src/libutil/include/nix/util/source-path.hh similarity index 96% rename from src/libutil/source-path.hh rename to src/libutil/include/nix/util/source-path.hh index fc2288f74..c0cba0241 100644 --- a/src/libutil/source-path.hh +++ b/src/libutil/include/nix/util/source-path.hh @@ -5,10 +5,10 @@ * @brief SourcePath */ -#include "ref.hh" -#include "canon-path.hh" -#include "source-accessor.hh" -#include "std-hash.hh" +#include "nix/util/ref.hh" +#include "nix/util/canon-path.hh" +#include "nix/util/source-accessor.hh" +#include "nix/util/std-hash.hh" namespace nix { diff --git a/src/libutil/split.hh b/src/libutil/include/nix/util/split.hh similarity index 97% rename from src/libutil/split.hh rename to src/libutil/include/nix/util/split.hh index 3b9b2b83b..24a73fea8 100644 --- a/src/libutil/split.hh +++ b/src/libutil/include/nix/util/split.hh @@ -4,7 +4,7 @@ #include #include -#include "util.hh" +#include "nix/util/util.hh" namespace nix { diff --git a/src/libutil/std-hash.hh b/src/libutil/include/nix/util/std-hash.hh similarity index 100% rename from src/libutil/std-hash.hh rename to src/libutil/include/nix/util/std-hash.hh diff --git a/src/libutil/strings-inline.hh b/src/libutil/include/nix/util/strings-inline.hh similarity index 98% rename from src/libutil/strings-inline.hh rename to src/libutil/include/nix/util/strings-inline.hh index 25b8e0ff6..d99b686fc 100644 --- a/src/libutil/strings-inline.hh +++ b/src/libutil/include/nix/util/strings-inline.hh @@ -1,6 +1,6 @@ #pragma once -#include "strings.hh" +#include "nix/util/strings.hh" namespace nix { diff --git a/src/libutil/strings.hh b/src/libutil/include/nix/util/strings.hh similarity index 84% rename from src/libutil/strings.hh rename to src/libutil/include/nix/util/strings.hh index c4fd3daa1..521e3425f 100644 --- a/src/libutil/strings.hh +++ b/src/libutil/include/nix/util/strings.hh @@ -6,6 +6,8 @@ #include #include +#include + namespace nix { /* @@ -54,6 +56,21 @@ std::string concatStringsSep(const std::string_view sep, const C & ss); extern template std::string concatStringsSep(std::string_view, const std::list &); extern template std::string concatStringsSep(std::string_view, const std::set &); extern template std::string concatStringsSep(std::string_view, const std::vector &); +extern template std::string concatStringsSep(std::string_view, const boost::container::small_vector &); + +/** + * Apply a function to the `iterable`'s items and concat them with `separator`. + */ +template +std::string concatMapStringsSep(std::string_view separator, const C & iterable, F fn) +{ + boost::container::small_vector strings; + strings.reserve(iterable.size()); + for (const auto & elem : iterable) { + strings.push_back(fn(elem)); + } + return concatStringsSep(separator, strings); +} /** * Ignore any empty strings at the start of the list, and then concatenate the diff --git a/src/libutil/suggestions.hh b/src/libutil/include/nix/util/suggestions.hh similarity index 98% rename from src/libutil/suggestions.hh rename to src/libutil/include/nix/util/suggestions.hh index e39ab400c..16496379c 100644 --- a/src/libutil/suggestions.hh +++ b/src/libutil/include/nix/util/suggestions.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "types.hh" +#include "nix/util/types.hh" #include namespace nix { diff --git a/src/libutil/sync.hh b/src/libutil/include/nix/util/sync.hh similarity index 99% rename from src/libutil/sync.hh rename to src/libutil/include/nix/util/sync.hh index d340f3d97..0c3e1f528 100644 --- a/src/libutil/sync.hh +++ b/src/libutil/include/nix/util/sync.hh @@ -7,7 +7,7 @@ #include #include -#include "error.hh" +#include "nix/util/error.hh" namespace nix { diff --git a/src/libutil/tarfile.hh b/src/libutil/include/nix/util/tarfile.hh similarity index 95% rename from src/libutil/tarfile.hh rename to src/libutil/include/nix/util/tarfile.hh index 5e29c6bba..2005d13ca 100644 --- a/src/libutil/tarfile.hh +++ b/src/libutil/include/nix/util/tarfile.hh @@ -1,8 +1,8 @@ #pragma once ///@file -#include "serialise.hh" -#include "fs-sink.hh" +#include "nix/util/serialise.hh" +#include "nix/util/fs-sink.hh" #include namespace nix { diff --git a/src/libutil/terminal.hh b/src/libutil/include/nix/util/terminal.hh similarity index 100% rename from src/libutil/terminal.hh rename to src/libutil/include/nix/util/terminal.hh diff --git a/src/libutil/thread-pool.hh b/src/libutil/include/nix/util/thread-pool.hh similarity index 98% rename from src/libutil/thread-pool.hh rename to src/libutil/include/nix/util/thread-pool.hh index 4adc48657..92009e396 100644 --- a/src/libutil/thread-pool.hh +++ b/src/libutil/include/nix/util/thread-pool.hh @@ -1,8 +1,8 @@ #pragma once ///@file -#include "error.hh" -#include "sync.hh" +#include "nix/util/error.hh" +#include "nix/util/sync.hh" #include #include diff --git a/src/libutil/topo-sort.hh b/src/libutil/include/nix/util/topo-sort.hh similarity index 97% rename from src/libutil/topo-sort.hh rename to src/libutil/include/nix/util/topo-sort.hh index a52811fbf..77a9ce421 100644 --- a/src/libutil/topo-sort.hh +++ b/src/libutil/include/nix/util/topo-sort.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "error.hh" +#include "nix/util/error.hh" namespace nix { diff --git a/src/libutil/types.hh b/src/libutil/include/nix/util/types.hh similarity index 100% rename from src/libutil/types.hh rename to src/libutil/include/nix/util/types.hh diff --git a/src/libutil/unix-domain-socket.hh b/src/libutil/include/nix/util/unix-domain-socket.hh similarity index 95% rename from src/libutil/unix-domain-socket.hh rename to src/libutil/include/nix/util/unix-domain-socket.hh index e0d934011..ae98e9923 100644 --- a/src/libutil/unix-domain-socket.hh +++ b/src/libutil/include/nix/util/unix-domain-socket.hh @@ -1,8 +1,8 @@ #pragma once ///@file -#include "types.hh" -#include "file-descriptor.hh" +#include "nix/util/types.hh" +#include "nix/util/file-descriptor.hh" #ifdef _WIN32 # include diff --git a/src/libutil/url-parts.hh b/src/libutil/include/nix/util/url-parts.hh similarity index 100% rename from src/libutil/url-parts.hh rename to src/libutil/include/nix/util/url-parts.hh diff --git a/src/libutil/url.hh b/src/libutil/include/nix/util/url.hh similarity index 98% rename from src/libutil/url.hh rename to src/libutil/include/nix/util/url.hh index 2b12f5af2..ced846787 100644 --- a/src/libutil/url.hh +++ b/src/libutil/include/nix/util/url.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "error.hh" +#include "nix/util/error.hh" namespace nix { diff --git a/src/libutil/users.hh b/src/libutil/include/nix/util/users.hh similarity index 97% rename from src/libutil/users.hh rename to src/libutil/include/nix/util/users.hh index d22c3311d..1d467173c 100644 --- a/src/libutil/users.hh +++ b/src/libutil/include/nix/util/users.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "types.hh" +#include "nix/util/types.hh" #ifndef _WIN32 # include diff --git a/src/libutil/util.hh b/src/libutil/include/nix/util/util.hh similarity index 98% rename from src/libutil/util.hh rename to src/libutil/include/nix/util/util.hh index 0d55cf93b..5a4530798 100644 --- a/src/libutil/util.hh +++ b/src/libutil/include/nix/util/util.hh @@ -1,9 +1,9 @@ #pragma once ///@file -#include "types.hh" -#include "error.hh" -#include "logging.hh" +#include "nix/util/types.hh" +#include "nix/util/error.hh" +#include "nix/util/logging.hh" #include @@ -11,7 +11,7 @@ #include #include -#include "strings.hh" +#include "nix/util/strings.hh" namespace nix { diff --git a/src/libutil/variant-wrapper.hh b/src/libutil/include/nix/util/variant-wrapper.hh similarity index 100% rename from src/libutil/variant-wrapper.hh rename to src/libutil/include/nix/util/variant-wrapper.hh diff --git a/src/libutil/xml-writer.hh b/src/libutil/include/nix/util/xml-writer.hh similarity index 100% rename from src/libutil/xml-writer.hh rename to src/libutil/include/nix/util/xml-writer.hh diff --git a/src/libutil/json-utils.cc b/src/libutil/json-utils.cc index f67811e21..2c8edfce8 100644 --- a/src/libutil/json-utils.cc +++ b/src/libutil/json-utils.cc @@ -1,6 +1,6 @@ -#include "json-utils.hh" -#include "error.hh" -#include "types.hh" +#include "nix/util/json-utils.hh" +#include "nix/util/error.hh" +#include "nix/util/types.hh" #include #include #include diff --git a/src/libutil/linux/cgroup.cc b/src/libutil/linux/cgroup.cc index ad3e8a017..890797c91 100644 --- a/src/libutil/linux/cgroup.cc +++ b/src/libutil/linux/cgroup.cc @@ -1,8 +1,8 @@ -#include "cgroup.hh" -#include "signals.hh" -#include "util.hh" -#include "file-system.hh" -#include "finally.hh" +#include "nix/util/cgroup.hh" +#include "nix/util/signals.hh" +#include "nix/util/util.hh" +#include "nix/util/file-system.hh" +#include "nix/util/finally.hh" #include #include diff --git a/src/libutil/linux/cgroup.hh b/src/libutil/linux/include/nix/util/cgroup.hh similarity index 96% rename from src/libutil/linux/cgroup.hh rename to src/libutil/linux/include/nix/util/cgroup.hh index 87d135ba6..6a41c6b44 100644 --- a/src/libutil/linux/cgroup.hh +++ b/src/libutil/linux/include/nix/util/cgroup.hh @@ -4,7 +4,7 @@ #include #include -#include "types.hh" +#include "nix/util/types.hh" namespace nix { diff --git a/src/libutil/linux/include/nix/util/meson.build b/src/libutil/linux/include/nix/util/meson.build new file mode 100644 index 000000000..9587aa916 --- /dev/null +++ b/src/libutil/linux/include/nix/util/meson.build @@ -0,0 +1,8 @@ +# Public headers directory + +include_dirs += include_directories('../..') + +headers += files( + 'cgroup.hh', + 'namespaces.hh', +) diff --git a/src/libutil/linux/namespaces.hh b/src/libutil/linux/include/nix/util/namespaces.hh similarity index 95% rename from src/libutil/linux/namespaces.hh rename to src/libutil/linux/include/nix/util/namespaces.hh index 208920b80..59db745d3 100644 --- a/src/libutil/linux/namespaces.hh +++ b/src/libutil/linux/include/nix/util/namespaces.hh @@ -3,7 +3,7 @@ #include -#include "types.hh" +#include "nix/util/types.hh" namespace nix { diff --git a/src/libutil/linux/meson.build b/src/libutil/linux/meson.build index a1ded76ca..bfda8b1a6 100644 --- a/src/libutil/linux/meson.build +++ b/src/libutil/linux/meson.build @@ -3,9 +3,4 @@ sources += files( 'namespaces.cc', ) -include_dirs += include_directories('.') - -headers += files( - 'cgroup.hh', - 'namespaces.hh', -) +subdir('include/nix/util') diff --git a/src/libutil/linux/namespaces.cc b/src/libutil/linux/namespaces.cc index c5e21dffc..405866c0b 100644 --- a/src/libutil/linux/namespaces.cc +++ b/src/libutil/linux/namespaces.cc @@ -1,13 +1,13 @@ -#include "current-process.hh" -#include "util.hh" -#include "finally.hh" -#include "file-system.hh" -#include "processes.hh" -#include "signals.hh" +#include "nix/util/current-process.hh" +#include "nix/util/util.hh" +#include "nix/util/finally.hh" +#include "nix/util/file-system.hh" +#include "nix/util/processes.hh" +#include "nix/util/signals.hh" #include #include -#include "cgroup.hh" +#include "nix/util/cgroup.hh" #include diff --git a/src/libutil/logging.cc b/src/libutil/logging.cc index 617ebeb16..7aad5de2c 100644 --- a/src/libutil/logging.cc +++ b/src/libutil/logging.cc @@ -1,13 +1,13 @@ -#include "logging.hh" -#include "file-descriptor.hh" -#include "environment-variables.hh" -#include "terminal.hh" -#include "util.hh" -#include "config-global.hh" -#include "source-path.hh" -#include "position.hh" -#include "sync.hh" -#include "unix-domain-socket.hh" +#include "nix/util/logging.hh" +#include "nix/util/file-descriptor.hh" +#include "nix/util/environment-variables.hh" +#include "nix/util/terminal.hh" +#include "nix/util/util.hh" +#include "nix/util/config-global.hh" +#include "nix/util/source-path.hh" +#include "nix/util/position.hh" +#include "nix/util/sync.hh" +#include "nix/util/unix-domain-socket.hh" #include #include diff --git a/src/libutil/memory-source-accessor.cc b/src/libutil/memory-source-accessor.cc index c4eee1031..7764ff946 100644 --- a/src/libutil/memory-source-accessor.cc +++ b/src/libutil/memory-source-accessor.cc @@ -1,4 +1,4 @@ -#include "memory-source-accessor.hh" +#include "nix/util/memory-source-accessor.hh" namespace nix { diff --git a/src/libutil/meson.build b/src/libutil/meson.build index f698f04dd..9ecbdcd06 100644 --- a/src/libutil/meson.build +++ b/src/libutil/meson.build @@ -23,34 +23,20 @@ deps_public_maybe_subproject = [ subdir('nix-meson-build-support/subprojects') # Check for each of these functions, and create a define like `#define -# HAVE_LUTIMES 1`. The `#define` is unconditional, 0 for not found and 1 -# for found. One therefore uses it with `#if` not `#ifdef`. +# HAVE_POSIX_FALLOCATE 1`. The `#define` is unconditional, 0 for not +# found and 1 for found. One therefore uses it with `#if` not `#ifdef`. check_funcs = [ - 'close_range', - # Optionally used for changing the mtime of symlinks. - 'lutimes', - # Optionally used for creating pipes on Unix - 'pipe2', - # Optionally used to preallocate files to be large enough before - # writing to them. - 'posix_fallocate', - # Optionally used to get more information about processes failing due - # to a signal on Unix. - 'strsignal', - # Optionally used to try to close more file descriptors (e.g. before - # forking) on Unix. - 'sysconf', - # Optionally used for changing the mtime of files and symlinks. - 'utimensat', + [ + 'posix_fallocate', + 'Optionally used to preallocate files to be large enough before writing to them.', + ], ] foreach funcspec : check_funcs - define_name = 'HAVE_' + funcspec.underscorify().to_upper() - define_value = cxx.has_function(funcspec).to_int() - configdata.set(define_name, define_value) + define_name = 'HAVE_' + funcspec[0].underscorify().to_upper() + define_value = cxx.has_function(funcspec[0]).to_int() + configdata.set(define_name, define_value, description: funcspec[1]) endforeach -configdata.set('HAVE_DECL_AT_SYMLINK_NOFOLLOW', cxx.has_header_symbol('fcntl.h', 'AT_SYMLINK_NOFOLLOW').to_int()) - subdir('nix-meson-build-support/libatomic') if host_machine.system() == 'windows' @@ -114,27 +100,20 @@ deps_public += nlohmann_json cxx = meson.get_compiler('cpp') -config_h = configure_file( +config_priv_h = configure_file( configuration : configdata, - output : 'config-util.hh', -) - -add_project_arguments( - # TODO(Qyriad): Yes this is how the autoconf+Make system did it. - # It would be nice for our headers to be idempotent instead. - '-include', 'config-util.hh', - language : 'cpp', + output : 'util-config-private.hh', ) subdir('nix-meson-build-support/common') -sources = files( +sources = [config_priv_h] + files( 'archive.cc', 'args.cc', 'canon-path.cc', 'compression.cc', 'compute-levels.cc', - 'config.cc', + 'configuration.cc', 'config-global.cc', 'current-process.cc', 'english.cc', @@ -177,92 +156,13 @@ sources = files( 'xml-writer.cc', ) -include_dirs = [include_directories('.')] +subdir('include/nix/util') + if not cxx.has_header('widechar_width.h', required : false) # use vendored widechar_width.h include_dirs += include_directories('./widecharwidth') endif -headers = [config_h] + files( - 'abstract-setting-to-json.hh', - 'ansicolor.hh', - 'archive.hh', - 'args.hh', - 'args/root.hh', - 'callback.hh', - 'canon-path.hh', - 'checked-arithmetic.hh', - 'chunked-vector.hh', - 'closure.hh', - 'comparator.hh', - 'compression.hh', - 'compute-levels.hh', - 'config-global.hh', - 'config-impl.hh', - 'config.hh', - 'current-process.hh', - 'english.hh', - 'environment-variables.hh', - 'error.hh', - 'exec.hh', - 'executable-path.hh', - 'exit.hh', - 'experimental-features.hh', - 'file-content-address.hh', - 'file-descriptor.hh', - 'file-path-impl.hh', - 'file-path.hh', - 'file-system.hh', - 'finally.hh', - 'fmt.hh', - 'fs-sink.hh', - 'git.hh', - 'hash.hh', - 'hilite.hh', - 'json-impls.hh', - 'json-utils.hh', - 'logging.hh', - 'lru-cache.hh', - 'memory-source-accessor.hh', - 'mounted-source-accessor.hh', - 'muxable-pipe.hh', - 'os-string.hh', - 'pool.hh', - 'pos-idx.hh', - 'pos-table.hh', - 'position.hh', - 'posix-source-accessor.hh', - 'processes.hh', - 'ref.hh', - 'references.hh', - 'regex-combinators.hh', - 'repair-flag.hh', - 'serialise.hh', - 'signals.hh', - 'signature/local-keys.hh', - 'signature/signer.hh', - 'source-accessor.hh', - 'source-path.hh', - 'split.hh', - 'std-hash.hh', - 'strings.hh', - 'strings-inline.hh', - 'suggestions.hh', - 'sync.hh', - 'tarfile.hh', - 'terminal.hh', - 'thread-pool.hh', - 'topo-sort.hh', - 'types.hh', - 'unix-domain-socket.hh', - 'url-parts.hh', - 'url.hh', - 'users.hh', - 'util.hh', - 'variant-wrapper.hh', - 'xml-writer.hh', -) - if host_machine.system() == 'linux' subdir('linux') endif @@ -286,7 +186,7 @@ this_library = library( install : true, ) -install_headers(headers, subdir : 'nix', preserve_path : true) +install_headers(headers, subdir : 'nix/util', preserve_path : true) libraries_private = [] if host_machine.system() == 'windows' diff --git a/src/libutil/mounted-source-accessor.cc b/src/libutil/mounted-source-accessor.cc index c21a71047..89063b10f 100644 --- a/src/libutil/mounted-source-accessor.cc +++ b/src/libutil/mounted-source-accessor.cc @@ -1,4 +1,4 @@ -#include "mounted-source-accessor.hh" +#include "nix/util/mounted-source-accessor.hh" namespace nix { diff --git a/src/libutil/package.nix b/src/libutil/package.nix index b85dcd58f..5bbbbfd96 100644 --- a/src/libutil/package.nix +++ b/src/libutil/package.nix @@ -34,9 +34,13 @@ mkMesonLibrary (finalAttrs: { ./widecharwidth ./meson.build ./meson.options + ./include/nix/util/meson.build ./linux/meson.build + ./linux/include/nix/util/meson.build ./unix/meson.build + ./unix/include/nix/util/meson.build ./windows/meson.build + ./windows/include/nix/util/meson.build (fileset.fileFilter (file: file.hasExt "cc") ./.) (fileset.fileFilter (file: file.hasExt "hh") ./.) ]; @@ -58,13 +62,6 @@ mkMesonLibrary (finalAttrs: { (lib.mesonEnable "cpuid" stdenv.hostPlatform.isx86_64) ]; - env = { - # Needed for Meson to find Boost. - # https://github.com/NixOS/nixpkgs/issues/86131. - BOOST_INCLUDEDIR = "${lib.getDev boost}/include"; - BOOST_LIBRARYDIR = "${lib.getLib boost}/lib"; - }; - meta = { platforms = lib.platforms.unix ++ lib.platforms.windows; }; diff --git a/src/libutil/pos-table.cc b/src/libutil/pos-table.cc index 8178beb90..5a61ffbc5 100644 --- a/src/libutil/pos-table.cc +++ b/src/libutil/pos-table.cc @@ -1,4 +1,4 @@ -#include "pos-table.hh" +#include "nix/util/pos-table.hh" #include diff --git a/src/libutil/position.cc b/src/libutil/position.cc index 275985c8c..dfe0e2abb 100644 --- a/src/libutil/position.cc +++ b/src/libutil/position.cc @@ -1,4 +1,4 @@ -#include "position.hh" +#include "nix/util/position.hh" namespace nix { diff --git a/src/libutil/posix-source-accessor.cc b/src/libutil/posix-source-accessor.cc index 70ad6474f..5c7b4654b 100644 --- a/src/libutil/posix-source-accessor.cc +++ b/src/libutil/posix-source-accessor.cc @@ -1,7 +1,7 @@ -#include "posix-source-accessor.hh" -#include "source-path.hh" -#include "signals.hh" -#include "sync.hh" +#include "nix/util/posix-source-accessor.hh" +#include "nix/util/source-path.hh" +#include "nix/util/signals.hh" +#include "nix/util/sync.hh" #include diff --git a/src/libutil/references.cc b/src/libutil/references.cc index b30e62c7b..66ad9d37c 100644 --- a/src/libutil/references.cc +++ b/src/libutil/references.cc @@ -1,6 +1,6 @@ -#include "references.hh" -#include "hash.hh" -#include "archive.hh" +#include "nix/util/references.hh" +#include "nix/util/hash.hh" +#include "nix/util/archive.hh" #include #include diff --git a/src/libutil/serialise.cc b/src/libutil/serialise.cc index d612c11b2..55397c6d4 100644 --- a/src/libutil/serialise.cc +++ b/src/libutil/serialise.cc @@ -1,6 +1,6 @@ -#include "serialise.hh" -#include "signals.hh" -#include "util.hh" +#include "nix/util/serialise.hh" +#include "nix/util/signals.hh" +#include "nix/util/util.hh" #include #include @@ -11,7 +11,7 @@ #ifdef _WIN32 # include # include -# include "windows-error.hh" +# include "nix/util/windows-error.hh" #else # include #endif diff --git a/src/libutil/signature/local-keys.cc b/src/libutil/signature/local-keys.cc index 70bcb5f33..1f7f2c7de 100644 --- a/src/libutil/signature/local-keys.cc +++ b/src/libutil/signature/local-keys.cc @@ -1,7 +1,7 @@ -#include "signature/local-keys.hh" +#include "nix/util/signature/local-keys.hh" -#include "file-system.hh" -#include "util.hh" +#include "nix/util/file-system.hh" +#include "nix/util/util.hh" #include namespace nix { diff --git a/src/libutil/signature/signer.cc b/src/libutil/signature/signer.cc index 0d26867b5..46445e9e9 100644 --- a/src/libutil/signature/signer.cc +++ b/src/libutil/signature/signer.cc @@ -1,5 +1,5 @@ -#include "signature/signer.hh" -#include "error.hh" +#include "nix/util/signature/signer.hh" +#include "nix/util/error.hh" #include diff --git a/src/libutil/source-accessor.cc b/src/libutil/source-accessor.cc index 78f038cf3..fc0d6cff1 100644 --- a/src/libutil/source-accessor.cc +++ b/src/libutil/source-accessor.cc @@ -1,5 +1,5 @@ -#include "source-accessor.hh" -#include "archive.hh" +#include "nix/util/source-accessor.hh" +#include "nix/util/archive.hh" namespace nix { diff --git a/src/libutil/source-path.cc b/src/libutil/source-path.cc index 759d3c355..6d42fa95f 100644 --- a/src/libutil/source-path.cc +++ b/src/libutil/source-path.cc @@ -1,4 +1,4 @@ -#include "source-path.hh" +#include "nix/util/source-path.hh" namespace nix { diff --git a/src/libutil/strings.cc b/src/libutil/strings.cc index 402b7ae98..7ce37d73c 100644 --- a/src/libutil/strings.cc +++ b/src/libutil/strings.cc @@ -2,9 +2,9 @@ #include #include -#include "strings-inline.hh" -#include "os-string.hh" -#include "error.hh" +#include "nix/util/strings-inline.hh" +#include "nix/util/os-string.hh" +#include "nix/util/error.hh" namespace nix { @@ -17,8 +17,10 @@ struct view_stringbuf : public std::stringbuf } }; -std::string_view toView(const std::ostringstream & os) +__attribute__((no_sanitize("undefined"))) std::string_view toView(const std::ostringstream & os) { + /* Downcasting like this is very much undefined behavior, so we disable + UBSAN for this function. */ auto buf = static_cast(os.rdbuf()); return buf->toView(); } @@ -37,6 +39,7 @@ basicSplitString(std::basic_string_view s, std::basic_string_view &); template std::string concatStringsSep(std::string_view, const std::set &); template std::string concatStringsSep(std::string_view, const std::vector &); +template std::string concatStringsSep(std::string_view, const boost::container::small_vector &); typedef std::string_view strings_2[2]; template std::string concatStringsSep(std::string_view, const strings_2 &); diff --git a/src/libutil/suggestions.cc b/src/libutil/suggestions.cc index 84c8e296f..0105c30e7 100644 --- a/src/libutil/suggestions.cc +++ b/src/libutil/suggestions.cc @@ -1,6 +1,6 @@ -#include "suggestions.hh" -#include "ansicolor.hh" -#include "terminal.hh" +#include "nix/util/suggestions.hh" +#include "nix/util/ansicolor.hh" +#include "nix/util/terminal.hh" #include #include diff --git a/src/libutil/tarfile.cc b/src/libutil/tarfile.cc index e412930bb..eb5cd8288 100644 --- a/src/libutil/tarfile.cc +++ b/src/libutil/tarfile.cc @@ -1,10 +1,10 @@ #include #include -#include "finally.hh" -#include "serialise.hh" -#include "tarfile.hh" -#include "file-system.hh" +#include "nix/util/finally.hh" +#include "nix/util/serialise.hh" +#include "nix/util/tarfile.hh" +#include "nix/util/file-system.hh" namespace nix { @@ -166,7 +166,7 @@ void unpackTarfile(Source & source, const fs::path & destDir) { auto archive = TarArchive(source); - fs::create_directories(destDir); + createDirs(destDir); extract_archive(archive, destDir); } @@ -174,7 +174,7 @@ void unpackTarfile(const fs::path & tarFile, const fs::path & destDir) { auto archive = TarArchive(tarFile); - fs::create_directories(destDir); + createDirs(destDir); extract_archive(archive, destDir); } diff --git a/src/libutil/tee-logger.cc b/src/libutil/tee-logger.cc index cb2548264..c539ae5d1 100644 --- a/src/libutil/tee-logger.cc +++ b/src/libutil/tee-logger.cc @@ -1,4 +1,4 @@ -#include "logging.hh" +#include "nix/util/logging.hh" namespace nix { diff --git a/src/libutil/terminal.cc b/src/libutil/terminal.cc index 8a8373f1b..fa0f7e871 100644 --- a/src/libutil/terminal.cc +++ b/src/libutil/terminal.cc @@ -1,8 +1,8 @@ -#include "terminal.hh" -#include "environment-variables.hh" -#include "sync.hh" +#include "nix/util/terminal.hh" +#include "nix/util/environment-variables.hh" +#include "nix/util/sync.hh" -#if _WIN32 +#ifdef _WIN32 # include # define WIN32_LEAN_AND_MEAN # include diff --git a/src/libutil/thread-pool.cc b/src/libutil/thread-pool.cc index 0725c1926..8958bc550 100644 --- a/src/libutil/thread-pool.cc +++ b/src/libutil/thread-pool.cc @@ -1,6 +1,6 @@ -#include "thread-pool.hh" -#include "signals.hh" -#include "util.hh" +#include "nix/util/thread-pool.hh" +#include "nix/util/signals.hh" +#include "nix/util/util.hh" namespace nix { diff --git a/src/libutil/union-source-accessor.cc b/src/libutil/union-source-accessor.cc index eec0850c2..9950f6049 100644 --- a/src/libutil/union-source-accessor.cc +++ b/src/libutil/union-source-accessor.cc @@ -1,4 +1,4 @@ -#include "source-accessor.hh" +#include "nix/util/source-accessor.hh" namespace nix { diff --git a/src/libutil/unix-domain-socket.cc b/src/libutil/unix-domain-socket.cc index 0a7af1308..0e8c21d66 100644 --- a/src/libutil/unix-domain-socket.cc +++ b/src/libutil/unix-domain-socket.cc @@ -1,6 +1,6 @@ -#include "file-system.hh" -#include "unix-domain-socket.hh" -#include "util.hh" +#include "nix/util/file-system.hh" +#include "nix/util/unix-domain-socket.hh" +#include "nix/util/util.hh" #ifdef _WIN32 # include @@ -8,7 +8,7 @@ #else # include # include -# include "processes.hh" +# include "nix/util/processes.hh" #endif #include diff --git a/src/libutil/unix/environment-variables.cc b/src/libutil/unix/environment-variables.cc index cd7c8f5e5..0e1ed2794 100644 --- a/src/libutil/unix/environment-variables.cc +++ b/src/libutil/unix/environment-variables.cc @@ -1,6 +1,6 @@ #include -#include "environment-variables.hh" +#include "nix/util/environment-variables.hh" namespace nix { diff --git a/src/libutil/unix/file-descriptor.cc b/src/libutil/unix/file-descriptor.cc index a02a53b1e..73ee49982 100644 --- a/src/libutil/unix/file-descriptor.cc +++ b/src/libutil/unix/file-descriptor.cc @@ -1,12 +1,15 @@ -#include "file-system.hh" -#include "signals.hh" -#include "finally.hh" -#include "serialise.hh" +#include "nix/util/file-system.hh" +#include "nix/util/signals.hh" +#include "nix/util/finally.hh" +#include "nix/util/serialise.hh" #include #include #include +#include "util-config-private.hh" +#include "util-unix-config-private.hh" + namespace nix { namespace { @@ -160,7 +163,7 @@ void Pipe::create() ////////////////////////////////////////////////////////////////////// -#if __linux__ || __FreeBSD__ +#if defined(__linux__) || defined(__FreeBSD__) static int unix_close_range(unsigned int first, unsigned int last, int flags) { #if !HAVE_CLOSE_RANGE @@ -176,7 +179,7 @@ void unix::closeExtraFDs() constexpr int MAX_KEPT_FD = 2; static_assert(std::max({STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO}) == MAX_KEPT_FD); -#if __linux__ || __FreeBSD__ +#if defined(__linux__) || defined(__FreeBSD__) // first try to close_range everything we don't care about. if this // returns an error with these parameters we're running on a kernel // that does not implement close_range (i.e. pre 5.9) and fall back @@ -186,7 +189,7 @@ void unix::closeExtraFDs() } #endif -#if __linux__ +#ifdef __linux__ try { for (auto & s : std::filesystem::directory_iterator{"/proc/self/fd"}) { checkInterrupt(); diff --git a/src/libutil/unix/file-path.cc b/src/libutil/unix/file-path.cc index cccee86a1..0fb1f468c 100644 --- a/src/libutil/unix/file-path.cc +++ b/src/libutil/unix/file-path.cc @@ -3,8 +3,8 @@ #include #include -#include "file-path.hh" -#include "util.hh" +#include "nix/util/file-path.hh" +#include "nix/util/util.hh" namespace nix { diff --git a/src/libutil/unix/file-system.cc b/src/libutil/unix/file-system.cc index bbbbfa559..e62b7d1c2 100644 --- a/src/libutil/unix/file-system.cc +++ b/src/libutil/unix/file-system.cc @@ -1,10 +1,72 @@ -#include "file-system.hh" +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "nix/util/file-system.hh" + +#include "util-unix-config-private.hh" namespace nix { +namespace fs { +using namespace std::filesystem; +} + Descriptor openDirectory(const std::filesystem::path & path) { return open(path.c_str(), O_RDONLY | O_DIRECTORY); } +void setWriteTime(const fs::path & path, time_t accessedTime, time_t modificationTime, std::optional optIsSymlink) +{ + // Would be nice to use std::filesystem unconditionally, but + // doesn't support access time just modification time. + // + // System clock vs File clock issues also make that annoying. +#if HAVE_UTIMENSAT && HAVE_DECL_AT_SYMLINK_NOFOLLOW + struct timespec times[2] = { + { + .tv_sec = accessedTime, + .tv_nsec = 0, + }, + { + .tv_sec = modificationTime, + .tv_nsec = 0, + }, + }; + if (utimensat(AT_FDCWD, path.c_str(), times, AT_SYMLINK_NOFOLLOW) == -1) + throw SysError("changing modification time of %s (using `utimensat`)", path); +#else + struct timeval times[2] = { + { + .tv_sec = accessedTime, + .tv_usec = 0, + }, + { + .tv_sec = modificationTime, + .tv_usec = 0, + }, + }; +# if HAVE_LUTIMES + if (lutimes(path.c_str(), times) == -1) + throw SysError("changing modification time of %s", path); +# else + bool isSymlink = optIsSymlink ? *optIsSymlink : fs::is_symlink(path); + + if (!isSymlink) { + if (utimes(path.c_str(), times) == -1) + throw SysError("changing modification time of %s (not a symlink)", path); + } else { + throw Error("Cannot change modification time of symlink %s", path); + } +# endif +#endif +} + } diff --git a/src/libutil/unix/include/nix/util/meson.build b/src/libutil/unix/include/nix/util/meson.build new file mode 100644 index 000000000..b6f1c40d3 --- /dev/null +++ b/src/libutil/unix/include/nix/util/meson.build @@ -0,0 +1,8 @@ +# Public headers directory + +include_dirs += include_directories('../..') + +headers += files( + 'monitor-fd.hh', + 'signals-impl.hh', +) diff --git a/src/libutil/unix/monitor-fd.hh b/src/libutil/unix/include/nix/util/monitor-fd.hh similarity index 99% rename from src/libutil/unix/monitor-fd.hh rename to src/libutil/unix/include/nix/util/monitor-fd.hh index c1f8705eb..c10ad96bd 100644 --- a/src/libutil/unix/monitor-fd.hh +++ b/src/libutil/unix/include/nix/util/monitor-fd.hh @@ -10,7 +10,7 @@ #include #include -#include "signals.hh" +#include "nix/util/signals.hh" namespace nix { diff --git a/src/libutil/unix/signals-impl.hh b/src/libutil/unix/include/nix/util/signals-impl.hh similarity index 94% rename from src/libutil/unix/signals-impl.hh rename to src/libutil/unix/include/nix/util/signals-impl.hh index 037416e7d..ffa967344 100644 --- a/src/libutil/unix/signals-impl.hh +++ b/src/libutil/unix/include/nix/util/signals-impl.hh @@ -10,11 +10,11 @@ * downstream code.) */ -#include "types.hh" -#include "error.hh" -#include "logging.hh" -#include "ansicolor.hh" -#include "signals.hh" +#include "nix/util/types.hh" +#include "nix/util/error.hh" +#include "nix/util/logging.hh" +#include "nix/util/ansicolor.hh" +#include "nix/util/signals.hh" #include #include diff --git a/src/libutil/unix/meson.build b/src/libutil/unix/meson.build index 1c5bf27fb..ea2391d05 100644 --- a/src/libutil/unix/meson.build +++ b/src/libutil/unix/meson.build @@ -1,3 +1,53 @@ +include_dirs += include_directories('.') + +configdata_unix = configuration_data() + +configdata_unix.set( + 'HAVE_DECL_AT_SYMLINK_NOFOLLOW', + cxx.has_header_symbol('fcntl.h', 'AT_SYMLINK_NOFOLLOW').to_int(), + description : 'Optionally used for changing the files and symlinks.' +) + +# Check for each of these functions, and create a define like `#define +# HAVE_CLOSE_RANGE 1`. +check_funcs_unix = [ + [ + 'close_range', + 'For closing many file descriptors after forking.', + ], + [ + 'lutimes', + 'Optionally used for changing the mtime of symlinks.', + ], + [ + 'pipe2', + 'Optionally used for creating pipes on Unix.', + ], + [ + 'strsignal', + 'Optionally used to get more information about processes failing due to a signal on Unix.', + ], + [ + 'sysconf', + 'Optionally used to try to close more file descriptors (e.g. before forking) on Unix.', + ], + [ + 'utimensat', + 'Optionally used for changing the mtime of files and symlinks.', + ], +] +foreach funcspec : check_funcs_unix + define_name = 'HAVE_' + funcspec[0].underscorify().to_upper() + define_value = cxx.has_function(funcspec[0]).to_int() + configdata_unix.set(define_name, define_value, description: funcspec[1]) +endforeach + +config_unix_priv_h = configure_file( + configuration : configdata_unix, + output : 'util-unix-config-private.hh', +) +sources += config_unix_priv_h + sources += files( 'environment-variables.cc', 'file-descriptor.cc', @@ -10,9 +60,4 @@ sources += files( 'users.cc', ) -include_dirs += include_directories('.') - -headers += files( - 'monitor-fd.hh', - 'signals-impl.hh', -) +subdir('include/nix/util') diff --git a/src/libutil/unix/muxable-pipe.cc b/src/libutil/unix/muxable-pipe.cc index 0104663c3..57bcdb0ad 100644 --- a/src/libutil/unix/muxable-pipe.cc +++ b/src/libutil/unix/muxable-pipe.cc @@ -1,8 +1,8 @@ #include -#include "logging.hh" -#include "util.hh" -#include "muxable-pipe.hh" +#include "nix/util/logging.hh" +#include "nix/util/util.hh" +#include "nix/util/muxable-pipe.hh" namespace nix { diff --git a/src/libutil/unix/os-string.cc b/src/libutil/unix/os-string.cc index 8378afde2..1a2be1554 100644 --- a/src/libutil/unix/os-string.cc +++ b/src/libutil/unix/os-string.cc @@ -3,8 +3,8 @@ #include #include -#include "file-path.hh" -#include "util.hh" +#include "nix/util/file-path.hh" +#include "nix/util/util.hh" namespace nix { diff --git a/src/libutil/unix/processes.cc b/src/libutil/unix/processes.cc index da198bed4..198243c20 100644 --- a/src/libutil/unix/processes.cc +++ b/src/libutil/unix/processes.cc @@ -1,10 +1,10 @@ -#include "current-process.hh" -#include "environment-variables.hh" -#include "executable-path.hh" -#include "signals.hh" -#include "processes.hh" -#include "finally.hh" -#include "serialise.hh" +#include "nix/util/current-process.hh" +#include "nix/util/environment-variables.hh" +#include "nix/util/executable-path.hh" +#include "nix/util/signals.hh" +#include "nix/util/processes.hh" +#include "nix/util/finally.hh" +#include "nix/util/serialise.hh" #include #include @@ -28,6 +28,9 @@ # include #endif +#include "util-config-private.hh" +#include "util-unix-config-private.hh" + namespace nix { @@ -75,7 +78,7 @@ int Pid::kill() /* On BSDs, killing a process group will return EPERM if all processes in the group are zombies (or something like that). So try to detect and ignore that situation. */ -#if __FreeBSD__ || __APPLE__ +#if defined(__FreeBSD__) || defined(__APPLE__) if (errno != EPERM || ::kill(pid, 0) != 0) #endif logError(SysError("killing process %d", pid).info()); @@ -187,7 +190,7 @@ static pid_t doFork(bool allowVfork, ChildWrapperFunction & fun) } -#if __linux__ +#ifdef __linux__ static int childEntry(void * arg) { auto & fun = *reinterpret_cast(arg); @@ -210,7 +213,7 @@ pid_t startProcess(std::function fun, const ProcessOptions & options) logger = makeSimpleLogger(); } try { -#if __linux__ +#ifdef __linux__ if (options.dieWithParent && prctl(PR_SET_PDEATHSIG, SIGKILL) == -1) throw SysError("setting death signal"); #endif diff --git a/src/libutil/unix/signals.cc b/src/libutil/unix/signals.cc index d0608dace..665b9b096 100644 --- a/src/libutil/unix/signals.cc +++ b/src/libutil/unix/signals.cc @@ -1,8 +1,8 @@ -#include "signals.hh" -#include "util.hh" -#include "error.hh" -#include "sync.hh" -#include "terminal.hh" +#include "nix/util/signals.hh" +#include "nix/util/util.hh" +#include "nix/util/error.hh" +#include "nix/util/sync.hh" +#include "nix/util/terminal.hh" #include @@ -105,7 +105,7 @@ void unix::setChildSignalMask(sigset_t * sigs) { assert(sigs); // C style function, but think of sigs as a reference -#if _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE +#if (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 1) || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE) || (defined(_POSIX_SOURCE) && _POSIX_SOURCE) sigemptyset(&savedSignalMask); // There's no "assign" or "copy" function, so we rely on (math) idempotence // of the or operator: a or a = a. diff --git a/src/libutil/unix/users.cc b/src/libutil/unix/users.cc index 107a6e04f..18df7fdf2 100644 --- a/src/libutil/unix/users.cc +++ b/src/libutil/unix/users.cc @@ -1,7 +1,7 @@ -#include "util.hh" -#include "users.hh" -#include "environment-variables.hh" -#include "file-system.hh" +#include "nix/util/util.hh" +#include "nix/util/users.hh" +#include "nix/util/environment-variables.hh" +#include "nix/util/file-system.hh" #include #include diff --git a/src/libutil/url.cc b/src/libutil/url.cc index 8fb1eecfb..eaa2b0682 100644 --- a/src/libutil/url.cc +++ b/src/libutil/url.cc @@ -1,8 +1,8 @@ -#include "url.hh" -#include "url-parts.hh" -#include "util.hh" -#include "split.hh" -#include "canon-path.hh" +#include "nix/util/url.hh" +#include "nix/util/url-parts.hh" +#include "nix/util/util.hh" +#include "nix/util/split.hh" +#include "nix/util/canon-path.hh" namespace nix { diff --git a/src/libutil/users.cc b/src/libutil/users.cc index b4bc67cbc..5a5d740c6 100644 --- a/src/libutil/users.cc +++ b/src/libutil/users.cc @@ -1,7 +1,7 @@ -#include "util.hh" -#include "users.hh" -#include "environment-variables.hh" -#include "file-system.hh" +#include "nix/util/util.hh" +#include "nix/util/users.hh" +#include "nix/util/environment-variables.hh" +#include "nix/util/file-system.hh" namespace nix { diff --git a/src/libutil/util.cc b/src/libutil/util.cc index ed5c7e4f1..ffd85ffbb 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -1,7 +1,7 @@ -#include "util.hh" -#include "fmt.hh" -#include "file-path.hh" -#include "signals.hh" +#include "nix/util/util.hh" +#include "nix/util/fmt.hh" +#include "nix/util/file-path.hh" +#include "nix/util/signals.hh" #include #include diff --git a/src/libutil/windows/environment-variables.cc b/src/libutil/windows/environment-variables.cc index d1093597c..f9f384a5b 100644 --- a/src/libutil/windows/environment-variables.cc +++ b/src/libutil/windows/environment-variables.cc @@ -1,4 +1,4 @@ -#include "environment-variables.hh" +#include "nix/util/environment-variables.hh" #ifdef _WIN32 # include "processenv.h" diff --git a/src/libutil/windows/file-descriptor.cc b/src/libutil/windows/file-descriptor.cc index e2a473a7c..f451bc0d3 100644 --- a/src/libutil/windows/file-descriptor.cc +++ b/src/libutil/windows/file-descriptor.cc @@ -1,9 +1,9 @@ -#include "file-system.hh" -#include "signals.hh" -#include "finally.hh" -#include "serialise.hh" -#include "windows-error.hh" -#include "file-path.hh" +#include "nix/util/file-system.hh" +#include "nix/util/signals.hh" +#include "nix/util/finally.hh" +#include "nix/util/serialise.hh" +#include "nix/util/windows-error.hh" +#include "nix/util/file-path.hh" #ifdef _WIN32 #include diff --git a/src/libutil/windows/file-path.cc b/src/libutil/windows/file-path.cc index 7405c426b..03cc5afe5 100644 --- a/src/libutil/windows/file-path.cc +++ b/src/libutil/windows/file-path.cc @@ -3,9 +3,9 @@ #include #include -#include "file-path.hh" -#include "file-path-impl.hh" -#include "util.hh" +#include "nix/util/file-path.hh" +#include "nix/util/file-path-impl.hh" +#include "nix/util/util.hh" namespace nix { diff --git a/src/libutil/windows/file-system.cc b/src/libutil/windows/file-system.cc index 7ed1c04a6..1dac7e754 100644 --- a/src/libutil/windows/file-system.cc +++ b/src/libutil/windows/file-system.cc @@ -1,8 +1,23 @@ -#include "file-system.hh" +#include "nix/util/file-system.hh" #ifdef _WIN32 namespace nix { +namespace fs { +using namespace std::filesystem; +} + +void setWriteTime(const fs::path & path, time_t accessedTime, time_t modificationTime, std::optional optIsSymlink) +{ + // FIXME use `fs::last_write_time`. + // + // Would be nice to use std::filesystem unconditionally, but + // doesn't support access time just modification time. + // + // System clock vs File clock issues also make that annoying. + warn("Changing file times is not yet implemented on Windows, path is %s", path); +} + Descriptor openDirectory(const std::filesystem::path & path) { return CreateFileW( diff --git a/src/libutil/windows/include/nix/util/meson.build b/src/libutil/windows/include/nix/util/meson.build new file mode 100644 index 000000000..1bd56c4bd --- /dev/null +++ b/src/libutil/windows/include/nix/util/meson.build @@ -0,0 +1,9 @@ +# Public headers directory + +include_dirs += include_directories('../..') + +headers += files( + 'signals-impl.hh', + 'windows-async-pipe.hh', + 'windows-error.hh', +) diff --git a/src/libutil/windows/signals-impl.hh b/src/libutil/windows/include/nix/util/signals-impl.hh similarity index 94% rename from src/libutil/windows/signals-impl.hh rename to src/libutil/windows/include/nix/util/signals-impl.hh index 26d2600bf..043f39100 100644 --- a/src/libutil/windows/signals-impl.hh +++ b/src/libutil/windows/include/nix/util/signals-impl.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "types.hh" +#include "nix/util/types.hh" namespace nix { diff --git a/src/libutil/windows/windows-async-pipe.hh b/src/libutil/windows/include/nix/util/windows-async-pipe.hh similarity index 92% rename from src/libutil/windows/windows-async-pipe.hh rename to src/libutil/windows/include/nix/util/windows-async-pipe.hh index 53715e260..5bb0c3518 100644 --- a/src/libutil/windows/windows-async-pipe.hh +++ b/src/libutil/windows/include/nix/util/windows-async-pipe.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "file-descriptor.hh" +#include "nix/util/file-descriptor.hh" #ifdef _WIN32 namespace nix::windows { diff --git a/src/libutil/windows/windows-error.hh b/src/libutil/windows/include/nix/util/windows-error.hh similarity index 97% rename from src/libutil/windows/windows-error.hh rename to src/libutil/windows/include/nix/util/windows-error.hh index 66c67b43a..abf979c6b 100644 --- a/src/libutil/windows/windows-error.hh +++ b/src/libutil/windows/include/nix/util/windows-error.hh @@ -4,7 +4,7 @@ #ifdef _WIN32 #include -#include "error.hh" +#include "nix/util/error.hh" namespace nix::windows { diff --git a/src/libutil/windows/meson.build b/src/libutil/windows/meson.build index 1c645fe05..0c1cec49c 100644 --- a/src/libutil/windows/meson.build +++ b/src/libutil/windows/meson.build @@ -11,10 +11,4 @@ sources += files( 'windows-error.cc', ) -include_dirs += include_directories('.') - -headers += files( - 'signals-impl.hh', - 'windows-async-pipe.hh', - 'windows-error.hh', -) +subdir('include/nix/util') diff --git a/src/libutil/windows/muxable-pipe.cc b/src/libutil/windows/muxable-pipe.cc index ac2882120..82ef40665 100644 --- a/src/libutil/windows/muxable-pipe.cc +++ b/src/libutil/windows/muxable-pipe.cc @@ -1,10 +1,10 @@ #ifdef _WIN32 # include -# include "windows-error.hh" +# include "nix/util/windows-error.hh" -# include "logging.hh" -# include "util.hh" -# include "muxable-pipe.hh" +# include "nix/util/logging.hh" +# include "nix/util/util.hh" +# include "nix/util/muxable-pipe.hh" namespace nix { diff --git a/src/libutil/windows/os-string.cc b/src/libutil/windows/os-string.cc index b09ef8b90..8c8a27a9f 100644 --- a/src/libutil/windows/os-string.cc +++ b/src/libutil/windows/os-string.cc @@ -3,9 +3,9 @@ #include #include -#include "file-path.hh" -#include "file-path-impl.hh" -#include "util.hh" +#include "nix/util/file-path.hh" +#include "nix/util/file-path-impl.hh" +#include "nix/util/util.hh" #ifdef _WIN32 diff --git a/src/libutil/windows/processes.cc b/src/libutil/windows/processes.cc index 90cb1f5f5..099dff31b 100644 --- a/src/libutil/windows/processes.cc +++ b/src/libutil/windows/processes.cc @@ -1,16 +1,16 @@ -#include "current-process.hh" -#include "environment-variables.hh" -#include "error.hh" -#include "executable-path.hh" -#include "file-descriptor.hh" -#include "file-path.hh" -#include "signals.hh" -#include "processes.hh" -#include "finally.hh" -#include "serialise.hh" -#include "file-system.hh" -#include "util.hh" -#include "windows-error.hh" +#include "nix/util/current-process.hh" +#include "nix/util/environment-variables.hh" +#include "nix/util/error.hh" +#include "nix/util/executable-path.hh" +#include "nix/util/file-descriptor.hh" +#include "nix/util/file-path.hh" +#include "nix/util/signals.hh" +#include "nix/util/processes.hh" +#include "nix/util/finally.hh" +#include "nix/util/serialise.hh" +#include "nix/util/file-system.hh" +#include "nix/util/util.hh" +#include "nix/util/windows-error.hh" #include #include diff --git a/src/libutil/windows/users.cc b/src/libutil/windows/users.cc index 438c4221c..90da0281f 100644 --- a/src/libutil/windows/users.cc +++ b/src/libutil/windows/users.cc @@ -1,8 +1,8 @@ -#include "util.hh" -#include "users.hh" -#include "environment-variables.hh" -#include "file-system.hh" -#include "windows-error.hh" +#include "nix/util/util.hh" +#include "nix/util/users.hh" +#include "nix/util/environment-variables.hh" +#include "nix/util/file-system.hh" +#include "nix/util/windows-error.hh" #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN diff --git a/src/libutil/windows/windows-async-pipe.cc b/src/libutil/windows/windows-async-pipe.cc index 4e139d5cf..d47930a1b 100644 --- a/src/libutil/windows/windows-async-pipe.cc +++ b/src/libutil/windows/windows-async-pipe.cc @@ -1,5 +1,5 @@ -#include "windows-async-pipe.hh" -#include "windows-error.hh" +#include "nix/util/windows-async-pipe.hh" +#include "nix/util/windows-error.hh" #ifdef _WIN32 diff --git a/src/libutil/windows/windows-error.cc b/src/libutil/windows/windows-error.cc index b92f9155f..1e7aff830 100644 --- a/src/libutil/windows/windows-error.cc +++ b/src/libutil/windows/windows-error.cc @@ -1,4 +1,4 @@ -#include "windows-error.hh" +#include "nix/util/windows-error.hh" #ifdef _WIN32 #include diff --git a/src/libutil/xml-writer.cc b/src/libutil/xml-writer.cc index 7993bee9a..e460dd169 100644 --- a/src/libutil/xml-writer.cc +++ b/src/libutil/xml-writer.cc @@ -1,6 +1,6 @@ #include -#include "xml-writer.hh" +#include "nix/util/xml-writer.hh" namespace nix { diff --git a/src/nix-build/nix-build.cc b/src/nix-build/nix-build.cc index a5ae12a12..45f891808 100644 --- a/src/nix-build/nix-build.cc +++ b/src/nix-build/nix-build.cc @@ -9,25 +9,25 @@ #include -#include "current-process.hh" -#include "parsed-derivations.hh" -#include "derivation-options.hh" -#include "store-api.hh" -#include "local-fs-store.hh" -#include "globals.hh" -#include "realisation.hh" -#include "derivations.hh" -#include "shared.hh" -#include "path-with-outputs.hh" -#include "eval.hh" -#include "eval-inline.hh" -#include "get-drvs.hh" -#include "common-eval-args.hh" -#include "attr-path.hh" -#include "legacy.hh" -#include "users.hh" -#include "network-proxy.hh" -#include "compatibility-settings.hh" +#include "nix/util/current-process.hh" +#include "nix/store/parsed-derivations.hh" +#include "nix/store/derivation-options.hh" +#include "nix/store/store-api.hh" +#include "nix/store/local-fs-store.hh" +#include "nix/store/globals.hh" +#include "nix/store/realisation.hh" +#include "nix/store/derivations.hh" +#include "nix/main/shared.hh" +#include "nix/store/path-with-outputs.hh" +#include "nix/expr/eval.hh" +#include "nix/expr/eval-inline.hh" +#include "nix/expr/get-drvs.hh" +#include "nix/cmd/common-eval-args.hh" +#include "nix/expr/attr-path.hh" +#include "nix/cmd/legacy.hh" +#include "nix/util/users.hh" +#include "nix/cmd/network-proxy.hh" +#include "nix/cmd/compatibility-settings.hh" #include "man-pages.hh" using namespace nix; diff --git a/src/nix-channel/nix-channel.cc b/src/nix-channel/nix-channel.cc index ee61db994..c0baa4aa2 100644 --- a/src/nix-channel/nix-channel.cc +++ b/src/nix-channel/nix-channel.cc @@ -1,12 +1,12 @@ -#include "profiles.hh" -#include "shared.hh" -#include "globals.hh" -#include "filetransfer.hh" -#include "store-api.hh" -#include "legacy.hh" -#include "eval-settings.hh" // for defexpr -#include "users.hh" -#include "tarball.hh" +#include "nix/store/profiles.hh" +#include "nix/main/shared.hh" +#include "nix/store/globals.hh" +#include "nix/store/filetransfer.hh" +#include "nix/store/store-api.hh" +#include "nix/cmd/legacy.hh" +#include "nix/expr/eval-settings.hh" // for defexpr +#include "nix/util/users.hh" +#include "nix/fetchers/tarball.hh" #include "self-exe.hh" #include "man-pages.hh" diff --git a/src/nix-collect-garbage/nix-collect-garbage.cc b/src/nix-collect-garbage/nix-collect-garbage.cc index a060a01fd..3a84d97aa 100644 --- a/src/nix-collect-garbage/nix-collect-garbage.cc +++ b/src/nix-collect-garbage/nix-collect-garbage.cc @@ -1,12 +1,12 @@ -#include "file-system.hh" -#include "signals.hh" -#include "store-api.hh" -#include "store-cast.hh" -#include "gc-store.hh" -#include "profiles.hh" -#include "shared.hh" -#include "globals.hh" -#include "legacy.hh" +#include "nix/util/file-system.hh" +#include "nix/util/signals.hh" +#include "nix/store/store-api.hh" +#include "nix/store/store-cast.hh" +#include "nix/store/gc-store.hh" +#include "nix/store/profiles.hh" +#include "nix/main/shared.hh" +#include "nix/store/globals.hh" +#include "nix/cmd/legacy.hh" #include "man-pages.hh" #include diff --git a/src/nix-copy-closure/nix-copy-closure.cc b/src/nix-copy-closure/nix-copy-closure.cc index 15bff0a0a..6d0db1008 100644 --- a/src/nix-copy-closure/nix-copy-closure.cc +++ b/src/nix-copy-closure/nix-copy-closure.cc @@ -1,7 +1,7 @@ -#include "shared.hh" -#include "realisation.hh" -#include "store-api.hh" -#include "legacy.hh" +#include "nix/main/shared.hh" +#include "nix/store/realisation.hh" +#include "nix/store/store-api.hh" +#include "nix/cmd/legacy.hh" #include "man-pages.hh" using namespace nix; diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc index aa1edb4c8..021619ada 100644 --- a/src/nix-env/nix-env.cc +++ b/src/nix-env/nix-env.cc @@ -1,22 +1,22 @@ -#include "users.hh" -#include "attr-path.hh" -#include "common-eval-args.hh" -#include "derivations.hh" -#include "eval.hh" -#include "get-drvs.hh" -#include "globals.hh" -#include "names.hh" -#include "profiles.hh" -#include "path-with-outputs.hh" -#include "shared.hh" -#include "store-api.hh" -#include "local-fs-store.hh" +#include "nix/util/users.hh" +#include "nix/expr/attr-path.hh" +#include "nix/cmd/common-eval-args.hh" +#include "nix/store/derivations.hh" +#include "nix/expr/eval.hh" +#include "nix/expr/get-drvs.hh" +#include "nix/store/globals.hh" +#include "nix/store/names.hh" +#include "nix/store/profiles.hh" +#include "nix/store/path-with-outputs.hh" +#include "nix/main/shared.hh" +#include "nix/store/store-api.hh" +#include "nix/store/local-fs-store.hh" #include "user-env.hh" -#include "value-to-json.hh" -#include "xml-writer.hh" -#include "legacy.hh" -#include "eval-settings.hh" // for defexpr -#include "terminal.hh" +#include "nix/expr/value-to-json.hh" +#include "nix/util/xml-writer.hh" +#include "nix/cmd/legacy.hh" +#include "nix/expr/eval-settings.hh" // for defexpr +#include "nix/util/terminal.hh" #include "man-pages.hh" #include diff --git a/src/nix-env/user-env.cc b/src/nix-env/user-env.cc index ee62077c0..e149b6aeb 100644 --- a/src/nix-env/user-env.cc +++ b/src/nix-env/user-env.cc @@ -1,14 +1,14 @@ #include "user-env.hh" -#include "derivations.hh" -#include "store-api.hh" -#include "path-with-outputs.hh" -#include "local-fs-store.hh" -#include "globals.hh" -#include "shared.hh" -#include "eval.hh" -#include "eval-inline.hh" -#include "profiles.hh" -#include "print-ambiguous.hh" +#include "nix/store/derivations.hh" +#include "nix/store/store-api.hh" +#include "nix/store/path-with-outputs.hh" +#include "nix/store/local-fs-store.hh" +#include "nix/store/globals.hh" +#include "nix/main/shared.hh" +#include "nix/expr/eval.hh" +#include "nix/expr/eval-inline.hh" +#include "nix/store/profiles.hh" +#include "nix/expr/print-ambiguous.hh" #include #include diff --git a/src/nix-env/user-env.hh b/src/nix-env/user-env.hh index 15da3fcb3..0a19b8f32 100644 --- a/src/nix-env/user-env.hh +++ b/src/nix-env/user-env.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "get-drvs.hh" +#include "nix/expr/get-drvs.hh" namespace nix { diff --git a/src/nix-instantiate/nix-instantiate.cc b/src/nix-instantiate/nix-instantiate.cc index 0cf926369..c1b6cc66a 100644 --- a/src/nix-instantiate/nix-instantiate.cc +++ b/src/nix-instantiate/nix-instantiate.cc @@ -1,17 +1,17 @@ -#include "globals.hh" -#include "print-ambiguous.hh" -#include "shared.hh" -#include "eval.hh" -#include "eval-inline.hh" -#include "get-drvs.hh" -#include "attr-path.hh" -#include "signals.hh" -#include "value-to-xml.hh" -#include "value-to-json.hh" -#include "store-api.hh" -#include "local-fs-store.hh" -#include "common-eval-args.hh" -#include "legacy.hh" +#include "nix/store/globals.hh" +#include "nix/expr/print-ambiguous.hh" +#include "nix/main/shared.hh" +#include "nix/expr/eval.hh" +#include "nix/expr/eval-inline.hh" +#include "nix/expr/get-drvs.hh" +#include "nix/expr/attr-path.hh" +#include "nix/util/signals.hh" +#include "nix/expr/value-to-xml.hh" +#include "nix/expr/value-to-json.hh" +#include "nix/store/store-api.hh" +#include "nix/store/local-fs-store.hh" +#include "nix/cmd/common-eval-args.hh" +#include "nix/cmd/legacy.hh" #include "man-pages.hh" #include diff --git a/src/nix-store/dotgraph.cc b/src/nix-store/dotgraph.cc index 2c530999b..f8054b554 100644 --- a/src/nix-store/dotgraph.cc +++ b/src/nix-store/dotgraph.cc @@ -1,5 +1,5 @@ #include "dotgraph.hh" -#include "store-api.hh" +#include "nix/store/store-api.hh" #include diff --git a/src/nix-store/dotgraph.hh b/src/nix-store/dotgraph.hh index 4fd944080..b8e0721ab 100644 --- a/src/nix-store/dotgraph.hh +++ b/src/nix-store/dotgraph.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "store-api.hh" +#include "nix/store/store-api.hh" namespace nix { diff --git a/src/nix-store/graphml.cc b/src/nix-store/graphml.cc index 3e789a2d8..3b3188a41 100644 --- a/src/nix-store/graphml.cc +++ b/src/nix-store/graphml.cc @@ -1,6 +1,6 @@ #include "graphml.hh" -#include "store-api.hh" -#include "derivations.hh" +#include "nix/store/store-api.hh" +#include "nix/store/derivations.hh" #include diff --git a/src/nix-store/graphml.hh b/src/nix-store/graphml.hh index bd3a4a37c..afcedb58e 100644 --- a/src/nix-store/graphml.hh +++ b/src/nix-store/graphml.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "store-api.hh" +#include "nix/store/store-api.hh" namespace nix { diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index d182b1eee..fbbb57f43 100644 --- a/src/nix-store/nix-store.cc +++ b/src/nix-store/nix-store.cc @@ -1,23 +1,23 @@ -#include "archive.hh" -#include "derivations.hh" +#include "nix/util/archive.hh" +#include "nix/store/derivations.hh" #include "dotgraph.hh" -#include "globals.hh" -#include "store-cast.hh" -#include "local-fs-store.hh" -#include "log-store.hh" -#include "serve-protocol.hh" -#include "serve-protocol-connection.hh" -#include "shared.hh" +#include "nix/store/globals.hh" +#include "nix/store/store-cast.hh" +#include "nix/store/local-fs-store.hh" +#include "nix/store/log-store.hh" +#include "nix/store/serve-protocol.hh" +#include "nix/store/serve-protocol-connection.hh" +#include "nix/main/shared.hh" #include "graphml.hh" -#include "legacy.hh" -#include "posix-source-accessor.hh" -#include "path-with-outputs.hh" +#include "nix/cmd/legacy.hh" +#include "nix/util/posix-source-accessor.hh" +#include "nix/store/path-with-outputs.hh" #include "man-pages.hh" #ifndef _WIN32 // TODO implement on Windows or provide allowed-to-noop interface -# include "local-store.hh" -# include "monitor-fd.hh" -# include "posix-fs-canonicalise.hh" +# include "nix/store/local-store.hh" +# include "nix/util/monitor-fd.hh" +# include "nix/store/posix-fs-canonicalise.hh" #endif #include @@ -27,9 +27,9 @@ #include #include -#include "build-result.hh" -#include "exit.hh" -#include "serve-protocol-impl.hh" +#include "nix/store/build-result.hh" +#include "nix/util/exit.hh" +#include "nix/store/serve-protocol-impl.hh" namespace nix_store { diff --git a/src/nix/add-to-store.cc b/src/nix/add-to-store.cc index 7f15de374..9b7306fdd 100644 --- a/src/nix/add-to-store.cc +++ b/src/nix/add-to-store.cc @@ -1,10 +1,10 @@ -#include "command.hh" -#include "common-args.hh" -#include "store-api.hh" -#include "archive.hh" -#include "git.hh" -#include "posix-source-accessor.hh" -#include "misc-store-flags.hh" +#include "nix/cmd/command.hh" +#include "nix/main/common-args.hh" +#include "nix/store/store-api.hh" +#include "nix/util/archive.hh" +#include "nix/util/git.hh" +#include "nix/util/posix-source-accessor.hh" +#include "nix/cmd/misc-store-flags.hh" using namespace nix; diff --git a/src/nix/app.cc b/src/nix/app.cc index 935ed18ec..75ef874ba 100644 --- a/src/nix/app.cc +++ b/src/nix/app.cc @@ -1,13 +1,13 @@ -#include "installables.hh" -#include "installable-derived-path.hh" -#include "installable-value.hh" -#include "store-api.hh" -#include "eval-inline.hh" -#include "eval-cache.hh" -#include "names.hh" -#include "command.hh" -#include "derivations.hh" -#include "downstream-placeholder.hh" +#include "nix/cmd/installables.hh" +#include "nix/cmd/installable-derived-path.hh" +#include "nix/cmd/installable-value.hh" +#include "nix/store/store-api.hh" +#include "nix/expr/eval-inline.hh" +#include "nix/expr/eval-cache.hh" +#include "nix/store/names.hh" +#include "nix/cmd/command.hh" +#include "nix/store/derivations.hh" +#include "nix/store/downstream-placeholder.hh" namespace nix { diff --git a/src/nix/build.cc b/src/nix/build.cc index 4ba6241ec..7cd3c7fbe 100644 --- a/src/nix/build.cc +++ b/src/nix/build.cc @@ -1,8 +1,8 @@ -#include "command.hh" -#include "common-args.hh" -#include "shared.hh" -#include "store-api.hh" -#include "local-fs-store.hh" +#include "nix/cmd/command.hh" +#include "nix/main/common-args.hh" +#include "nix/main/shared.hh" +#include "nix/store/store-api.hh" +#include "nix/store/local-fs-store.hh" #include diff --git a/src/nix/bundle.cc b/src/nix/bundle.cc index 5b7862c4e..30b3003e7 100644 --- a/src/nix/bundle.cc +++ b/src/nix/bundle.cc @@ -1,10 +1,10 @@ -#include "installable-flake.hh" -#include "command-installable-value.hh" -#include "common-args.hh" -#include "shared.hh" -#include "store-api.hh" -#include "local-fs-store.hh" -#include "eval-inline.hh" +#include "nix/cmd/installable-flake.hh" +#include "nix/cmd/command-installable-value.hh" +#include "nix/main/common-args.hh" +#include "nix/main/shared.hh" +#include "nix/store/store-api.hh" +#include "nix/store/local-fs-store.hh" +#include "nix/expr/eval-inline.hh" namespace nix::fs { using namespace std::filesystem; } diff --git a/src/nix/cat.cc b/src/nix/cat.cc index 214d256e9..a790c0301 100644 --- a/src/nix/cat.cc +++ b/src/nix/cat.cc @@ -1,6 +1,6 @@ -#include "command.hh" -#include "store-api.hh" -#include "nar-accessor.hh" +#include "nix/cmd/command.hh" +#include "nix/store/store-api.hh" +#include "nix/store/nar-accessor.hh" using namespace nix; diff --git a/src/nix/config-check.cc b/src/nix/config-check.cc index a72b06542..deac8e560 100644 --- a/src/nix/config-check.cc +++ b/src/nix/config-check.cc @@ -1,14 +1,14 @@ #include -#include "command.hh" -#include "exit.hh" -#include "logging.hh" -#include "serve-protocol.hh" -#include "shared.hh" -#include "store-api.hh" -#include "local-fs-store.hh" -#include "worker-protocol.hh" -#include "executable-path.hh" +#include "nix/cmd/command.hh" +#include "nix/util/exit.hh" +#include "nix/util/logging.hh" +#include "nix/store/serve-protocol.hh" +#include "nix/main/shared.hh" +#include "nix/store/store-api.hh" +#include "nix/store/local-fs-store.hh" +#include "nix/store/worker-protocol.hh" +#include "nix/util/executable-path.hh" namespace nix::fs { using namespace std::filesystem; } diff --git a/src/nix/config.cc b/src/nix/config.cc index 07f975a00..1dc2bed20 100644 --- a/src/nix/config.cc +++ b/src/nix/config.cc @@ -1,8 +1,8 @@ -#include "command.hh" -#include "common-args.hh" -#include "shared.hh" -#include "store-api.hh" -#include "config-global.hh" +#include "nix/cmd/command.hh" +#include "nix/main/common-args.hh" +#include "nix/main/shared.hh" +#include "nix/store/store-api.hh" +#include "nix/util/config-global.hh" #include diff --git a/src/nix/copy.cc b/src/nix/copy.cc index 399a6c0fd..0702215fd 100644 --- a/src/nix/copy.cc +++ b/src/nix/copy.cc @@ -1,7 +1,7 @@ -#include "command.hh" -#include "shared.hh" -#include "store-api.hh" -#include "local-fs-store.hh" +#include "nix/cmd/command.hh" +#include "nix/main/shared.hh" +#include "nix/store/store-api.hh" +#include "nix/store/local-fs-store.hh" using namespace nix; diff --git a/src/nix/crash-handler.cc b/src/nix/crash-handler.cc index 8ffd436ac..d65773fa0 100644 --- a/src/nix/crash-handler.cc +++ b/src/nix/crash-handler.cc @@ -1,13 +1,14 @@ #include "crash-handler.hh" -#include "fmt.hh" -#include "logging.hh" + +#include "nix/util/fmt.hh" +#include "nix/util/logging.hh" #include #include #include // Darwin and FreeBSD stdenv do not define _GNU_SOURCE but do have _Unwind_Backtrace. -#if __APPLE__ || __FreeBSD__ +#if defined(__APPLE__) || defined(__FreeBSD__) # define BOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED #endif diff --git a/src/nix/derivation-add.cc b/src/nix/derivation-add.cc index 4d91d4538..e99c44deb 100644 --- a/src/nix/derivation-add.cc +++ b/src/nix/derivation-add.cc @@ -1,10 +1,10 @@ // FIXME: rename to 'nix plan add' or 'nix derivation add'? -#include "command.hh" -#include "common-args.hh" -#include "store-api.hh" -#include "archive.hh" -#include "derivations.hh" +#include "nix/cmd/command.hh" +#include "nix/main/common-args.hh" +#include "nix/store/store-api.hh" +#include "nix/util/archive.hh" +#include "nix/store/derivations.hh" #include using namespace nix; diff --git a/src/nix/derivation-show.cc b/src/nix/derivation-show.cc index 5a07f58e6..050144ccf 100644 --- a/src/nix/derivation-show.cc +++ b/src/nix/derivation-show.cc @@ -1,11 +1,11 @@ // FIXME: integrate this with `nix path-info`? // FIXME: rename to 'nix store derivation show'? -#include "command.hh" -#include "common-args.hh" -#include "store-api.hh" -#include "archive.hh" -#include "derivations.hh" +#include "nix/cmd/command.hh" +#include "nix/main/common-args.hh" +#include "nix/store/store-api.hh" +#include "nix/util/archive.hh" +#include "nix/store/derivations.hh" #include using namespace nix; diff --git a/src/nix/derivation.cc b/src/nix/derivation.cc index 59a78d378..ee62ab4dc 100644 --- a/src/nix/derivation.cc +++ b/src/nix/derivation.cc @@ -1,4 +1,4 @@ -#include "command.hh" +#include "nix/cmd/command.hh" using namespace nix; diff --git a/src/nix/develop.cc b/src/nix/develop.cc index 961962ebd..e88134a78 100644 --- a/src/nix/develop.cc +++ b/src/nix/develop.cc @@ -1,12 +1,12 @@ -#include "config-global.hh" -#include "eval.hh" -#include "installable-flake.hh" -#include "command-installable-value.hh" -#include "common-args.hh" -#include "shared.hh" -#include "store-api.hh" -#include "outputs-spec.hh" -#include "derivations.hh" +#include "nix/util/config-global.hh" +#include "nix/expr/eval.hh" +#include "nix/cmd/installable-flake.hh" +#include "nix/cmd/command-installable-value.hh" +#include "nix/main/common-args.hh" +#include "nix/main/shared.hh" +#include "nix/store/store-api.hh" +#include "nix/store/outputs-spec.hh" +#include "nix/store/derivations.hh" #ifndef _WIN32 // TODO re-enable on Windows # include "run.hh" @@ -18,7 +18,7 @@ #include #include -#include "strings.hh" +#include "nix/util/strings.hh" namespace nix::fs { using namespace std::filesystem; } diff --git a/src/nix/diff-closures.cc b/src/nix/diff-closures.cc index 2bc7fe82b..c4d21db6f 100644 --- a/src/nix/diff-closures.cc +++ b/src/nix/diff-closures.cc @@ -1,12 +1,12 @@ -#include "command.hh" -#include "shared.hh" -#include "store-api.hh" -#include "common-args.hh" -#include "names.hh" +#include "nix/cmd/command.hh" +#include "nix/main/shared.hh" +#include "nix/store/store-api.hh" +#include "nix/main/common-args.hh" +#include "nix/store/names.hh" #include -#include "strings.hh" +#include "nix/util/strings.hh" namespace nix { diff --git a/src/nix/dump-path.cc b/src/nix/dump-path.cc index 98a059fa1..c883630b1 100644 --- a/src/nix/dump-path.cc +++ b/src/nix/dump-path.cc @@ -1,6 +1,6 @@ -#include "command.hh" -#include "store-api.hh" -#include "archive.hh" +#include "nix/cmd/command.hh" +#include "nix/store/store-api.hh" +#include "nix/util/archive.hh" using namespace nix; diff --git a/src/nix/edit.cc b/src/nix/edit.cc index 49807da9e..cfb9eb74a 100644 --- a/src/nix/edit.cc +++ b/src/nix/edit.cc @@ -1,9 +1,9 @@ -#include "current-process.hh" -#include "command-installable-value.hh" -#include "shared.hh" -#include "eval.hh" -#include "attr-path.hh" -#include "editor-for.hh" +#include "nix/util/current-process.hh" +#include "nix/cmd/command-installable-value.hh" +#include "nix/main/shared.hh" +#include "nix/expr/eval.hh" +#include "nix/expr/attr-path.hh" +#include "nix/cmd/editor-for.hh" #include diff --git a/src/nix/env.cc b/src/nix/env.cc index 832320320..4b00dbc7c 100644 --- a/src/nix/env.cc +++ b/src/nix/env.cc @@ -1,11 +1,11 @@ #include #include -#include "command.hh" -#include "eval.hh" +#include "nix/cmd/command.hh" +#include "nix/expr/eval.hh" #include "run.hh" -#include "strings.hh" -#include "executable-path.hh" +#include "nix/util/strings.hh" +#include "nix/util/executable-path.hh" using namespace nix; diff --git a/src/nix/eval.cc b/src/nix/eval.cc index e038d75c3..24a87f140 100644 --- a/src/nix/eval.cc +++ b/src/nix/eval.cc @@ -1,10 +1,10 @@ -#include "command-installable-value.hh" -#include "common-args.hh" -#include "shared.hh" -#include "store-api.hh" -#include "eval.hh" -#include "eval-inline.hh" -#include "value-to-json.hh" +#include "nix/cmd/command-installable-value.hh" +#include "nix/main/common-args.hh" +#include "nix/main/shared.hh" +#include "nix/store/store-api.hh" +#include "nix/expr/eval.hh" +#include "nix/expr/eval-inline.hh" +#include "nix/expr/value-to-json.hh" #include diff --git a/src/nix/flake.cc b/src/nix/flake.cc index 9ffe65b06..f429f1c6e 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -1,30 +1,30 @@ -#include "command.hh" -#include "installable-flake.hh" -#include "common-args.hh" -#include "shared.hh" -#include "eval.hh" -#include "eval-inline.hh" -#include "eval-settings.hh" -#include "flake/flake.hh" -#include "get-drvs.hh" -#include "signals.hh" -#include "store-api.hh" -#include "derivations.hh" -#include "outputs-spec.hh" -#include "attr-path.hh" -#include "fetchers.hh" -#include "registry.hh" -#include "eval-cache.hh" -#include "markdown.hh" -#include "users.hh" -#include "fetch-to-store.hh" -#include "local-fs-store.hh" +#include "nix/cmd/command.hh" +#include "nix/cmd/installable-flake.hh" +#include "nix/main/common-args.hh" +#include "nix/main/shared.hh" +#include "nix/expr/eval.hh" +#include "nix/expr/eval-inline.hh" +#include "nix/expr/eval-settings.hh" +#include "nix/flake/flake.hh" +#include "nix/expr/get-drvs.hh" +#include "nix/util/signals.hh" +#include "nix/store/store-api.hh" +#include "nix/store/derivations.hh" +#include "nix/store/outputs-spec.hh" +#include "nix/expr/attr-path.hh" +#include "nix/fetchers/fetchers.hh" +#include "nix/fetchers/registry.hh" +#include "nix/expr/eval-cache.hh" +#include "nix/cmd/markdown.hh" +#include "nix/util/users.hh" +#include "nix/fetchers/fetch-to-store.hh" +#include "nix/store/local-fs-store.hh" #include #include #include -#include "strings-inline.hh" +#include "nix/util/strings-inline.hh" namespace nix::fs { using namespace std::filesystem; } @@ -905,7 +905,7 @@ struct CmdFlakeInitCommon : virtual Args, EvalCommand std::function copyDir; copyDir = [&](const SourcePath & from, const fs::path & to) { - fs::create_directories(to); + createDirs(to); for (auto & [name, entry] : from.readDirectory()) { checkInterrupt(); diff --git a/src/nix/fmt.cc b/src/nix/fmt.cc index f444d6add..dc270fb8c 100644 --- a/src/nix/fmt.cc +++ b/src/nix/fmt.cc @@ -1,6 +1,6 @@ -#include "command.hh" -#include "installable-value.hh" -#include "eval.hh" +#include "nix/cmd/command.hh" +#include "nix/cmd/installable-value.hh" +#include "nix/expr/eval.hh" #include "run.hh" using namespace nix; diff --git a/src/nix/hash.cc b/src/nix/hash.cc index 91bba47f4..510cfa592 100644 --- a/src/nix/hash.cc +++ b/src/nix/hash.cc @@ -1,13 +1,13 @@ -#include "command.hh" -#include "hash.hh" -#include "content-address.hh" -#include "legacy.hh" -#include "shared.hh" -#include "references.hh" -#include "archive.hh" -#include "git.hh" -#include "posix-source-accessor.hh" -#include "misc-store-flags.hh" +#include "nix/cmd/command.hh" +#include "nix/util/hash.hh" +#include "nix/store/content-address.hh" +#include "nix/cmd/legacy.hh" +#include "nix/main/shared.hh" +#include "nix/util/references.hh" +#include "nix/util/archive.hh" +#include "nix/util/git.hh" +#include "nix/util/posix-source-accessor.hh" +#include "nix/cmd/misc-store-flags.hh" #include "man-pages.hh" using namespace nix; diff --git a/src/nix/log.cc b/src/nix/log.cc index 2c35ed803..00ab74ea6 100644 --- a/src/nix/log.cc +++ b/src/nix/log.cc @@ -1,8 +1,8 @@ -#include "command.hh" -#include "common-args.hh" -#include "shared.hh" -#include "store-api.hh" -#include "log-store.hh" +#include "nix/cmd/command.hh" +#include "nix/main/common-args.hh" +#include "nix/main/shared.hh" +#include "nix/store/store-api.hh" +#include "nix/store/log-store.hh" using namespace nix; diff --git a/src/nix/ls.cc b/src/nix/ls.cc index 63f97f2d3..1a90ed074 100644 --- a/src/nix/ls.cc +++ b/src/nix/ls.cc @@ -1,7 +1,7 @@ -#include "command.hh" -#include "store-api.hh" -#include "nar-accessor.hh" -#include "common-args.hh" +#include "nix/cmd/command.hh" +#include "nix/store/store-api.hh" +#include "nix/store/nar-accessor.hh" +#include "nix/main/common-args.hh" #include using namespace nix; diff --git a/src/nix/main.cc b/src/nix/main.cc index a2dc371d4..580be0992 100644 --- a/src/nix/main.cc +++ b/src/nix/main.cc @@ -1,27 +1,30 @@ -#include "args/root.hh" -#include "current-process.hh" -#include "command.hh" -#include "common-args.hh" -#include "eval.hh" -#include "eval-settings.hh" -#include "globals.hh" -#include "config-global.hh" -#include "legacy.hh" -#include "shared.hh" -#include "store-api.hh" -#include "filetransfer.hh" -#include "finally.hh" -#include "loggers.hh" -#include "markdown.hh" -#include "memory-source-accessor.hh" -#include "terminal.hh" -#include "users.hh" -#include "network-proxy.hh" -#include "eval-cache.hh" -#include "flake/flake.hh" +#include "nix/util/args/root.hh" +#include "nix/util/current-process.hh" +#include "nix/cmd/command.hh" +#include "nix/main/common-args.hh" +#include "nix/expr/eval.hh" +#include "nix/expr/eval-settings.hh" +#include "nix/store/globals.hh" +#include "nix/util/config-global.hh" +#include "nix/cmd/legacy.hh" +#include "nix/main/shared.hh" +#include "nix/store/store-api.hh" +#include "nix/store/filetransfer.hh" +#include "nix/util/finally.hh" +#include "nix/main/loggers.hh" +#include "nix/cmd/markdown.hh" +#include "nix/util/memory-source-accessor.hh" +#include "nix/util/terminal.hh" +#include "nix/util/users.hh" +#include "nix/cmd/network-proxy.hh" +#include "nix/expr/eval-cache.hh" +#include "nix/flake/flake.hh" +#include "nix/flake/settings.hh" +#include "nix/util/json-utils.hh" + #include "self-exe.hh" -#include "json-utils.hh" #include "crash-handler.hh" +#include "cli-config-private.hh" #include #include @@ -34,8 +37,8 @@ # include #endif -#if __linux__ -# include "namespaces.hh" +#ifdef __linux__ +# include "nix/util/namespaces.hh" #endif #ifndef _WIN32 @@ -44,7 +47,7 @@ extern std::string chrootHelperName; void chrootHelper(int argc, char * * argv); #endif -#include "strings.hh" +#include "nix/util/strings.hh" namespace nix { @@ -366,7 +369,7 @@ void mainWrapped(int argc, char * * argv) initNix(); initGC(); - flake::initLib(flakeSettings); + flakeSettings.configureEvalSettings(evalSettings); /* Set the build hook location @@ -379,7 +382,7 @@ void mainWrapped(int argc, char * * argv) "__build-remote", }); - #if __linux__ + #ifdef __linux__ if (isRootUser()) { try { saveMountNamespace(); diff --git a/src/nix/make-content-addressed.cc b/src/nix/make-content-addressed.cc index d9c988a9f..f8f588ae9 100644 --- a/src/nix/make-content-addressed.cc +++ b/src/nix/make-content-addressed.cc @@ -1,7 +1,7 @@ -#include "command.hh" -#include "store-api.hh" -#include "make-content-addressed.hh" -#include "common-args.hh" +#include "nix/cmd/command.hh" +#include "nix/store/store-api.hh" +#include "nix/store/make-content-addressed.hh" +#include "nix/main/common-args.hh" #include diff --git a/src/nix/man-pages.cc b/src/nix/man-pages.cc index e9e89bb62..8585c164c 100644 --- a/src/nix/man-pages.cc +++ b/src/nix/man-pages.cc @@ -1,7 +1,8 @@ #include "man-pages.hh" -#include "file-system.hh" -#include "current-process.hh" -#include "environment-variables.hh" +#include "cli-config-private.hh" +#include "nix/util/file-system.hh" +#include "nix/util/current-process.hh" +#include "nix/util/environment-variables.hh" namespace nix { diff --git a/src/nix/meson.build b/src/nix/meson.build index 79ad840f6..3cb45f1f5 100644 --- a/src/nix/meson.build +++ b/src/nix/meson.build @@ -39,35 +39,25 @@ configdata = configuration_data() configdata.set_quoted('NIX_CLI_VERSION', meson.project_version()) fs = import('fs') +prefix = get_option('prefix') bindir = get_option('bindir') -if not fs.is_absolute(bindir) - bindir = get_option('prefix') / bindir -endif +bindir = fs.is_absolute(bindir) ? bindir : prefix / bindir configdata.set_quoted('NIX_BIN_DIR', bindir) -config_h = configure_file( - configuration : configdata, - output : 'config-nix-cli.hh', -) +mandir = get_option('mandir') +mandir = fs.is_absolute(mandir) ? mandir : prefix / mandir +configdata.set_quoted('NIX_MAN_DIR', mandir) -add_project_arguments( - # TODO(Qyriad): Yes this is how the autoconf+Make system did it. - # It would be nice for our headers to be idempotent instead. - '-include', 'config-util.hh', - '-include', 'config-store.hh', - '-include', 'config-expr.hh', - #'-include', 'config-fetchers.hh', - '-include', 'config-main.hh', - '-include', 'config-cmd.hh', - '-include', 'config-nix-cli.hh', - language : 'cpp', +config_priv_h = configure_file( + configuration : configdata, + output : 'cli-config-private.hh', ) subdir('nix-meson-build-support/common') subdir('nix-meson-build-support/generate-header') -nix_sources = [config_h] + files( +nix_sources = [config_priv_h] + files( 'add-to-store.cc', 'app.cc', 'self-exe.cc', @@ -187,16 +177,6 @@ if host_machine.system() != 'windows' ] endif -fs = import('fs') -prefix = get_option('prefix') - -mandir = get_option('mandir') -mandir = fs.is_absolute(mandir) ? mandir : prefix / mandir - -cpp_args= [ - '-DNIX_MAN_DIR="@0@"'.format(mandir) -] - include_dirs = [include_directories('.')] this_exe = executable( @@ -204,7 +184,6 @@ this_exe = executable( sources, dependencies : deps_private_subproject + deps_private + deps_other, include_directories : include_dirs, - cpp_args : cpp_args, link_args: linker_export_flags, install : true, ) diff --git a/src/nix/nar.cc b/src/nix/nar.cc index 8ad4f92a7..debb6b95e 100644 --- a/src/nix/nar.cc +++ b/src/nix/nar.cc @@ -1,4 +1,4 @@ -#include "command.hh" +#include "nix/cmd/command.hh" using namespace nix; diff --git a/src/nix/optimise-store.cc b/src/nix/optimise-store.cc index 985006e5a..e319f5c90 100644 --- a/src/nix/optimise-store.cc +++ b/src/nix/optimise-store.cc @@ -1,6 +1,6 @@ -#include "command.hh" -#include "shared.hh" -#include "store-api.hh" +#include "nix/cmd/command.hh" +#include "nix/main/shared.hh" +#include "nix/store/store-api.hh" #include diff --git a/src/nix/path-from-hash-part.cc b/src/nix/path-from-hash-part.cc index 7f7cda8d3..814b723f9 100644 --- a/src/nix/path-from-hash-part.cc +++ b/src/nix/path-from-hash-part.cc @@ -1,5 +1,5 @@ -#include "command.hh" -#include "store-api.hh" +#include "nix/cmd/command.hh" +#include "nix/store/store-api.hh" using namespace nix; diff --git a/src/nix/path-info.cc b/src/nix/path-info.cc index 8e3d0406d..329e15830 100644 --- a/src/nix/path-info.cc +++ b/src/nix/path-info.cc @@ -1,15 +1,15 @@ -#include "command.hh" -#include "shared.hh" -#include "store-api.hh" -#include "common-args.hh" -#include "nar-info.hh" +#include "nix/cmd/command.hh" +#include "nix/main/shared.hh" +#include "nix/store/store-api.hh" +#include "nix/main/common-args.hh" +#include "nix/store/nar-info.hh" #include #include #include -#include "strings.hh" +#include "nix/util/strings.hh" using namespace nix; using nlohmann::json; diff --git a/src/nix/prefetch.cc b/src/nix/prefetch.cc index ba2fd39d8..397134b03 100644 --- a/src/nix/prefetch.cc +++ b/src/nix/prefetch.cc @@ -1,17 +1,18 @@ -#include "command.hh" -#include "common-args.hh" -#include "shared.hh" -#include "store-api.hh" -#include "filetransfer.hh" -#include "finally.hh" -#include "loggers.hh" -#include "tarfile.hh" -#include "attr-path.hh" -#include "eval-inline.hh" -#include "legacy.hh" -#include "posix-source-accessor.hh" -#include "misc-store-flags.hh" -#include "terminal.hh" +#include "nix/cmd/command.hh" +#include "nix/main/common-args.hh" +#include "nix/main/shared.hh" +#include "nix/store/store-api.hh" +#include "nix/store/filetransfer.hh" +#include "nix/util/finally.hh" +#include "nix/main/loggers.hh" +#include "nix/util/tarfile.hh" +#include "nix/expr/attr-path.hh" +#include "nix/expr/eval-inline.hh" +#include "nix/cmd/legacy.hh" +#include "nix/util/posix-source-accessor.hh" +#include "nix/cmd/misc-store-flags.hh" +#include "nix/util/terminal.hh" + #include "man-pages.hh" #include diff --git a/src/nix/profile.cc b/src/nix/profile.cc index 324fd6330..1a129d0c5 100644 --- a/src/nix/profile.cc +++ b/src/nix/profile.cc @@ -1,23 +1,23 @@ -#include "command.hh" -#include "installable-flake.hh" -#include "common-args.hh" -#include "shared.hh" -#include "store-api.hh" -#include "derivations.hh" -#include "archive.hh" -#include "builtins/buildenv.hh" -#include "flake/flakeref.hh" +#include "nix/cmd/command.hh" +#include "nix/cmd/installable-flake.hh" +#include "nix/main/common-args.hh" +#include "nix/main/shared.hh" +#include "nix/store/store-api.hh" +#include "nix/store/derivations.hh" +#include "nix/util/archive.hh" +#include "nix/store/builtins/buildenv.hh" +#include "nix/flake/flakeref.hh" #include "../nix-env/user-env.hh" -#include "profiles.hh" -#include "names.hh" -#include "url.hh" -#include "flake/url-name.hh" +#include "nix/store/profiles.hh" +#include "nix/store/names.hh" +#include "nix/util/url.hh" +#include "nix/flake/url-name.hh" #include #include #include -#include "strings.hh" +#include "nix/util/strings.hh" using namespace nix; diff --git a/src/nix/realisation.cc b/src/nix/realisation.cc index a386d98ea..77465e0b7 100644 --- a/src/nix/realisation.cc +++ b/src/nix/realisation.cc @@ -1,5 +1,5 @@ -#include "command.hh" -#include "common-args.hh" +#include "nix/cmd/command.hh" +#include "nix/main/common-args.hh" #include diff --git a/src/nix/registry.cc b/src/nix/registry.cc index ee4516230..340d10ec4 100644 --- a/src/nix/registry.cc +++ b/src/nix/registry.cc @@ -1,11 +1,11 @@ -#include "command.hh" -#include "common-args.hh" -#include "shared.hh" -#include "eval.hh" -#include "flake/flake.hh" -#include "store-api.hh" -#include "fetchers.hh" -#include "registry.hh" +#include "nix/cmd/command.hh" +#include "nix/main/common-args.hh" +#include "nix/main/shared.hh" +#include "nix/expr/eval.hh" +#include "nix/flake/flake.hh" +#include "nix/store/store-api.hh" +#include "nix/fetchers/fetchers.hh" +#include "nix/fetchers/registry.hh" using namespace nix; using namespace nix::flake; diff --git a/src/nix/repl.cc b/src/nix/repl.cc index 5a570749f..fcce43b8f 100644 --- a/src/nix/repl.cc +++ b/src/nix/repl.cc @@ -1,11 +1,11 @@ -#include "eval.hh" -#include "eval-settings.hh" -#include "config-global.hh" -#include "globals.hh" -#include "command.hh" -#include "installable-value.hh" -#include "repl.hh" -#include "processes.hh" +#include "nix/expr/eval.hh" +#include "nix/expr/eval-settings.hh" +#include "nix/util/config-global.hh" +#include "nix/store/globals.hh" +#include "nix/cmd/command.hh" +#include "nix/cmd/installable-value.hh" +#include "nix/cmd/repl.hh" +#include "nix/util/processes.hh" #include "self-exe.hh" namespace nix { diff --git a/src/nix/run.cc b/src/nix/run.cc index 897824d68..146ae9ec9 100644 --- a/src/nix/run.cc +++ b/src/nix/run.cc @@ -1,20 +1,20 @@ -#include "current-process.hh" +#include "nix/util/current-process.hh" #include "run.hh" -#include "command-installable-value.hh" -#include "common-args.hh" -#include "shared.hh" -#include "signals.hh" -#include "store-api.hh" -#include "derivations.hh" -#include "local-fs-store.hh" -#include "finally.hh" -#include "source-accessor.hh" -#include "eval.hh" +#include "nix/cmd/command-installable-value.hh" +#include "nix/main/common-args.hh" +#include "nix/main/shared.hh" +#include "nix/util/signals.hh" +#include "nix/store/store-api.hh" +#include "nix/store/derivations.hh" +#include "nix/store/local-fs-store.hh" +#include "nix/util/finally.hh" +#include "nix/util/source-accessor.hh" +#include "nix/expr/eval.hh" #include -#if __linux__ +#ifdef __linux__ # include -# include "personality.hh" +# include "nix/store/personality.hh" #endif #include @@ -59,7 +59,7 @@ void execProgramInStore(ref store, throw SysError("could not execute chroot helper"); } -#if __linux__ +#ifdef __linux__ if (system) linux::setPersonality(*system); #endif @@ -153,7 +153,7 @@ void chrootHelper(int argc, char * * argv) while (p < argc) args.push_back(argv[p++]); -#if __linux__ +#ifdef __linux__ uid_t uid = getuid(); uid_t gid = getgid(); @@ -212,7 +212,7 @@ void chrootHelper(int argc, char * * argv) writeFile(fs::path{"/proc/self/uid_map"}, fmt("%d %d %d", uid, uid, 1)); writeFile(fs::path{"/proc/self/gid_map"}, fmt("%d %d %d", gid, gid, 1)); -#if __linux__ +#ifdef __linux__ if (system != "") linux::setPersonality(system); #endif diff --git a/src/nix/run.hh b/src/nix/run.hh index 51517fdc9..9d95b8e7c 100644 --- a/src/nix/run.hh +++ b/src/nix/run.hh @@ -1,7 +1,7 @@ #pragma once ///@file -#include "store-api.hh" +#include "nix/store/store-api.hh" namespace nix { diff --git a/src/nix/search.cc b/src/nix/search.cc index 30b96c500..a27891c93 100644 --- a/src/nix/search.cc +++ b/src/nix/search.cc @@ -1,22 +1,22 @@ -#include "command-installable-value.hh" -#include "globals.hh" -#include "eval.hh" -#include "eval-inline.hh" -#include "eval-settings.hh" -#include "names.hh" -#include "get-drvs.hh" -#include "common-args.hh" -#include "shared.hh" -#include "eval-cache.hh" -#include "attr-path.hh" -#include "hilite.hh" -#include "strings-inline.hh" +#include "nix/cmd/command-installable-value.hh" +#include "nix/store/globals.hh" +#include "nix/expr/eval.hh" +#include "nix/expr/eval-inline.hh" +#include "nix/expr/eval-settings.hh" +#include "nix/store/names.hh" +#include "nix/expr/get-drvs.hh" +#include "nix/main/common-args.hh" +#include "nix/main/shared.hh" +#include "nix/expr/eval-cache.hh" +#include "nix/expr/attr-path.hh" +#include "nix/util/hilite.hh" +#include "nix/util/strings-inline.hh" #include #include #include -#include "strings.hh" +#include "nix/util/strings.hh" using namespace nix; using json = nlohmann::json; diff --git a/src/nix/self-exe.cc b/src/nix/self-exe.cc index 77d20a835..5cc2326be 100644 --- a/src/nix/self-exe.cc +++ b/src/nix/self-exe.cc @@ -1,7 +1,9 @@ -#include "current-process.hh" -#include "file-system.hh" -#include "globals.hh" +#include "nix/util/current-process.hh" +#include "nix/util/file-system.hh" +#include "nix/store/globals.hh" + #include "self-exe.hh" +#include "cli-config-private.hh" namespace nix { diff --git a/src/nix/sigs.cc b/src/nix/sigs.cc index 10b99b452..87d0e1edb 100644 --- a/src/nix/sigs.cc +++ b/src/nix/sigs.cc @@ -1,8 +1,8 @@ -#include "signals.hh" -#include "command.hh" -#include "shared.hh" -#include "store-api.hh" -#include "thread-pool.hh" +#include "nix/util/signals.hh" +#include "nix/cmd/command.hh" +#include "nix/main/shared.hh" +#include "nix/store/store-api.hh" +#include "nix/util/thread-pool.hh" #include diff --git a/src/nix/store-copy-log.cc b/src/nix/store-copy-log.cc index a6e8aeff7..599b40edc 100644 --- a/src/nix/store-copy-log.cc +++ b/src/nix/store-copy-log.cc @@ -1,10 +1,10 @@ -#include "command.hh" -#include "shared.hh" -#include "store-api.hh" -#include "store-cast.hh" -#include "log-store.hh" -#include "sync.hh" -#include "thread-pool.hh" +#include "nix/cmd/command.hh" +#include "nix/main/shared.hh" +#include "nix/store/store-api.hh" +#include "nix/store/store-cast.hh" +#include "nix/store/log-store.hh" +#include "nix/util/sync.hh" +#include "nix/util/thread-pool.hh" #include diff --git a/src/nix/store-delete.cc b/src/nix/store-delete.cc index 6719227df..f71a56bc7 100644 --- a/src/nix/store-delete.cc +++ b/src/nix/store-delete.cc @@ -1,9 +1,9 @@ -#include "command.hh" -#include "common-args.hh" -#include "shared.hh" -#include "store-api.hh" -#include "store-cast.hh" -#include "gc-store.hh" +#include "nix/cmd/command.hh" +#include "nix/main/common-args.hh" +#include "nix/main/shared.hh" +#include "nix/store/store-api.hh" +#include "nix/store/store-cast.hh" +#include "nix/store/gc-store.hh" using namespace nix; diff --git a/src/nix/store-gc.cc b/src/nix/store-gc.cc index 8b9b5d164..e6a303874 100644 --- a/src/nix/store-gc.cc +++ b/src/nix/store-gc.cc @@ -1,9 +1,9 @@ -#include "command.hh" -#include "common-args.hh" -#include "shared.hh" -#include "store-api.hh" -#include "store-cast.hh" -#include "gc-store.hh" +#include "nix/cmd/command.hh" +#include "nix/main/common-args.hh" +#include "nix/main/shared.hh" +#include "nix/store/store-api.hh" +#include "nix/store/store-cast.hh" +#include "nix/store/gc-store.hh" using namespace nix; diff --git a/src/nix/store-info.cc b/src/nix/store-info.cc index a7c595761..8b4ac9b30 100644 --- a/src/nix/store-info.cc +++ b/src/nix/store-info.cc @@ -1,7 +1,7 @@ -#include "command.hh" -#include "shared.hh" -#include "store-api.hh" -#include "finally.hh" +#include "nix/cmd/command.hh" +#include "nix/main/shared.hh" +#include "nix/store/store-api.hh" +#include "nix/util/finally.hh" #include diff --git a/src/nix/store-repair.cc b/src/nix/store-repair.cc index 895e39685..edd699981 100644 --- a/src/nix/store-repair.cc +++ b/src/nix/store-repair.cc @@ -1,5 +1,5 @@ -#include "command.hh" -#include "store-api.hh" +#include "nix/cmd/command.hh" +#include "nix/store/store-api.hh" using namespace nix; diff --git a/src/nix/store.cc b/src/nix/store.cc index 79b41e096..b40b6d068 100644 --- a/src/nix/store.cc +++ b/src/nix/store.cc @@ -1,4 +1,4 @@ -#include "command.hh" +#include "nix/cmd/command.hh" using namespace nix; diff --git a/src/nix/unix/daemon.cc b/src/nix/unix/daemon.cc index b4c7c10ed..607a7bb01 100644 --- a/src/nix/unix/daemon.cc +++ b/src/nix/unix/daemon.cc @@ -1,20 +1,20 @@ ///@file -#include "signals.hh" -#include "unix-domain-socket.hh" -#include "command.hh" -#include "shared.hh" -#include "local-store.hh" -#include "remote-store.hh" -#include "remote-store-connection.hh" -#include "serialise.hh" -#include "archive.hh" -#include "globals.hh" -#include "config-global.hh" -#include "derivations.hh" -#include "finally.hh" -#include "legacy.hh" -#include "daemon.hh" +#include "nix/util/signals.hh" +#include "nix/util/unix-domain-socket.hh" +#include "nix/cmd/command.hh" +#include "nix/main/shared.hh" +#include "nix/store/local-store.hh" +#include "nix/store/remote-store.hh" +#include "nix/store/remote-store-connection.hh" +#include "nix/util/serialise.hh" +#include "nix/util/archive.hh" +#include "nix/store/globals.hh" +#include "nix/util/config-global.hh" +#include "nix/store/derivations.hh" +#include "nix/util/finally.hh" +#include "nix/cmd/legacy.hh" +#include "nix/store/daemon.hh" #include "man-pages.hh" #include @@ -34,11 +34,11 @@ #include #include -#if __linux__ -#include "cgroup.hh" +#ifdef __linux__ +#include "nix/util/cgroup.hh" #endif -#if __APPLE__ || __FreeBSD__ +#if defined(__APPLE__) || defined(__FreeBSD__) #include #endif @@ -317,7 +317,7 @@ static void daemonLoop(std::optional forceTrustClientOpt) // Get rid of children automatically; don't let them become zombies. setSigChldAction(true); - #if __linux__ + #ifdef __linux__ if (settings.useCgroups) { experimentalFeatureSettings.require(Xp::Cgroups); @@ -546,7 +546,7 @@ static int main_nix_daemon(int argc, char * * argv) static RegisterLegacyCommand r_nix_daemon("nix-daemon", main_nix_daemon); -struct CmdDaemon : StoreCommand +struct CmdDaemon : Command { bool stdio = false; std::optional isTrustedOpt = std::nullopt; @@ -615,7 +615,7 @@ struct CmdDaemon : StoreCommand ; } - void run(ref store) override + void run() override { runDaemon(stdio, isTrustedOpt, processOps); } diff --git a/src/nix/upgrade-nix.cc b/src/nix/upgrade-nix.cc index 398e533ce..c0a6e6827 100644 --- a/src/nix/upgrade-nix.cc +++ b/src/nix/upgrade-nix.cc @@ -1,13 +1,13 @@ -#include "processes.hh" -#include "command.hh" -#include "common-args.hh" -#include "store-api.hh" -#include "filetransfer.hh" -#include "eval.hh" -#include "eval-settings.hh" -#include "attr-path.hh" -#include "names.hh" -#include "executable-path.hh" +#include "nix/util/processes.hh" +#include "nix/cmd/command.hh" +#include "nix/main/common-args.hh" +#include "nix/store/store-api.hh" +#include "nix/store/filetransfer.hh" +#include "nix/expr/eval.hh" +#include "nix/expr/eval-settings.hh" +#include "nix/expr/attr-path.hh" +#include "nix/store/names.hh" +#include "nix/util/executable-path.hh" #include "self-exe.hh" using namespace nix; diff --git a/src/nix/verify.cc b/src/nix/verify.cc index 52585fe08..734387ee7 100644 --- a/src/nix/verify.cc +++ b/src/nix/verify.cc @@ -1,13 +1,13 @@ -#include "command.hh" -#include "shared.hh" -#include "store-api.hh" -#include "thread-pool.hh" -#include "signals.hh" -#include "keys.hh" +#include "nix/cmd/command.hh" +#include "nix/main/shared.hh" +#include "nix/store/store-api.hh" +#include "nix/util/thread-pool.hh" +#include "nix/util/signals.hh" +#include "nix/store/keys.hh" #include -#include "exit.hh" +#include "nix/util/exit.hh" using namespace nix; diff --git a/src/nix/why-depends.cc b/src/nix/why-depends.cc index ae5c45ae3..8dfd8343f 100644 --- a/src/nix/why-depends.cc +++ b/src/nix/why-depends.cc @@ -1,7 +1,7 @@ -#include "command.hh" -#include "store-api.hh" -#include "source-accessor.hh" -#include "shared.hh" +#include "nix/cmd/command.hh" +#include "nix/store/store-api.hh" +#include "nix/util/source-accessor.hh" +#include "nix/main/shared.hh" #include diff --git a/src/perl/lib/Nix/Store.xs b/src/perl/lib/Nix/Store.xs index cfc3ac034..34ed8b5f0 100644 --- a/src/perl/lib/Nix/Store.xs +++ b/src/perl/lib/Nix/Store.xs @@ -1,6 +1,3 @@ -#include "config-util.hh" -#include "config-store.hh" - #include "EXTERN.h" #include "perl.h" #include "XSUB.h" @@ -9,11 +6,11 @@ #undef do_open #undef do_close -#include "derivations.hh" -#include "realisation.hh" -#include "globals.hh" -#include "store-api.hh" -#include "posix-source-accessor.hh" +#include "nix/store/derivations.hh" +#include "nix/store/realisation.hh" +#include "nix/store/globals.hh" +#include "nix/store/store-api.hh" +#include "nix/util/posix-source-accessor.hh" #include #include diff --git a/src/perl/package.nix b/src/perl/package.nix index d948cbcdc..f7e81b66a 100644 --- a/src/perl/package.nix +++ b/src/perl/package.nix @@ -31,7 +31,7 @@ perl.pkgs.toPerlModule ( ./meson.build ./meson.options ] - ++ lib.optionals finalAttrs.doCheck [ + ++ lib.optionals finalAttrs.finalPackage.doCheck [ ./.yath.rc.in ./t ] @@ -70,7 +70,7 @@ perl.pkgs.toPerlModule ( mesonFlags = [ (lib.mesonOption "dbi_path" "${perlPackages.DBI}/${perl.libPrefix}") (lib.mesonOption "dbd_sqlite_path" "${perlPackages.DBDSQLite}/${perl.libPrefix}") - (lib.mesonEnable "tests" finalAttrs.doCheck) + (lib.mesonEnable "tests" finalAttrs.finalPackage.doCheck) ]; mesonCheckFlags = [ diff --git a/tests/functional/check-refs.nix b/tests/functional/check-refs.nix index 471d95753..bdd5c4f8d 100644 --- a/tests/functional/check-refs.nix +++ b/tests/functional/check-refs.nix @@ -79,4 +79,13 @@ rec { buildCommand = ''echo ${dep} > "''${outputs[out]}"''; }; + test12 = makeTest 12 { + builder = builtins.toFile "builder.sh" "mkdir $out $lib"; + outputs = [ + "out" + "lib" + ]; + disallowedReferences = [ "dev" ]; + }; + } diff --git a/tests/functional/check-refs.sh b/tests/functional/check-refs.sh index 5c3ac915e..590c3fb53 100755 --- a/tests/functional/check-refs.sh +++ b/tests/functional/check-refs.sh @@ -60,3 +60,9 @@ if ! isTestOnNixOS; then fi fi + +if isDaemonNewer "2.28pre20241225"; then + # test12 should fail (syntactically invalid). + expectStderr 1 nix-build -vvv -o "$RESULT" check-refs.nix -A test12 >"$TEST_ROOT/test12.stderr" + grepQuiet -F "output check for 'lib' contains an illegal reference specifier 'dev', expected store path or output name (one of [lib, out])" < "$TEST_ROOT/test12.stderr" +fi diff --git a/tests/functional/plugins/meson.build b/tests/functional/plugins/meson.build index 3d6b2f0e1..ae66e3036 100644 --- a/tests/functional/plugins/meson.build +++ b/tests/functional/plugins/meson.build @@ -1,14 +1,6 @@ libplugintest = shared_module( 'plugintest', 'plugintest.cc', - cpp_args : [ - # TODO(Qyriad): Yes this is how the autoconf+Make system did it. - # It would be nice for our headers to be idempotent instead. - '-include', 'config-util.hh', - '-include', 'config-store.hh', - # '-include', 'config-fetchers.hh', - '-include', 'config-expr.hh', - ], dependencies : [ dependency('nix-expr'), ], diff --git a/tests/functional/plugins/plugintest.cc b/tests/functional/plugins/plugintest.cc index 7433ad190..0b1a01a6e 100644 --- a/tests/functional/plugins/plugintest.cc +++ b/tests/functional/plugins/plugintest.cc @@ -1,5 +1,5 @@ -#include "config-global.hh" -#include "primops.hh" +#include "nix/util/config-global.hh" +#include "nix/expr/primops.hh" using namespace nix; diff --git a/tests/functional/repl.sh b/tests/functional/repl.sh index 3235e216a..82de2b4fa 100755 --- a/tests/functional/repl.sh +++ b/tests/functional/repl.sh @@ -56,6 +56,10 @@ testRepl () { nix repl "${nixArgs[@]}" 2>&1 <<< "builtins.currentSystem" \ | grep "$(nix-instantiate --eval -E 'builtins.currentSystem')" + # regression test for #12163 + replOutput=$(nix repl "${nixArgs[@]}" 2>&1 <<< ":sh import $testDir/simple.nix") + echo "$replOutput" | grepInverse "error: Cannot run 'nix-shell'" + expectStderr 1 nix repl "${testDir}/simple.nix" \ | grepQuiet -s "error: path '$testDir/simple.nix' is not a flake" } diff --git a/tests/functional/test-libstoreconsumer/main.cc b/tests/functional/test-libstoreconsumer/main.cc index c61489af6..2c0402094 100644 --- a/tests/functional/test-libstoreconsumer/main.cc +++ b/tests/functional/test-libstoreconsumer/main.cc @@ -1,6 +1,6 @@ -#include "globals.hh" -#include "store-api.hh" -#include "build-result.hh" +#include "nix/store/globals.hh" +#include "nix/store/store-api.hh" +#include "nix/store/build-result.hh" #include using namespace nix; diff --git a/tests/functional/test-libstoreconsumer/meson.build b/tests/functional/test-libstoreconsumer/meson.build index 7076127f7..e5a1cc182 100644 --- a/tests/functional/test-libstoreconsumer/meson.build +++ b/tests/functional/test-libstoreconsumer/meson.build @@ -1,12 +1,6 @@ libstoreconsumer_tester = executable( 'test-libstoreconsumer', 'main.cc', - cpp_args : [ - # TODO(Qyriad): Yes this is how the autoconf+Make system did it. - # It would be nice for our headers to be idempotent instead. - '-include', 'config-util.hh', - '-include', 'config-store.hh', - ], dependencies : [ dependency('nix-store'), ], diff --git a/tests/nixos/ca-fd-leak/sender.c b/tests/nixos/ca-fd-leak/sender.c index 8356b2479..2ec79947a 100644 --- a/tests/nixos/ca-fd-leak/sender.c +++ b/tests/nixos/ca-fd-leak/sender.c @@ -19,7 +19,7 @@ int main(int argc, char **argv) { struct sockaddr_un data; data.sun_family = AF_UNIX; data.sun_path[0] = 0; - strcpy(data.sun_path + 1, argv[1]); + strncpy(data.sun_path + 1, argv[1], sizeof(data.sun_path) - 2); // Now try to connect, To ensure we work no matter what order we are // executed in, just busyloop here. diff --git a/tests/nixos/ca-fd-leak/smuggler.c b/tests/nixos/ca-fd-leak/smuggler.c index 3f89af5bb..7279c48bf 100644 --- a/tests/nixos/ca-fd-leak/smuggler.c +++ b/tests/nixos/ca-fd-leak/smuggler.c @@ -5,6 +5,7 @@ #include #include #include +#include int main(int argc, char **argv) {