1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2024-10-18 00:16:11 -04:00

Compare commits

...

20 commits

Author SHA1 Message Date
Bryan Honof 6045b9154d
Merge 35599b8f86 into 694c378d14 2024-10-17 22:06:18 +00:00
John Ericson 694c378d14
Merge pull request #11708 from obsidiansystems/move-tests
Move unit tests to the location Meson expects them to be
2024-10-17 16:15:34 -04:00
John Ericson e65510da56 Move unit tests to the location Meson expects them to be
Everything that is a separate subproject should live in the subprojects
directory.

Progress on #2503

This reverts commit 451f8a8c19.
2024-10-17 15:42:16 -04:00
Eelco Dolstra 1cd48008f0
Merge pull request #11710 from NixOS/doc-onboarding
maintainers/onboarding: Start documenting
2024-10-17 11:06:23 +02:00
Eelco Dolstra 2e2c7f3b14
Merge pull request #11709 from DeterminateSystems/remove-team-list
maintainers/README.md: Remove the list of team members
2024-10-17 11:05:55 +02:00
Robert Hensing c196011d23 maintainers/onboarding: Start documenting 2024-10-16 22:06:28 +02:00
Eelco Dolstra 7bd0c70b37 maintainers/README.md: Remove the list of team members
Let's have one canonical location for the team membership.
2024-10-16 22:03:44 +02:00
Robert Hensing f51974d698
Merge pull request #11665 from roberth/fix-Interrupted-falling-out-of-thread
Fix `Interrupted` falling out of thread crash
2024-10-16 20:09:29 +02:00
Robert Hensing ed184f0b61
Typo
Co-authored-by: Cole Helbling <cole.e.helbling@outlook.com>
2024-10-16 19:40:45 +02:00
Eelco Dolstra facc502bc8
Merge pull request #11695 from DeterminateSystems/override-lastModified
path fetcher: Allow the lastModified attribute to be overriden again
2024-10-16 18:03:29 +02:00
Robert Hensing fd8a4a86d9 ThreadPool: don't silently ignore non-std exceptions
Introduced in 8f6b347abd without explanation.

Throwing anything that's not that is a programming mistake that we don't want
to ignore silently. A crash would be ok, because that means we/they can fix
the offending throw.
2024-10-16 17:56:08 +02:00
Robert Hensing 16320f6d24 Handle ThreadPoolShutdown with normal catch 2024-10-16 17:56:08 +02:00
Robert Hensing 3f9ff10786 ThreadPool: catch Interrupted 2024-10-16 17:56:08 +02:00
Robert Hensing de41e46175 Document recursive-nix startDaemon/stopDaemon 2024-10-16 17:56:08 +02:00
Robert Hensing 0e5a5303ad fix: Ignore Interrupted in recursive-nix daemon worker
Otherwise, if checkInterrupt() in any of the supported store operations
would catch onto a user interrupt, the exception would bubble to the thread
start and be handled by std::terminate(): a crash.
2024-10-16 17:56:08 +02:00
Eelco Dolstra 781ff7672e Add test 2024-10-16 17:18:07 +02:00
Eelco Dolstra 5d35424445 path fetcher: Allow the lastModified attribute to be overriden again
Fixes #11660.
2024-10-14 16:17:18 +02:00
Bryan Honof 35599b8f86
chore: run formatters 2024-09-29 15:13:41 +02:00
Bryan Honof a3aaa573c4
test(functional): add tests for new environment operation flags
Refs: nixos/nix#10795
2024-09-29 15:13:41 +02:00
Bryan Honof d68b2a7c1b
feat: add flag set-env-var to MixEnvironment 2024-09-29 15:13:23 +02:00
281 changed files with 394 additions and 273 deletions

2
.github/labeler.yml vendored
View file

@ -1,7 +1,7 @@
"c api": "c api":
- changed-files: - changed-files:
- any-glob-to-any-file: "src/lib*-c/**/*" - any-glob-to-any-file: "src/lib*-c/**/*"
- any-glob-to-any-file: "test/unit/**/nix_api_*" - any-glob-to-any-file: "src/*test*/**/nix_api_*"
- any-glob-to-any-file: "doc/external-api/**/*" - any-glob-to-any-file: "doc/external-api/**/*"
"contributor-experience": "contributor-experience":

10
.gitignore vendored
View file

@ -49,22 +49,22 @@ perl/Makefile.config
/src/libexpr/parser-tab.output /src/libexpr/parser-tab.output
/src/libexpr/nix.tbl /src/libexpr/nix.tbl
/src/libexpr/tests /src/libexpr/tests
/tests/unit/libexpr/libnixexpr-tests /src/libexpr-tests/libnixexpr-tests
# /src/libfetchers # /src/libfetchers
/tests/unit/libfetchers/libnixfetchers-tests /src/libfetchers-tests/libnixfetchers-tests
# /src/libflake # /src/libflake
/tests/unit/libflake/libnixflake-tests /src/libflake-tests/libnixflake-tests
# /src/libstore/ # /src/libstore/
*.gen.* *.gen.*
/src/libstore/tests /src/libstore/tests
/tests/unit/libstore/libnixstore-tests /src/libstore-tests/libnixstore-tests
# /src/libutil/ # /src/libutil/
/src/libutil/tests /src/libutil/tests
/tests/unit/libutil/libnixutil-tests /src/libutil-tests/libnixutil-tests
/src/nix/nix /src/nix/nix

View file

@ -40,14 +40,14 @@ endif
ifeq ($(ENABLE_UNIT_TESTS), yes) ifeq ($(ENABLE_UNIT_TESTS), yes)
makefiles += \ makefiles += \
tests/unit/libutil/local.mk \ src/libutil-tests/local.mk \
tests/unit/libutil-support/local.mk \ src/libutil-test-support/local.mk \
tests/unit/libstore/local.mk \ src/libstore-tests/local.mk \
tests/unit/libstore-support/local.mk \ src/libstore-test-support/local.mk \
tests/unit/libfetchers/local.mk \ src/libfetchers-tests/local.mk \
tests/unit/libexpr/local.mk \ src/libexpr-tests/local.mk \
tests/unit/libexpr-support/local.mk \ src/libexpr-test-support/local.mk \
tests/unit/libflake/local.mk src/libflake-tests/local.mk
endif endif
ifeq ($(ENABLE_FUNCTIONAL_TESTS), yes) ifeq ($(ENABLE_FUNCTIONAL_TESTS), yes)

View file

@ -60,10 +60,10 @@ 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`. 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/nix-expr-tests/value/context.cc`, and (possibly) declare/define additional interfaces for testing purposes in `src/nix-expr-test-support/tests/value/context.{hh,cc}`. 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}`.
Data for unit tests is stored in a `data` subdir of the directory for each unit test executable. 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/nix-store-tests/data`. For example, `libnixstore` code is in `src/libstore`, and its test data is in `src/libstore-tests/data`.
The path to the `src/${library_name_without-nix}-test/data` directory is passed to the unit test executable with the environment variable `_NIX_TEST_UNIT_DATA`. The path to the `src/${library_name_without-nix}-test/data` directory is passed to the unit test executable with the environment variable `_NIX_TEST_UNIT_DATA`.
Note that each executable only gets the data for its tests. Note that each executable only gets the data for its tests.

View file

@ -29,11 +29,7 @@ We aim to achieve this by improving the contributor experience and attracting mo
## Members ## Members
- Eelco Dolstra (@edolstra) Team lead See https://nixos.org/community/teams/nix/ for the current team membership.
- Valentin Gagarin (@fricklerhandwerk)
- Thomas Bereknyei (@tomberek)
- Robert Hensing (@roberth)
- John Ericson (@Ericson2314)
The team is on Github as [@NixOS/nix-team](https://github.com/orgs/NixOS/teams/nix-team). The team is on Github as [@NixOS/nix-team](https://github.com/orgs/NixOS/teams/nix-team).

View file

@ -15,7 +15,7 @@
excludes = [ excludes = [
# We don't want to format test data # We don't want to format test data
# ''tests/(?!nixos/).*\.nix'' # ''tests/(?!nixos/).*\.nix''
''^tests/unit/[^/]*/data/.*$'' ''^src/[^/]*-tests/data/.*$''
# Don't format vendored code # Don't format vendored code
''^doc/manual/redirects\.js$'' ''^doc/manual/redirects\.js$''
@ -28,8 +28,6 @@
''^src/build-remote/build-remote\.cc$'' ''^src/build-remote/build-remote\.cc$''
''^src/libcmd/built-path\.cc$'' ''^src/libcmd/built-path\.cc$''
''^src/libcmd/built-path\.hh$'' ''^src/libcmd/built-path\.hh$''
''^src/libcmd/command\.cc$''
''^src/libcmd/command\.hh$''
''^src/libcmd/common-eval-args\.cc$'' ''^src/libcmd/common-eval-args\.cc$''
''^src/libcmd/common-eval-args\.hh$'' ''^src/libcmd/common-eval-args\.hh$''
''^src/libcmd/editor-for\.cc$'' ''^src/libcmd/editor-for\.cc$''
@ -427,64 +425,64 @@
''^tests/nixos/ca-fd-leak/sender\.c'' ''^tests/nixos/ca-fd-leak/sender\.c''
''^tests/nixos/ca-fd-leak/smuggler\.c'' ''^tests/nixos/ca-fd-leak/smuggler\.c''
''^tests/nixos/user-sandboxing/attacker\.c'' ''^tests/nixos/user-sandboxing/attacker\.c''
''^tests/unit/libexpr-support/tests/libexpr\.hh'' ''^src/libexpr-test-support/tests/libexpr\.hh''
''^tests/unit/libexpr-support/tests/value/context\.cc'' ''^src/libexpr-test-support/tests/value/context\.cc''
''^tests/unit/libexpr-support/tests/value/context\.hh'' ''^src/libexpr-test-support/tests/value/context\.hh''
''^tests/unit/libexpr/derived-path\.cc'' ''^src/libexpr-tests/derived-path\.cc''
''^tests/unit/libexpr/error_traces\.cc'' ''^src/libexpr-tests/error_traces\.cc''
''^tests/unit/libexpr/eval\.cc'' ''^src/libexpr-tests/eval\.cc''
''^tests/unit/libexpr/json\.cc'' ''^src/libexpr-tests/json\.cc''
''^tests/unit/libexpr/main\.cc'' ''^src/libexpr-tests/main\.cc''
''^tests/unit/libexpr/primops\.cc'' ''^src/libexpr-tests/primops\.cc''
''^tests/unit/libexpr/search-path\.cc'' ''^src/libexpr-tests/search-path\.cc''
''^tests/unit/libexpr/trivial\.cc'' ''^src/libexpr-tests/trivial\.cc''
''^tests/unit/libexpr/value/context\.cc'' ''^src/libexpr-tests/value/context\.cc''
''^tests/unit/libexpr/value/print\.cc'' ''^src/libexpr-tests/value/print\.cc''
''^tests/unit/libfetchers/public-key\.cc'' ''^src/libfetchers-tests/public-key\.cc''
''^tests/unit/libflake/flakeref\.cc'' ''^src/libflake-tests/flakeref\.cc''
''^tests/unit/libflake/url-name\.cc'' ''^src/libflake-tests/url-name\.cc''
''^tests/unit/libstore-support/tests/derived-path\.cc'' ''^src/libstore-test-support/tests/derived-path\.cc''
''^tests/unit/libstore-support/tests/derived-path\.hh'' ''^src/libstore-test-support/tests/derived-path\.hh''
''^tests/unit/libstore-support/tests/nix_api_store\.hh'' ''^src/libstore-test-support/tests/nix_api_store\.hh''
''^tests/unit/libstore-support/tests/outputs-spec\.cc'' ''^src/libstore-test-support/tests/outputs-spec\.cc''
''^tests/unit/libstore-support/tests/outputs-spec\.hh'' ''^src/libstore-test-support/tests/outputs-spec\.hh''
''^tests/unit/libstore-support/tests/path\.cc'' ''^src/libstore-test-support/tests/path\.cc''
''^tests/unit/libstore-support/tests/path\.hh'' ''^src/libstore-test-support/tests/path\.hh''
''^tests/unit/libstore-support/tests/protocol\.hh'' ''^src/libstore-test-support/tests/protocol\.hh''
''^tests/unit/libstore/common-protocol\.cc'' ''^src/libstore-tests/common-protocol\.cc''
''^tests/unit/libstore/content-address\.cc'' ''^src/libstore-tests/content-address\.cc''
''^tests/unit/libstore/derivation\.cc'' ''^src/libstore-tests/derivation\.cc''
''^tests/unit/libstore/derived-path\.cc'' ''^src/libstore-tests/derived-path\.cc''
''^tests/unit/libstore/downstream-placeholder\.cc'' ''^src/libstore-tests/downstream-placeholder\.cc''
''^tests/unit/libstore/machines\.cc'' ''^src/libstore-tests/machines\.cc''
''^tests/unit/libstore/nar-info-disk-cache\.cc'' ''^src/libstore-tests/nar-info-disk-cache\.cc''
''^tests/unit/libstore/nar-info\.cc'' ''^src/libstore-tests/nar-info\.cc''
''^tests/unit/libstore/outputs-spec\.cc'' ''^src/libstore-tests/outputs-spec\.cc''
''^tests/unit/libstore/path-info\.cc'' ''^src/libstore-tests/path-info\.cc''
''^tests/unit/libstore/path\.cc'' ''^src/libstore-tests/path\.cc''
''^tests/unit/libstore/serve-protocol\.cc'' ''^src/libstore-tests/serve-protocol\.cc''
''^tests/unit/libstore/worker-protocol\.cc'' ''^src/libstore-tests/worker-protocol\.cc''
''^tests/unit/libutil-support/tests/characterization\.hh'' ''^src/libutil-test-support/tests/characterization\.hh''
''^tests/unit/libutil-support/tests/hash\.cc'' ''^src/libutil-test-support/tests/hash\.cc''
''^tests/unit/libutil-support/tests/hash\.hh'' ''^src/libutil-test-support/tests/hash\.hh''
''^tests/unit/libutil/args\.cc'' ''^src/libutil-tests/args\.cc''
''^tests/unit/libutil/canon-path\.cc'' ''^src/libutil-tests/canon-path\.cc''
''^tests/unit/libutil/chunked-vector\.cc'' ''^src/libutil-tests/chunked-vector\.cc''
''^tests/unit/libutil/closure\.cc'' ''^src/libutil-tests/closure\.cc''
''^tests/unit/libutil/compression\.cc'' ''^src/libutil-tests/compression\.cc''
''^tests/unit/libutil/config\.cc'' ''^src/libutil-tests/config\.cc''
''^tests/unit/libutil/file-content-address\.cc'' ''^src/libutil-tests/file-content-address\.cc''
''^tests/unit/libutil/git\.cc'' ''^src/libutil-tests/git\.cc''
''^tests/unit/libutil/hash\.cc'' ''^src/libutil-tests/hash\.cc''
''^tests/unit/libutil/hilite\.cc'' ''^src/libutil-tests/hilite\.cc''
''^tests/unit/libutil/json-utils\.cc'' ''^src/libutil-tests/json-utils\.cc''
''^tests/unit/libutil/logging\.cc'' ''^src/libutil-tests/logging\.cc''
''^tests/unit/libutil/lru-cache\.cc'' ''^src/libutil-tests/lru-cache\.cc''
''^tests/unit/libutil/pool\.cc'' ''^src/libutil-tests/pool\.cc''
''^tests/unit/libutil/references\.cc'' ''^src/libutil-tests/references\.cc''
''^tests/unit/libutil/suggestions\.cc'' ''^src/libutil-tests/suggestions\.cc''
''^tests/unit/libutil/url\.cc'' ''^src/libutil-tests/url\.cc''
''^tests/unit/libutil/xml-writer\.cc'' ''^src/libutil-tests/xml-writer\.cc''
]; ];
}; };
shellcheck = { shellcheck = {
@ -552,7 +550,6 @@
''^tests/functional/flakes/check\.sh$'' ''^tests/functional/flakes/check\.sh$''
''^tests/functional/flakes/common\.sh$'' ''^tests/functional/flakes/common\.sh$''
''^tests/functional/flakes/config\.sh$'' ''^tests/functional/flakes/config\.sh$''
''^tests/functional/flakes/develop\.sh$''
''^tests/functional/flakes/flakes\.sh$'' ''^tests/functional/flakes/flakes\.sh$''
''^tests/functional/flakes/follow-paths\.sh$'' ''^tests/functional/flakes/follow-paths\.sh$''
''^tests/functional/flakes/prefetch\.sh$'' ''^tests/functional/flakes/prefetch\.sh$''
@ -650,7 +647,7 @@
''^tests/functional/user-envs\.sh$'' ''^tests/functional/user-envs\.sh$''
''^tests/functional/why-depends\.sh$'' ''^tests/functional/why-depends\.sh$''
''^tests/functional/zstd\.sh$'' ''^tests/functional/zstd\.sh$''
''^tests/unit/libutil/data/git/check-data\.sh$'' ''^src/libutil-tests/data/git/check-data\.sh$''
]; ];
}; };
# TODO: nixfmt, https://github.com/NixOS/nixfmt/issues/153 # TODO: nixfmt, https://github.com/NixOS/nixfmt/issues/153

View file

@ -0,0 +1,6 @@
# Onboarding a new team member
- https://github.com/NixOS/nixos-homepage/
- https://github.com/orgs/NixOS/teams/nix-team
- Matrix room

View file

@ -40,12 +40,12 @@ if not meson.is_cross_build()
endif endif
# Testing # Testing
subproject('nix-util-test-support') subproject('libutil-test-support')
subproject('nix-util-tests') subproject('libutil-tests')
subproject('nix-store-test-support') subproject('libstore-test-support')
subproject('nix-store-tests') subproject('libstore-tests')
subproject('nix-fetchers-tests') subproject('libfetchers-tests')
subproject('nix-expr-test-support') subproject('libexpr-test-support')
subproject('nix-expr-tests') subproject('libexpr-tests')
subproject('nix-flake-tests') subproject('libflake-tests')
subproject('nix-functional-tests') subproject('nix-functional-tests')

View file

@ -176,8 +176,6 @@ in {
./scripts/local.mk ./scripts/local.mk
] ++ lib.optionals enableManual [ ] ++ lib.optionals enableManual [
./doc/manual ./doc/manual
] ++ lib.optionals buildUnitTests [
./tests/unit
] ++ lib.optionals doInstallCheck [ ] ++ lib.optionals doInstallCheck [
./tests/functional ./tests/functional
])); ]));

View file

@ -32,24 +32,24 @@ in
nix-util = callPackage ../src/libutil/package.nix { }; nix-util = callPackage ../src/libutil/package.nix { };
nix-util-c = callPackage ../src/libutil-c/package.nix { }; nix-util-c = callPackage ../src/libutil-c/package.nix { };
nix-util-test-support = callPackage ../tests/unit/libutil-support/package.nix { }; nix-util-test-support = callPackage ../src/libutil-test-support/package.nix { };
nix-util-tests = callPackage ../tests/unit/libutil/package.nix { }; nix-util-tests = callPackage ../src/libutil-tests/package.nix { };
nix-store = callPackage ../src/libstore/package.nix { }; nix-store = callPackage ../src/libstore/package.nix { };
nix-store-c = callPackage ../src/libstore-c/package.nix { }; nix-store-c = callPackage ../src/libstore-c/package.nix { };
nix-store-test-support = callPackage ../tests/unit/libstore-support/package.nix { }; nix-store-test-support = callPackage ../src/libstore-test-support/package.nix { };
nix-store-tests = callPackage ../tests/unit/libstore/package.nix { }; nix-store-tests = callPackage ../src/libstore-tests/package.nix { };
nix-fetchers = callPackage ../src/libfetchers/package.nix { }; nix-fetchers = callPackage ../src/libfetchers/package.nix { };
nix-fetchers-tests = callPackage ../tests/unit/libfetchers/package.nix { }; nix-fetchers-tests = callPackage ../src/libfetchers-tests/package.nix { };
nix-expr = callPackage ../src/libexpr/package.nix { }; nix-expr = callPackage ../src/libexpr/package.nix { };
nix-expr-c = callPackage ../src/libexpr-c/package.nix { }; nix-expr-c = callPackage ../src/libexpr-c/package.nix { };
nix-expr-test-support = callPackage ../tests/unit/libexpr-support/package.nix { }; nix-expr-test-support = callPackage ../src/libexpr-test-support/package.nix { };
nix-expr-tests = callPackage ../tests/unit/libexpr/package.nix { }; nix-expr-tests = callPackage ../src/libexpr-tests/package.nix { };
nix-flake = callPackage ../src/libflake/package.nix { }; nix-flake = callPackage ../src/libflake/package.nix { };
nix-flake-tests = callPackage ../tests/unit/libflake/package.nix { }; nix-flake-tests = callPackage ../src/libflake-tests/package.nix { };
nix-main = callPackage ../src/libmain/package.nix { }; nix-main = callPackage ../src/libmain/package.nix { };
nix-main-c = callPackage ../src/libmain-c/package.nix { }; nix-main-c = callPackage ../src/libmain-c/package.nix { };

View file

@ -41,21 +41,21 @@ INPUT = \
@src@/libcmd \ @src@/libcmd \
@src@/libexpr \ @src@/libexpr \
@src@/libexpr/flake \ @src@/libexpr/flake \
@src@/nix-expr-tests \ @src@/libexpr-tests \
@src@/nix-expr-tests/value \ @src@/libexpr-tests/value \
@src@/nix-expr-test-support/test \ @src@/libexpr-test-support/test \
@src@/nix-expr-test-support/test/value \ @src@/libexpr-test-support/test/value \
@src@/libexpr/value \ @src@/libexpr/value \
@src@/libfetchers \ @src@/libfetchers \
@src@/libmain \ @src@/libmain \
@src@/libstore \ @src@/libstore \
@src@/libstore/build \ @src@/libstore/build \
@src@/libstore/builtins \ @src@/libstore/builtins \
@src@/nix-store-tests \ @src@/libstore-tests \
@src@/nix-store-test-support/test \ @src@/libstore-test-support/test \
@src@/libutil \ @src@/libutil \
@src@/nix-util-tests \ @src@/libutil-tests \
@src@/nix-util-test-support/test \ @src@/libutil-test-support/test \
@src@/nix \ @src@/nix \
@src@/nix-env \ @src@/nix-env \
@src@/nix-store @src@/nix-store

View file

@ -1,3 +1,4 @@
#include <algorithm>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include "command.hh" #include "command.hh"
@ -9,8 +10,7 @@
#include "profiles.hh" #include "profiles.hh"
#include "repl.hh" #include "repl.hh"
#include "strings.hh" #include "strings.hh"
#include "environment-variables.hh"
extern char * * environ __attribute__((weak));
namespace nix { namespace nix {
@ -23,7 +23,8 @@ nix::Commands RegisterCommand::getCommandsFor(const std::vector<std::string> & p
if (name.size() == prefix.size() + 1) { if (name.size() == prefix.size() + 1) {
bool equal = true; bool equal = true;
for (size_t i = 0; i < prefix.size(); ++i) for (size_t i = 0; i < prefix.size(); ++i)
if (name[i] != prefix[i]) equal = false; if (name[i] != prefix[i])
equal = false;
if (equal) if (equal)
res.insert_or_assign(name[prefix.size()], command); res.insert_or_assign(name[prefix.size()], command);
} }
@ -42,16 +43,16 @@ void NixMultiCommand::run()
std::set<std::string> subCommandTextLines; std::set<std::string> subCommandTextLines;
for (auto & [name, _] : commands) for (auto & [name, _] : commands)
subCommandTextLines.insert(fmt("- `%s`", name)); subCommandTextLines.insert(fmt("- `%s`", name));
std::string markdownError = fmt("`nix %s` requires a sub-command. Available sub-commands:\n\n%s\n", std::string markdownError =
commandName, concatStringsSep("\n", subCommandTextLines)); fmt("`nix %s` requires a sub-command. Available sub-commands:\n\n%s\n",
commandName,
concatStringsSep("\n", subCommandTextLines));
throw UsageError(renderMarkdownToTerminal(markdownError)); throw UsageError(renderMarkdownToTerminal(markdownError));
} }
command->second->run(); command->second->run();
} }
StoreCommand::StoreCommand() StoreCommand::StoreCommand() {}
{
}
ref<Store> StoreCommand::getStore() ref<Store> StoreCommand::getStore()
{ {
@ -126,10 +127,8 @@ ref<Store> EvalCommand::getEvalStore()
ref<EvalState> EvalCommand::getEvalState() ref<EvalState> EvalCommand::getEvalState()
{ {
if (!evalState) { if (!evalState) {
evalState = evalState = std::allocate_shared<EvalState>(
std::allocate_shared<EvalState>( traceable_allocator<EvalState>(), lookupPath, getEvalStore(), fetchSettings, evalSettings, getStore());
traceable_allocator<EvalState>(),
lookupPath, getEvalStore(), fetchSettings, evalSettings, getStore());
evalState->repair = repair; evalState->repair = repair;
@ -144,7 +143,8 @@ MixOperateOnOptions::MixOperateOnOptions()
{ {
addFlag({ addFlag({
.longName = "derivation", .longName = "derivation",
.description = "Operate on the [store derivation](@docroot@/glossary.md#gloss-store-derivation) rather than its outputs.", .description =
"Operate on the [store derivation](@docroot@/glossary.md#gloss-store-derivation) rather than its outputs.",
.category = installablesCategory, .category = installablesCategory,
.handler = {&operateOn, OperateOn::Derivation}, .handler = {&operateOn, OperateOn::Derivation},
}); });
@ -233,46 +233,48 @@ void StorePathCommand::run(ref<Store> store, StorePaths && storePaths)
MixProfile::MixProfile() MixProfile::MixProfile()
{ {
addFlag({ addFlag(
.longName = "profile", {.longName = "profile",
.description = "The profile to operate on.", .description = "The profile to operate on.",
.labels = {"path"}, .labels = {"path"},
.handler = {&profile}, .handler = {&profile},
.completer = completePath .completer = completePath});
});
} }
void MixProfile::updateProfile(const StorePath & storePath) void MixProfile::updateProfile(const StorePath & storePath)
{ {
if (!profile) return; if (!profile)
return;
auto store = getStore().dynamic_pointer_cast<LocalFSStore>(); auto store = getStore().dynamic_pointer_cast<LocalFSStore>();
if (!store) throw Error("'--profile' is not supported for this Nix store"); if (!store)
throw Error("'--profile' is not supported for this Nix store");
auto profile2 = absPath(*profile); auto profile2 = absPath(*profile);
switchLink(profile2, switchLink(profile2, createGeneration(*store, profile2, storePath));
createGeneration(*store, profile2, storePath));
} }
void MixProfile::updateProfile(const BuiltPaths & buildables) void MixProfile::updateProfile(const BuiltPaths & buildables)
{ {
if (!profile) return; if (!profile)
return;
StorePaths result; StorePaths result;
for (auto & buildable : buildables) { for (auto & buildable : buildables) {
std::visit(overloaded { std::visit(
[&](const BuiltPath::Opaque & bo) { overloaded{
result.push_back(bo.path); [&](const BuiltPath::Opaque & bo) { result.push_back(bo.path); },
[&](const BuiltPath::Built & bfd) {
for (auto & output : bfd.outputs) {
result.push_back(output.second);
}
},
}, },
[&](const BuiltPath::Built & bfd) { buildable.raw());
for (auto & output : bfd.outputs) {
result.push_back(output.second);
}
},
}, buildable.raw());
} }
if (result.size() != 1) if (result.size() != 1)
throw UsageError("'--profile' requires that the arguments produce a single store path, but there are %d", result.size()); throw UsageError(
"'--profile' requires that the arguments produce a single store path, but there are %d", result.size());
updateProfile(result[0]); updateProfile(result[0]);
} }
@ -282,51 +284,78 @@ MixDefaultProfile::MixDefaultProfile()
profile = getDefaultProfile(); profile = getDefaultProfile();
} }
MixEnvironment::MixEnvironment() : ignoreEnvironment(false) MixEnvironment::MixEnvironment()
: ignoreEnvironment(false)
{ {
addFlag({ addFlag({
.longName = "ignore-environment", .longName = "ignore-env",
.aliases = {"ignore-environment"},
.shortName = 'i', .shortName = 'i',
.description = "Clear the entire environment (except those specified with `--keep`).", .description = "Clear the entire environment, except for those specified with `--keep-env-var`. "
"Alias for `--ignore-environment`.",
.category = environmentVariablesCategory,
.handler = {&ignoreEnvironment, true}, .handler = {&ignoreEnvironment, true},
}); });
addFlag({ addFlag({
.longName = "keep", .longName = "keep-env-var",
.aliases = {"keep"},
.shortName = 'k', .shortName = 'k',
.description = "Keep the environment variable *name*.", .description = "Keep the environment variable *name*, when using `--ignore-env`. "
"Alias for `--keep`.",
.category = environmentVariablesCategory,
.labels = {"name"}, .labels = {"name"},
.handler = {[&](std::string s) { keep.insert(s); }}, .handler = {[&](std::string s) { keepVars.insert(s); }},
}); });
addFlag({ addFlag({
.longName = "unset", .longName = "unset-env-var",
.aliases = {"unset"},
.shortName = 'u', .shortName = 'u',
.description = "Unset the environment variable *name*.", .description = "Unset the environment variable *name*. "
"Alias for `--unset`.",
.category = environmentVariablesCategory,
.labels = {"name"}, .labels = {"name"},
.handler = {[&](std::string s) { unset.insert(s); }}, .handler = {[&](std::string s) { unsetVars.insert(s); }},
});
addFlag({
.longName = "set-env-var",
.shortName = 's',
.description = "Add/override an environment variable *name* with *value*.\n\n"
"> **Notes**\n"
">\n"
"> Duplicate definitions will be overwritten, last one wins.\n\n"
"> Cancles out with `--unset-env-var`.\n\n",
.category = environmentVariablesCategory,
.labels = {"name", "value"},
.handler = {[&](std::string name, std::string value) { setVars.insert_or_assign(name, value); }},
}); });
} }
void MixEnvironment::setEnviron() { void MixEnvironment::setEnviron()
if (ignoreEnvironment) { {
if (!unset.empty()) if (ignoreEnvironment && !unsetVars.empty())
throw UsageError("--unset does not make sense with --ignore-environment"); throw UsageError("--unset-env-var does not make sense with --ignore-env");
for (const auto & var : keep) { if (!ignoreEnvironment && !keepVars.empty())
auto val = getenv(var.c_str()); throw UsageError("--keep-env-var does not make sense without --ignore-env");
if (val) stringsEnv.emplace_back(fmt("%s=%s", var.c_str(), val));
}
vectorEnv = stringsToCharPtrs(stringsEnv); auto env = getEnv();
environ = vectorEnv.data();
} else {
if (!keep.empty())
throw UsageError("--keep does not make sense without --ignore-environment");
for (const auto & var : unset) if (ignoreEnvironment)
unsetenv(var.c_str()); std::erase_if(env, [&](const auto & var) { return !keepVars.contains(var.first); });
}
if (!setVars.empty())
for (const auto & [name, value] : setVars)
env[name] = value;
if (!unsetVars.empty())
std::erase_if(env, [&](const auto & var) { return unsetVars.contains(var.first); });
replaceEnv(env);
return;
} }
} }

View file

@ -13,7 +13,7 @@ namespace nix {
extern std::string programPath; extern std::string programPath;
extern char * * savedArgv; extern char ** savedArgv;
class EvalState; class EvalState;
struct Pos; struct Pos;
@ -24,7 +24,8 @@ static constexpr Command::Category catSecondary = 100;
static constexpr Command::Category catUtility = 101; static constexpr Command::Category catUtility = 101;
static constexpr Command::Category catNixInstallation = 102; static constexpr Command::Category catNixInstallation = 102;
static constexpr auto installablesCategory = "Options that change the interpretation of [installables](@docroot@/command-ref/new-cli/nix.md#installables)"; static constexpr auto installablesCategory =
"Options that change the interpretation of [installables](@docroot@/command-ref/new-cli/nix.md#installables)";
struct NixMultiCommand : MultiCommand, virtual Command struct NixMultiCommand : MultiCommand, virtual Command
{ {
@ -112,7 +113,9 @@ struct MixFlakeOptions : virtual Args, EvalCommand
* arguments) so that the completions for these flags can use them. * arguments) so that the completions for these flags can use them.
*/ */
virtual std::vector<FlakeRef> getFlakeRefsForCompletion() virtual std::vector<FlakeRef> getFlakeRefsForCompletion()
{ return {}; } {
return {};
}
}; };
struct SourceExprCommand : virtual Args, MixFlakeOptions struct SourceExprCommand : virtual Args, MixFlakeOptions
@ -122,11 +125,9 @@ struct SourceExprCommand : virtual Args, MixFlakeOptions
SourceExprCommand(); SourceExprCommand();
Installables parseInstallables( Installables parseInstallables(ref<Store> store, std::vector<std::string> ss);
ref<Store> store, std::vector<std::string> ss);
ref<Installable> parseInstallable( ref<Installable> parseInstallable(ref<Store> store, const std::string & installable);
ref<Store> store, const std::string & installable);
virtual Strings getDefaultFlakeAttrPaths(); virtual Strings getDefaultFlakeAttrPaths();
@ -272,10 +273,10 @@ struct RegisterCommand
typedef std::map<std::vector<std::string>, std::function<ref<Command>()>> Commands; typedef std::map<std::vector<std::string>, std::function<ref<Command>()>> Commands;
static Commands * commands; static Commands * commands;
RegisterCommand(std::vector<std::string> && name, RegisterCommand(std::vector<std::string> && name, std::function<ref<Command>()> command)
std::function<ref<Command>()> command)
{ {
if (!commands) commands = new Commands; if (!commands)
commands = new Commands;
commands->emplace(name, command); commands->emplace(name, command);
} }
@ -285,13 +286,13 @@ struct RegisterCommand
template<class T> template<class T>
static RegisterCommand registerCommand(const std::string & name) static RegisterCommand registerCommand(const std::string & name)
{ {
return RegisterCommand({name}, [](){ return make_ref<T>(); }); return RegisterCommand({name}, []() { return make_ref<T>(); });
} }
template<class T> template<class T>
static RegisterCommand registerCommand2(std::vector<std::string> && name) static RegisterCommand registerCommand2(std::vector<std::string> && name)
{ {
return RegisterCommand(std::move(name), [](){ return make_ref<T>(); }); return RegisterCommand(std::move(name), []() { return make_ref<T>(); });
} }
struct MixProfile : virtual StoreCommand struct MixProfile : virtual StoreCommand
@ -313,19 +314,21 @@ struct MixDefaultProfile : MixProfile
MixDefaultProfile(); MixDefaultProfile();
}; };
struct MixEnvironment : virtual Args { struct MixEnvironment : virtual Args
{
StringSet keep, unset; StringSet keepVars;
Strings stringsEnv; StringSet unsetVars;
std::vector<char*> vectorEnv; std::map<std::string, std::string> setVars;
bool ignoreEnvironment; bool ignoreEnvironment;
MixEnvironment(); MixEnvironment();
/*** /***
* Modify global environ based on `ignoreEnvironment`, `keep`, and * Modify global environ based on `ignoreEnvironment`, `keep`,
* `unset`. It's expected that exec will be called before this class * `unset`, and `added`. It's expected that exec will be called
* goes out of scope, otherwise `environ` will become invalid. * before this class goes out of scope, otherwise `environ` will
* become invalid.
*/ */
void setEnviron(); void setEnviron();
}; };
@ -349,9 +352,6 @@ void completeFlakeRefWithFragment(
std::string showVersions(const std::set<std::string> & versions); std::string showVersions(const std::set<std::string> & versions);
void printClosureDiff( void printClosureDiff(
ref<Store> store, ref<Store> store, const StorePath & beforePath, const StorePath & afterPath, std::string_view indent);
const StorePath & beforePath,
const StorePath & afterPath,
std::string_view indent);
} }

View file

@ -0,0 +1 @@
../../.version

View file

@ -0,0 +1 @@
../../build-utils-meson

View file

@ -22,9 +22,9 @@ mkMesonLibrary (finalAttrs: {
workDir = ./.; workDir = ./.;
fileset = fileset.unions [ fileset = fileset.unions [
../../../build-utils-meson ../../build-utils-meson
./build-utils-meson ./build-utils-meson
../../../.version ../../.version
./.version ./.version
./meson.build ./meson.build
# ./meson.options # ./meson.options
@ -43,7 +43,7 @@ mkMesonLibrary (finalAttrs: {
# Do the meson utils, without modification. # Do the meson utils, without modification.
'' ''
chmod u+w ./.version chmod u+w ./.version
echo ${version} > ../../../.version echo ${version} > ../../.version
''; '';
mesonFlags = [ mesonFlags = [

1
src/libexpr-tests/.version Symbolic link
View file

@ -0,0 +1 @@
../../.version

View file

@ -0,0 +1 @@
../../build-utils-meson

View file

@ -20,9 +20,9 @@ libexpr-tests_SOURCES := \
$(wildcard $(d)/flake/*.cc) $(wildcard $(d)/flake/*.cc)
libexpr-tests_EXTRA_INCLUDES = \ libexpr-tests_EXTRA_INCLUDES = \
-I tests/unit/libexpr-support \ -I src/libexpr-test-support \
-I tests/unit/libstore-support \ -I src/libstore-test-support \
-I tests/unit/libutil-support \ -I src/libutil-test-support \
$(INCLUDE_libexpr) \ $(INCLUDE_libexpr) \
$(INCLUDE_libexprc) \ $(INCLUDE_libexprc) \
$(INCLUDE_libfetchers) \ $(INCLUDE_libfetchers) \

View file

@ -27,9 +27,9 @@ mkMesonExecutable (finalAttrs: {
workDir = ./.; workDir = ./.;
fileset = fileset.unions [ fileset = fileset.unions [
../../../build-utils-meson ../../build-utils-meson
./build-utils-meson ./build-utils-meson
../../../.version ../../.version
./.version ./.version
./meson.build ./meson.build
# ./meson.options # ./meson.options
@ -50,7 +50,7 @@ mkMesonExecutable (finalAttrs: {
# Do the meson utils, without modification. # Do the meson utils, without modification.
'' ''
chmod u+w ./.version chmod u+w ./.version
echo ${version} > ../../../.version echo ${version} > ../../.version
''; '';
mesonFlags = [ mesonFlags = [

View file

@ -0,0 +1 @@
../../.version

View file

@ -0,0 +1 @@
../../build-utils-meson

View file

@ -17,8 +17,8 @@ endif
libfetchers-tests_SOURCES := $(wildcard $(d)/*.cc) libfetchers-tests_SOURCES := $(wildcard $(d)/*.cc)
libfetchers-tests_EXTRA_INCLUDES = \ libfetchers-tests_EXTRA_INCLUDES = \
-I tests/unit/libstore-support \ -I src/libstore-test-support \
-I tests/unit/libutil-support \ -I src/libutil-test-support \
$(INCLUDE_libfetchers) \ $(INCLUDE_libfetchers) \
$(INCLUDE_libstore) \ $(INCLUDE_libstore) \
$(INCLUDE_libutil) $(INCLUDE_libutil)

View file

@ -26,9 +26,9 @@ mkMesonExecutable (finalAttrs: {
workDir = ./.; workDir = ./.;
fileset = fileset.unions [ fileset = fileset.unions [
../../../build-utils-meson ../../build-utils-meson
./build-utils-meson ./build-utils-meson
../../../.version ../../.version
./.version ./.version
./meson.build ./meson.build
# ./meson.options # ./meson.options
@ -48,7 +48,7 @@ mkMesonExecutable (finalAttrs: {
# Do the meson utils, without modification. # Do the meson utils, without modification.
'' ''
chmod u+w ./.version chmod u+w ./.version
echo ${version} > ../../../.version echo ${version} > ../../.version
''; '';
mesonFlags = [ mesonFlags = [

View file

@ -157,7 +157,11 @@ struct PathInputScheme : InputScheme
}); });
storePath = store->addToStoreFromDump(*src, "source"); storePath = store->addToStoreFromDump(*src, "source");
} }
input.attrs.insert_or_assign("lastModified", uint64_t(mtime));
/* Trust the lastModified value supplied by the user, if
any. It's not a "secure" attribute so we don't care. */
if (!input.getLastModified())
input.attrs.insert_or_assign("lastModified", uint64_t(mtime));
return {makeStorePathAccessor(store, *storePath), std::move(input)}; return {makeStorePathAccessor(store, *storePath), std::move(input)};
} }

1
src/libflake-tests/.version Symbolic link
View file

@ -0,0 +1 @@
../../.version

View file

@ -0,0 +1 @@
../../build-utils-meson

View file

@ -20,9 +20,9 @@ libflake-tests_SOURCES := \
$(wildcard $(d)/flake/*.cc) $(wildcard $(d)/flake/*.cc)
libflake-tests_EXTRA_INCLUDES = \ libflake-tests_EXTRA_INCLUDES = \
-I tests/unit/libflake-support \ -I src/libflake-test-support \
-I tests/unit/libstore-support \ -I src/libstore-test-support \
-I tests/unit/libutil-support \ -I src/libutil-test-support \
$(INCLUDE_libflake) \ $(INCLUDE_libflake) \
$(INCLUDE_libexpr) \ $(INCLUDE_libexpr) \
$(INCLUDE_libfetchers) \ $(INCLUDE_libfetchers) \

View file

@ -26,9 +26,9 @@ mkMesonExecutable (finalAttrs: {
workDir = ./.; workDir = ./.;
fileset = fileset.unions [ fileset = fileset.unions [
../../../build-utils-meson ../../build-utils-meson
./build-utils-meson ./build-utils-meson
../../../.version ../../.version
./.version ./.version
./meson.build ./meson.build
# ./meson.options # ./meson.options
@ -48,7 +48,7 @@ mkMesonExecutable (finalAttrs: {
# Do the meson utils, without modification. # Do the meson utils, without modification.
'' ''
chmod u+w ./.version chmod u+w ./.version
echo ${version} > ../../../.version echo ${version} > ../../.version
''; '';
mesonFlags = [ mesonFlags = [

View file

@ -0,0 +1 @@
../../.version

View file

@ -0,0 +1 @@
../../build-utils-meson

View file

@ -22,9 +22,9 @@ mkMesonLibrary (finalAttrs: {
workDir = ./.; workDir = ./.;
fileset = fileset.unions [ fileset = fileset.unions [
../../../build-utils-meson ../../build-utils-meson
./build-utils-meson ./build-utils-meson
../../../.version ../../.version
./.version ./.version
./meson.build ./meson.build
# ./meson.options # ./meson.options
@ -43,7 +43,7 @@ mkMesonLibrary (finalAttrs: {
# Do the meson utils, without modification. # Do the meson utils, without modification.
'' ''
chmod u+w ./.version chmod u+w ./.version
echo ${version} > ../../../.version echo ${version} > ../../.version
''; '';
mesonFlags = [ mesonFlags = [

1
src/libstore-tests/.version Symbolic link
View file

@ -0,0 +1 @@
../../.version

View file

@ -0,0 +1 @@
../../build-utils-meson

View file

@ -0,0 +1 @@
../../../../tests/functional/derivation/advanced-attributes-defaults.drv

View file

@ -0,0 +1 @@
../../../../tests/functional/derivation/advanced-attributes-structured-attrs-defaults.drv

View file

@ -0,0 +1 @@
../../../../tests/functional/derivation/advanced-attributes-structured-attrs.drv

View file

@ -0,0 +1 @@
../../../../tests/functional/derivation/advanced-attributes.drv

Some files were not shown because too many files have changed in this diff Show more