From c97e17144e0d0b666d7b79d8b4b0d581bfdf373b Mon Sep 17 00:00:00 2001 From: Jade Lovelace Date: Thu, 16 May 2024 17:04:05 -0700 Subject: [PATCH 1/5] packaging: rename nixexpr -> lixexpr and so on This breaks downstreams linking to us on purpose to make sure that if someone is linking to Lix they're doing it on purpose and crucially not mixing up Nix and Lix versions in compatibility code. We still need to fix the internal includes to follow the same schema so we can drop the single-level include system entirely. However, this requires a little more effort. This adds pkg-config for libfetchers and config.h. Migration path: expr.hh -> lix/libexpr/expr.hh nix/config.h -> lix/config.h To apply this migration automatically, remove all `` from includes, so: `#include ` -> `#include `. Then, the correct paths will be resolved from the tangled mess, and the clang-tidy automated fix will work. Then run the following for out of tree projects: ``` lix_root=$HOME/lix (cd $lix_root/clang-tidy && nix develop -c 'meson setup build && ninja -C build') run-clang-tidy -checks='-*,lix-fixincludes' -load=$lix_root/clang-tidy/build/liblix-clang-tidy.so -p build/ -fix src ``` Related: https://git.lix.systems/lix-project/nix-eval-jobs/pulls/5 Fixes: https://git.lix.systems/lix-project/lix/issues/279 Change-Id: I7498e903afa6850a731ef8ce77a70da6b2b46966 --- doc/manual/rl-next/rename-lixexpr.md | 31 ++++++++++++++++++++++++++ doc/manual/src/contributing/hacking.md | 4 ++-- meson.build | 16 ++++++++++++- meson/cleanup-install.bash | 2 +- package.nix | 4 ++-- perl/lib/Nix/meson.build | 2 +- perl/meson.build | 2 +- src/libcmd/lix-cmd.pc.in | 10 +++++++++ src/libcmd/meson.build | 10 ++++----- src/libcmd/nix-cmd.pc.in | 9 -------- src/libexpr/flake/meson.build | 2 +- src/libexpr/lix-expr.pc.in | 10 +++++++++ src/libexpr/meson.build | 14 ++++++------ src/libexpr/nix-expr.pc.in | 10 --------- src/libfetchers/lix-fetchers.pc.in | 10 +++++++++ src/libfetchers/meson.build | 18 +++++++++++++-- src/libmain/lix-main.pc.in | 10 +++++++++ src/libmain/meson.build | 8 +++---- src/libmain/nix-main.pc.in | 9 -------- src/libstore/lix-store.pc.in | 10 +++++++++ src/libstore/meson.build | 10 ++++----- src/libstore/nix-store.pc.in | 9 -------- src/libutil/lix-util.pc.in | 10 +++++++++ src/libutil/meson.build | 18 +++++++++++++-- src/lix-base.pc.in | 8 +++++++ tests/unit/meson.build | 12 +++++----- 26 files changed, 181 insertions(+), 77 deletions(-) create mode 100644 doc/manual/rl-next/rename-lixexpr.md create mode 100644 src/libcmd/lix-cmd.pc.in delete mode 100644 src/libcmd/nix-cmd.pc.in create mode 100644 src/libexpr/lix-expr.pc.in delete mode 100644 src/libexpr/nix-expr.pc.in create mode 100644 src/libfetchers/lix-fetchers.pc.in create mode 100644 src/libmain/lix-main.pc.in delete mode 100644 src/libmain/nix-main.pc.in create mode 100644 src/libstore/lix-store.pc.in delete mode 100644 src/libstore/nix-store.pc.in create mode 100644 src/libutil/lix-util.pc.in create mode 100644 src/lix-base.pc.in diff --git a/doc/manual/rl-next/rename-lixexpr.md b/doc/manual/rl-next/rename-lixexpr.md new file mode 100644 index 000000000..698553c7f --- /dev/null +++ b/doc/manual/rl-next/rename-lixexpr.md @@ -0,0 +1,31 @@ +--- +synopsis: Rename all the libraries nixexpr, nixstore, etc to lixexpr, lixstore, etc +credits: jade +category: Breaking Changes +--- + +The Lix C++ API libraries have had the following changes: +- Includes moved from `include/nix/` to `include/lix/` +- `pkg-config` files renamed from `nix-expr` to `lix-expr` and so on. +- Libraries renamed from `libnixexpr.so` to `liblixexpr.so` and so on. + +There are other changes between Nix 2.18 and Lix, since these APIs are not +stable. However, this change in particular is a deliberate compatibility break +to force downstreams linking to Lix to specifically handle Lix and avoid Lix +accidentally getting ensnared in compatibility code for newer CppNix. + +Migration path: + +- expr.hh -> lix/libexpr/expr.hh +- nix/config.h -> lix/config.h + +To apply this migration automatically, remove all `` from includes, so `#include ` -> `#include `. +Then, the correct paths will be resolved from the tangled mess, and the clang-tidy automated fix will work. + +Then run the following for out of tree projects: + +```console +lix_root=$HOME/lix +(cd $lix_root/clang-tidy && nix develop -c 'meson setup build && ninja -C build') +run-clang-tidy -checks='-*,lix-fixincludes' -load=$lix_root/clang-tidy/build/liblix-clang-tidy.so -p build/ -fix src +``` diff --git a/doc/manual/src/contributing/hacking.md b/doc/manual/src/contributing/hacking.md index a8591e7ca..a73d672d4 100644 --- a/doc/manual/src/contributing/hacking.md +++ b/doc/manual/src/contributing/hacking.md @@ -102,14 +102,14 @@ $ meson compile -C build nixexpr All targets may be addressed as their output, relative to the build directory, e.g.: ```bash -$ meson compile -C build src/libexpr/libnixexpr.so +$ meson compile -C build src/libexpr/liblixexpr.so ``` But Meson does not consider intermediate files like object files targets. To build a specific object file, use Ninja directly and specify the output file relative to the build directory: ```bash -$ ninja -C build src/libexpr/libnixexpr.so.p/nixexpr.cc.o +$ ninja -C build src/libexpr/liblixexpr.so.p/nixexpr.cc.o ``` To inspect the canonical source of truth on what the state of the buildsystem configuration is, use: diff --git a/meson.build b/meson.build index 5885905c5..0d59ff751 100644 --- a/meson.build +++ b/meson.build @@ -395,7 +395,21 @@ config_h = configure_file( output : 'config.h', ) -install_headers(config_h, subdir : 'nix') +install_headers(config_h, subdir : 'lix') + +# FIXME: not using the pkg-config module because it creates way too many deps +# while meson migration is in progress, and we want to not include boost here +configure_file( + input : 'src/lix-base.pc.in', + output : 'lix-base.pc', + install_dir : libdir / 'pkgconfig', + configuration : { + 'prefix' : prefix, + 'libdir' : libdir, + 'includedir' : includedir, + 'PACKAGE_VERSION' : meson.project_version(), + }, +) add_project_arguments( # TODO(Qyriad): Yes this is how the autoconf+Make system did it. diff --git a/meson/cleanup-install.bash b/meson/cleanup-install.bash index 3e229cbc6..928edc74a 100755 --- a/meson/cleanup-install.bash +++ b/meson/cleanup-install.bash @@ -47,4 +47,4 @@ fi # Intentionally not using -f. # If these files don't exist then our assumptions have been violated and we should fail. -rm -v "$includedir/nix/parser-tab.cc" "$includedir/nix/lexer-tab.cc" +rm -v "$includedir/lix/libexpr/parser-tab.cc" "$includedir/lix/libexpr/lexer-tab.cc" diff --git a/package.nix b/package.nix index be3bcfb35..ebafa9420 100644 --- a/package.nix +++ b/package.nix @@ -49,7 +49,7 @@ # internal fork of nix-doc providing :doc in the repl lix-doc ? __forDefaults.lix-doc, - pname ? "nix", + pname ? "lix", versionSuffix ? "", officialRelease ? false, # Set to true to build the release notes for the next release. @@ -333,7 +333,7 @@ stdenv.mkDerivation (finalAttrs: { echo "file binary-dist $out/bin/nix" >> $out/nix-support/hydra-build-products '' + lib.optionalString stdenv.isDarwin '' - for lib in libnixutil.dylib libnixexpr.dylib; do + for lib in liblixutil.dylib liblixexpr.dylib; do install_name_tool \ -change "${lib.getLib boost}/lib/libboost_context.dylib" \ "$out/lib/libboost_context.dylib" \ diff --git a/perl/lib/Nix/meson.build b/perl/lib/Nix/meson.build index 6810622e3..1d235b74c 100644 --- a/perl/lib/Nix/meson.build +++ b/perl/lib/Nix/meson.build @@ -27,7 +27,7 @@ perl_libstore = shared_module( ], link_args : [ # Nix doesn't provide a pkg-config file for libutil. - '-lnixutil', + '-llixutil', soname_args, ], install : true, diff --git a/perl/meson.build b/perl/meson.build index 75c7c2c79..4b179da8f 100644 --- a/perl/meson.build +++ b/perl/meson.build @@ -64,6 +64,6 @@ if cxx.get_linker_id() in ['ld.bfd', 'ld.gold'] add_project_link_arguments('-Wl,--no-copy-dt-needed-entries', language : 'cpp') endif -libstore = dependency('nixstore', 'nix-store', required : true) +libstore = dependency('lixstore', 'lix-store', required : true) subdir('lib/Nix') diff --git a/src/libcmd/lix-cmd.pc.in b/src/libcmd/lix-cmd.pc.in new file mode 100644 index 000000000..f2e3f9d5e --- /dev/null +++ b/src/libcmd/lix-cmd.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: Lix (libcmd) +Description: Lix Package Manager (libcmd) +Version: @PACKAGE_VERSION@ +Requires: lix-base lix-util +Libs: -L${libdir} -llixcmd +Cflags: -I${includedir}/lix/libcmd diff --git a/src/libcmd/meson.build b/src/libcmd/meson.build index 5a0e61503..4da1b496b 100644 --- a/src/libcmd/meson.build +++ b/src/libcmd/meson.build @@ -39,7 +39,7 @@ libcmd_generated_headers = [ ] libcmd = library( - 'nixcmd', + 'lixcmd', libcmd_generated_headers, libcmd_sources, dependencies : [ @@ -59,13 +59,13 @@ libcmd = library( install_rpath : libdir, ) -install_headers(libcmd_headers, subdir : 'nix', preserve_path : true) +install_headers(libcmd_headers, subdir : 'lix/libcmd', preserve_path : true) custom_target( command : [ 'cp', '@INPUT@', '@OUTPUT@' ], input : libcmd_generated_headers, output : '@PLAINNAME@', install : true, - install_dir : includedir / 'nix', + install_dir : includedir / 'lix/libcmd', ) liblixcmd = declare_dependency( @@ -76,8 +76,8 @@ liblixcmd = declare_dependency( # FIXME: not using the pkg-config module because it creates way too many deps # while meson migration is in progress, and we want to not include boost here configure_file( - input : 'nix-cmd.pc.in', - output : 'nix-cmd.pc', + input : 'lix-cmd.pc.in', + output : 'lix-cmd.pc', install_dir : libdir / 'pkgconfig', configuration : { 'prefix' : prefix, diff --git a/src/libcmd/nix-cmd.pc.in b/src/libcmd/nix-cmd.pc.in deleted file mode 100644 index 39575f222..000000000 --- a/src/libcmd/nix-cmd.pc.in +++ /dev/null @@ -1,9 +0,0 @@ -prefix=@prefix@ -libdir=@libdir@ -includedir=@includedir@ - -Name: Nix -Description: Nix Package Manager -Version: @PACKAGE_VERSION@ -Libs: -L${libdir} -lnixcmd -Cflags: -I${includedir}/nix -std=c++2a diff --git a/src/libexpr/flake/meson.build b/src/libexpr/flake/meson.build index 3ecc30f4e..cce1b0c75 100644 --- a/src/libexpr/flake/meson.build +++ b/src/libexpr/flake/meson.build @@ -4,5 +4,5 @@ libexpr_generated_headers += custom_target( output : '@PLAINNAME@.gen.hh', capture : true, install : true, - install_dir : includedir / 'nix/flake', + install_dir : includedir / 'lix/libexpr/flake', ) diff --git a/src/libexpr/lix-expr.pc.in b/src/libexpr/lix-expr.pc.in new file mode 100644 index 000000000..5e850976d --- /dev/null +++ b/src/libexpr/lix-expr.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: Lix libexpr +Description: Lix Package Manager (libexpr) +Version: @PACKAGE_VERSION@ +Requires: lix-base lix-util lix-fetchers lix-store bdw-gc +Libs: -L${libdir} -llixexpr +Cflags: -I${includedir}/lix/libexpr diff --git a/src/libexpr/meson.build b/src/libexpr/meson.build index 099279d56..fda6fde2c 100644 --- a/src/libexpr/meson.build +++ b/src/libexpr/meson.build @@ -15,7 +15,7 @@ parser_tab = custom_target( # NOTE(Qyriad): Meson doesn't support installing only part of a custom target, so we add # an install script below which removes parser-tab.cc. install : true, - install_dir : includedir / 'nix', + install_dir : includedir / 'lix/libexpr', ) lexer_tab = custom_target( @@ -37,7 +37,7 @@ lexer_tab = custom_target( # NOTE(Qyriad): Meson doesn't support installing only part of a custom target, so we add # an install script below which removes lexer-tab.cc. install : true, - install_dir : includedir / 'nix', + install_dir : includedir / 'lix/libexpr', ) # TODO(Qyriad): When the parser and lexer are rewritten this should be removed. @@ -59,7 +59,7 @@ foreach header : [ 'imported-drv-to-derivation.nix', 'fetchurl.nix' ] output : '@PLAINNAME@.gen.hh', capture : true, install : true, - install_dir : includedir / 'nix', + install_dir : includedir / 'lix/libexpr', ) endforeach subdir('flake') @@ -127,7 +127,7 @@ libexpr_headers = files( ) libexpr = library( - 'nixexpr', + 'lixexpr', libexpr_sources, parser_tab, lexer_tab, @@ -152,7 +152,7 @@ libexpr = library( install_headers( libexpr_headers, - subdir : 'nix', + subdir : 'lix/libexpr', preserve_path : true, ) @@ -164,8 +164,8 @@ liblixexpr = declare_dependency( # FIXME: not using the pkg-config module because it creates way too many deps # while meson migration is in progress, and we want to not include boost here configure_file( - input : 'nix-expr.pc.in', - output : 'nix-expr.pc', + input : 'lix-expr.pc.in', + output : 'lix-expr.pc', install_dir : libdir / 'pkgconfig', configuration : { 'prefix' : prefix, diff --git a/src/libexpr/nix-expr.pc.in b/src/libexpr/nix-expr.pc.in deleted file mode 100644 index 60ffb5dba..000000000 --- a/src/libexpr/nix-expr.pc.in +++ /dev/null @@ -1,10 +0,0 @@ -prefix=@prefix@ -libdir=@libdir@ -includedir=@includedir@ - -Name: Nix -Description: Nix Package Manager -Version: @PACKAGE_VERSION@ -Requires: nix-store bdw-gc -Libs: -L${libdir} -lnixexpr -Cflags: -I${includedir}/nix -std=c++2a diff --git a/src/libfetchers/lix-fetchers.pc.in b/src/libfetchers/lix-fetchers.pc.in new file mode 100644 index 000000000..fa213b769 --- /dev/null +++ b/src/libfetchers/lix-fetchers.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: Lix libfetchers +Description: Lix Package Manager (libfetchers) +Version: @PACKAGE_VERSION@ +Requires: lix-base lix-util +Libs: -L${libdir} -llixfetchers +Cflags: -I${includedir}/lix/libfetchers diff --git a/src/libfetchers/meson.build b/src/libfetchers/meson.build index 3809701b7..dbb85b84c 100644 --- a/src/libfetchers/meson.build +++ b/src/libfetchers/meson.build @@ -23,7 +23,7 @@ libfetchers_headers = files( ) libfetchers = library( - 'nixfetchers', + 'lixfetchers', libfetchers_sources, dependencies : [ liblixstore, @@ -35,7 +35,21 @@ libfetchers = library( install_rpath : libdir, ) -install_headers(libfetchers_headers, subdir : 'nix', preserve_path : true) +install_headers(libfetchers_headers, subdir : 'lix/libfetchers', preserve_path : true) + +# FIXME: not using the pkg-config module because it creates way too many deps +# while meson migration is in progress, and we want to not include boost here +configure_file( + input : 'lix-fetchers.pc.in', + output : 'lix-fetchers.pc', + install_dir : libdir / 'pkgconfig', + configuration : { + 'prefix' : prefix, + 'libdir' : libdir, + 'includedir' : includedir, + 'PACKAGE_VERSION' : meson.project_version(), + }, +) liblixfetchers = declare_dependency( include_directories : include_directories('.'), diff --git a/src/libmain/lix-main.pc.in b/src/libmain/lix-main.pc.in new file mode 100644 index 000000000..0ceaec393 --- /dev/null +++ b/src/libmain/lix-main.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: Lix libmain +Description: Lix Package Manager (libmain) +Version: @PACKAGE_VERSION@ +Requires: lix-base lix-util +Libs: -L${libdir} -llixmain +Cflags: -I${includedir}/lix/libmain diff --git a/src/libmain/meson.build b/src/libmain/meson.build index 3f50b158d..b17247a9d 100644 --- a/src/libmain/meson.build +++ b/src/libmain/meson.build @@ -14,7 +14,7 @@ libmain_headers = files( ) libmain = library( - 'nixmain', + 'lixmain', libmain_sources, dependencies : [ liblixutil, @@ -25,7 +25,7 @@ libmain = library( install_rpath : libdir, ) -install_headers(libmain_headers, subdir : 'nix', preserve_path : true) +install_headers(libmain_headers, subdir : 'lix/libmain', preserve_path : true) liblixmain = declare_dependency( include_directories : include_directories('.'), @@ -35,8 +35,8 @@ liblixmain = declare_dependency( # FIXME: not using the pkg-config module because it creates way too many deps # while meson migration is in progress, and we want to not include boost here configure_file( - input : 'nix-main.pc.in', - output : 'nix-main.pc', + input : 'lix-main.pc.in', + output : 'lix-main.pc', install_dir : libdir / 'pkgconfig', configuration : { 'prefix' : prefix, diff --git a/src/libmain/nix-main.pc.in b/src/libmain/nix-main.pc.in deleted file mode 100644 index fb3ead6fa..000000000 --- a/src/libmain/nix-main.pc.in +++ /dev/null @@ -1,9 +0,0 @@ -prefix=@prefix@ -libdir=@libdir@ -includedir=@includedir@ - -Name: Nix -Description: Nix Package Manager -Version: @PACKAGE_VERSION@ -Libs: -L${libdir} -lnixmain -Cflags: -I${includedir}/nix -std=c++2a diff --git a/src/libstore/lix-store.pc.in b/src/libstore/lix-store.pc.in new file mode 100644 index 000000000..69c323a28 --- /dev/null +++ b/src/libstore/lix-store.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: Lix libstore +Description: Lix Package Manager (libstore) +Version: @PACKAGE_VERSION@ +Requires: lix-base lix-util +Libs: -L${libdir} -llixstore -llixutil +Cflags: -I${includedir}/lix/libstore diff --git a/src/libstore/meson.build b/src/libstore/meson.build index 5fde92dd0..4ccb03df7 100644 --- a/src/libstore/meson.build +++ b/src/libstore/meson.build @@ -6,7 +6,7 @@ foreach header : [ 'schema.sql', 'ca-specific-schema.sql' ] output : '@PLAINNAME@.gen.hh', capture : true, install : true, - install_dir : includedir / 'nix', + install_dir : includedir / 'lix/libstore', ) endforeach @@ -201,7 +201,7 @@ foreach name, value : cpp_str_defines endforeach libstore = library( - 'nixstore', + 'lixstore', libstore_generated_headers, libstore_sources, dependencies : [ @@ -224,7 +224,7 @@ libstore = library( install_rpath : libdir, ) -install_headers(libstore_headers, subdir : 'nix', preserve_path : true) +install_headers(libstore_headers, subdir : 'lix/libstore', preserve_path : true) # Used by libfetchers. liblixstore = declare_dependency( @@ -235,8 +235,8 @@ liblixstore = declare_dependency( # FIXME: not using the pkg-config module because it creates way too many deps # while meson migration is in progress, and we want to not include boost here configure_file( - input : 'nix-store.pc.in', - output : 'nix-store.pc', + input : 'lix-store.pc.in', + output : 'lix-store.pc', install_dir : libdir / 'pkgconfig', configuration : { 'prefix' : prefix, diff --git a/src/libstore/nix-store.pc.in b/src/libstore/nix-store.pc.in deleted file mode 100644 index dc42d0bca..000000000 --- a/src/libstore/nix-store.pc.in +++ /dev/null @@ -1,9 +0,0 @@ -prefix=@prefix@ -libdir=@libdir@ -includedir=@includedir@ - -Name: Nix -Description: Nix Package Manager -Version: @PACKAGE_VERSION@ -Libs: -L${libdir} -lnixstore -lnixutil -Cflags: -I${includedir}/nix -std=c++2a diff --git a/src/libutil/lix-util.pc.in b/src/libutil/lix-util.pc.in new file mode 100644 index 000000000..cd749aabb --- /dev/null +++ b/src/libutil/lix-util.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: Lix libutil +Description: Lix Package Manager (libutil) +Version: @PACKAGE_VERSION@ +Requires: lix-base lix-util +Libs: -L${libdir} -llixutil +Cflags: -I${includedir}/lix/libutil diff --git a/src/libutil/meson.build b/src/libutil/meson.build index 13266f6bd..58e0bd062 100644 --- a/src/libutil/meson.build +++ b/src/libutil/meson.build @@ -100,7 +100,7 @@ libutil_headers = files( ) libutil = library( - 'nixutil', + 'lixutil', libutil_sources, dependencies : [ aws_sdk, @@ -118,7 +118,21 @@ libutil = library( install : true, ) -install_headers(libutil_headers, subdir : 'nix', preserve_path : true) +install_headers(libutil_headers, subdir : 'lix/libutil', preserve_path : true) + +# FIXME: not using the pkg-config module because it creates way too many deps +# while meson migration is in progress, and we want to not include boost here +configure_file( + input : 'lix-util.pc.in', + output : 'lix-util.pc', + install_dir : libdir / 'pkgconfig', + configuration : { + 'prefix' : prefix, + 'libdir' : libdir, + 'includedir' : includedir, + 'PACKAGE_VERSION' : meson.project_version(), + }, +) # Used by libstore and libfetchers. liblixutil = declare_dependency( diff --git a/src/lix-base.pc.in b/src/lix-base.pc.in new file mode 100644 index 000000000..925a7753a --- /dev/null +++ b/src/lix-base.pc.in @@ -0,0 +1,8 @@ +prefix=@prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: Lix base +Description: Lix Package Manager (config.hh fixup) +Version: @PACKAGE_VERSION@ +Cflags: -I${includedir}/lix diff --git a/tests/unit/meson.build b/tests/unit/meson.build index f5355cce8..a997a0d56 100644 --- a/tests/unit/meson.build +++ b/tests/unit/meson.build @@ -17,7 +17,7 @@ libutil_test_support_sources = files( 'libutil-support/tests/terminal-code-eater.cc', ) libutil_test_support = library( - 'nixutil-test-support', + 'lixutil-test-support', libutil_test_support_sources, dependencies : [ liblixutil, @@ -57,7 +57,7 @@ libutil_tests_sources = files( ) libutil_tester = executable( - 'libnixutil-tests', + 'liblixutil-tests', libutil_tests_sources, dependencies : [ rapidcheck, @@ -90,7 +90,7 @@ libstore_test_support_sources = files( ) libstore_test_support = library( - 'nixstore-test-support', + 'lixstore-test-support', libstore_test_support_sources, dependencies : [ liblixutil_test_support, @@ -124,7 +124,7 @@ libstore_tests_sources = files( ) libstore_tester = executable( - 'libnixstore-tests', + 'liblixstore-tests', libstore_tests_sources, dependencies : [ liblixstore_test_support, @@ -154,7 +154,7 @@ libexpr_test_support_sources = files( ) libexpr_test_support = library( - 'nixexpr-test-support', + 'lixexpr-test-support', libexpr_test_support_sources, dependencies : [ liblixstore_test_support, @@ -185,7 +185,7 @@ libexpr_tests_sources = files( ) libexpr_tester = executable( - 'libnixexpr-tests', + 'liblixexpr-tests', libexpr_tests_sources, dependencies : [ liblixexpr_test_support, From c31d2735bfd61f803ea9164f7b621aa9a9bfcc0b Mon Sep 17 00:00:00 2001 From: Qyriad Date: Tue, 21 May 2024 15:37:08 -0600 Subject: [PATCH 2/5] docs: document the cursed file syntax for old cli This documents the fact that nix-build, nix-env, nix-instantiate, and nix-shell accept an extended syntax for their file arguments, including some well-known (but not well documented) aspects, like being able to specify ``, but also https:// tarball URLs, `flake:` prefixed flakerefs, and the cursed `channel:` prefixed hardcoded URLs Same thing for the new CLI incoming :) Change-Id: Ib6d68594a16132805ba5d97526e16f7b3633117e --- doc/manual/src/command-ref/fileish-summary.md | 14 ++++++ doc/manual/src/command-ref/nix-build.md | 50 ++++++++++++++++--- doc/manual/src/command-ref/nix-env.md | 2 +- .../src/command-ref/nix-env/opt-common.md | 20 ++++++-- doc/manual/src/command-ref/nix-instantiate.md | 9 ++-- doc/manual/src/command-ref/nix-shell.md | 5 +- 6 files changed, 80 insertions(+), 20 deletions(-) create mode 100644 doc/manual/src/command-ref/fileish-summary.md diff --git a/doc/manual/src/command-ref/fileish-summary.md b/doc/manual/src/command-ref/fileish-summary.md new file mode 100644 index 000000000..c5db366de --- /dev/null +++ b/doc/manual/src/command-ref/fileish-summary.md @@ -0,0 +1,14 @@ + +- A normal filesystem path, like `/home/meow/nixfiles/default.nix` + - Or a directory, like `/home/meow/nixfiles`, equivalent to above +- A single lookup path, like `` or `` +- A URL to a tarball, like `https://github.com/NixOS/nixpkgs/archive/refs/heads/release-23.11.tar.gz` +- A [flakeref](@docroot@/command-ref/new-cli/nix3-flake.md#flake-references), introduced by the prefix `flake:`, like `flake:git+https://git.lix.systems/lix-project/lix` +- A channel name, introduced by the prefix `channel:`, like `channel:nixpkgs-unstable`. + - This uses a hard-coded URL pattern and is *not* related to the subscribed channels managed by the [nix-channel](@docroot@/command-ref/nix-channel.md) command. diff --git a/doc/manual/src/command-ref/nix-build.md b/doc/manual/src/command-ref/nix-build.md index 24714b2b4..b4c3a4697 100644 --- a/doc/manual/src/command-ref/nix-build.md +++ b/doc/manual/src/command-ref/nix-build.md @@ -4,7 +4,7 @@ # Synopsis -`nix-build` [*paths…*] +`nix-build` [*fileish…*] [`--arg` *name* *value*] [`--argstr` *name* *value*] [{`--attr` | `-A`} *attrPath*] @@ -20,19 +20,55 @@ For documentation on the latter, run `nix build --help` or see `man nix3-build`. # Description The `nix-build` command builds the derivations described by the Nix -expressions in *paths*. If the build succeeds, it places a symlink to +expressions in each *fileish*. If the build succeeds, it places a symlink to the result in the current directory. The symlink is called `result`. If there are multiple Nix expressions, or the Nix expressions evaluate to multiple derivations, multiple sequentially numbered symlinks are created (`result`, `result-2`, and so on). -If no *paths* are specified, then `nix-build` will use `default.nix` in +If no *fileish* is specified, then `nix-build` will use `default.nix` in the current directory, if it exists. -If an element of *paths* starts with `http://` or `https://`, it is -interpreted as the URL of a tarball that will be downloaded and unpacked -to a temporary location. The tarball must include a single top-level -directory containing at least a file named `default.nix`. +## Fileish Syntax + +A given *fileish* may take one of a few different forms, the first being a simple filesystem path, e.g. `nix-build /tmp/some-file.nix`. +Like the [import builtin](../language/builtins.md#builtins-import) specifying a directory is equivalent to specifying `default.nix` within that directory. +It may also be a [search path](./env-common.md#env-NIX_PATH) (also known as a lookup path) like ``, which is convenient to use with `--attr`/`-A`: + +```console +$ nix-build '' -A firefox +``` + +(Note the quotation marks around ``, which will be necessary in most Unix shells.) + +If a *fileish* starts with `http://` or `https://`, it is interpreted as the URL of a tarball which will be fetched and unpacked. +Lix will then `import` the unpacked directory, so these tarballs must include at least a single top-level directory with a file called `default.nix` +For example, you could build from a specific version of Nixpkgs with something like: + +```console +$ nix-build "https://github.com/NixOS/nixpkgs/archive/refs/heads/release-23.11.tar.gz" -A firefox +``` + +If a path starts with `flake:`, the rest of the argument is interpreted as a [flakeref](./new-cli/nix3-flake.md#flake-references) (see `nix flake --help` or `man nix3-flake`), which requires the "flakes" experimental feature to be enabled. +Lix will fetch the flake, and then `import` its unpacked directory, so the flake must include a file called `default.nix`. +For example, the flake analogues to the above `nix-build` commands are: + +```console +$ nix-build flake:nixpkgs -A firefox +$ nix-build flake:github:NixOS/nixpkgs/release-23.11 -A firefox +``` + +Finally, for legacy reasons, if a path starts with `channel:`, the rest of the argument is interpreted as the name of a channel to fetch from `https://nixos.org/channels/$CHANNEL_NAME/nixexprs.tar.xz`. +This is a **hard coded URL** pattern and is *not* related to the subscribed channels managed by the [nix-channel](./nix-channel.md) command. + +> **Note**: any of the special syntaxes may always be disambiguated by prefixing the path. +> For example: a file in the current directory literally called `` can be addressed as `./`, to escape the special interpretation. + +In summary, a path argument may be one of: + +{{#include ./fileish-summary.md}} + +## Notes `nix-build` is essentially a wrapper around [`nix-instantiate`](nix-instantiate.md) (to translate a high-level Nix diff --git a/doc/manual/src/command-ref/nix-env.md b/doc/manual/src/command-ref/nix-env.md index 5a9e05fed..b3940aeaa 100644 --- a/doc/manual/src/command-ref/nix-env.md +++ b/doc/manual/src/command-ref/nix-env.md @@ -8,7 +8,7 @@ [`--option` *name* *value*] [`--arg` *name* *value*] [`--argstr` *name* *value*] - [{`--file` | `-f`} *path*] + [{`--file` | `-f`} *fileish*] [{`--profile` | `-p`} *path*] [`--system-filter` *system*] [`--dry-run`] diff --git a/doc/manual/src/command-ref/nix-env/opt-common.md b/doc/manual/src/command-ref/nix-env/opt-common.md index 636281b6d..fcf7e16db 100644 --- a/doc/manual/src/command-ref/nix-env/opt-common.md +++ b/doc/manual/src/command-ref/nix-env/opt-common.md @@ -2,16 +2,26 @@ The following options are allowed for all `nix-env` operations, but may not always have an effect. - - `--file` / `-f` *path*\ + - `--file` / `-f` *fileish*\ Specifies the Nix expression (designated below as the *active Nix expression*) used by the `--install`, `--upgrade`, and `--query --available` operations to obtain derivations. The default is `~/.nix-defexpr`. - If the argument starts with `http://` or `https://`, it is - interpreted as the URL of a tarball that will be downloaded and - unpacked to a temporary location. The tarball must include a single - top-level directory containing at least a file named `default.nix`. + *fileish* is interpreted the same as with [nix-build](../nix-build.md#Path_Syntax). + See that section for complete details (`nix-build --help`), but in summary, a path argument may be one of: + + + + - A normal filesystem path, like `/home/meow/nixfiles/default.nix` + - Or a directory, like `/home/meow/nixfiles`, equivalent to above + - A single lookup path, like `` or `` + - A URL to a tarball, like `https://github.com/NixOS/nixpkgs/archive/refs/heads/release-23.11.tar.gz` + - A [flakeref](@docroot@/command-ref/new-cli/nix3-flake.md#flake-references), introduced by the prefix `flake:`, like `flake:git+https://git.lix.systems/lix-project/lix` + - A channel name, introduced by the prefix `channel:`, like `channel:nixpkgs-unstable`. + - This uses a hard-coded URL pattern and is *not* related to the subscribed channels managed by the [nix-channel](@docroot@/command-ref/nix-channel.md) command. - `--profile` / `-p` *path*\ Specifies the profile to be used by those operations that operate on diff --git a/doc/manual/src/command-ref/nix-instantiate.md b/doc/manual/src/command-ref/nix-instantiate.md index 479c9abcf..f9c7fcac5 100644 --- a/doc/manual/src/command-ref/nix-instantiate.md +++ b/doc/manual/src/command-ref/nix-instantiate.md @@ -11,7 +11,7 @@ [{`--attr`| `-A`} *attrPath*] [`--add-root` *path*] [`--expr` | `-E`] - *files…* + *fileish…* `nix-instantiate` `--find-file` *files…* @@ -25,8 +25,11 @@ of the resulting store derivations are printed on standard output. [store derivation]: ../glossary.md#gloss-store-derivation -If *files* is the character `-`, then a Nix expression will be read from -standard input. +If *fileish* is the character `-`, then a Nix expression will be read from standard input. +Otherwise, each *fileish* is interpreted the same as with [nix-build](./nix-build.md#Path_Syntax). +See that section for complete details (`nix-build --help`), but in summary, a path argument may be one of: + +{{#include ./fileish-summary.md}} # Options diff --git a/doc/manual/src/command-ref/nix-shell.md b/doc/manual/src/command-ref/nix-shell.md index 1eaf3c36a..ce33b264f 100644 --- a/doc/manual/src/command-ref/nix-shell.md +++ b/doc/manual/src/command-ref/nix-shell.md @@ -33,10 +33,7 @@ the environment of a derivation for development. If *path* is not given, `nix-shell` defaults to `shell.nix` if it exists, and `default.nix` otherwise. -If *path* starts with `http://` or `https://`, it is interpreted as the -URL of a tarball that will be downloaded and unpacked to a temporary -location. The tarball must include a single top-level directory -containing at least a file named `default.nix`. +{{#include ./fileish-summary.md}} If the derivation defines the variable `shellHook`, it will be run after `$stdenv/setup` has been sourced. Since this hook is not executed From 2d72c02b58af152af1cba58fd4b29bc5bf1f9688 Mon Sep 17 00:00:00 2001 From: Qyriad Date: Wed, 22 May 2024 17:15:45 -0600 Subject: [PATCH 3/5] docstrings: NixRepl::getDerivationPath: exceptions directly thrown getDerivationPath() directly throws nix::Error for invalid derivations Change-Id: I81ead950060b789794fa683b61c6349fece1690d --- src/libcmd/repl.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc index 46b6d57ed..02aa5a272 100644 --- a/src/libcmd/repl.cc +++ b/src/libcmd/repl.cc @@ -107,6 +107,11 @@ struct NixRepl void initEnv() override; virtual StringSet completePrefix(const std::string & prefix) override; + + /** + * @exception nix::Error thrown directly if the expression does not evaluate + * to a derivation, or evaluates to an invalid derivation. + */ StorePath getDerivationPath(Value & v); ProcessLineResult processLine(std::string line); From 407210e043ac8c7977924dc3f9ea1ad8102298db Mon Sep 17 00:00:00 2001 From: Qyriad Date: Wed, 22 May 2024 22:31:19 -0600 Subject: [PATCH 4/5] docs: document the cursed file syntax for new CLI This documents that all installables in the nix3 commands, in their --file/-f form accept an extended syntax for the file argument, which is the same as it is for nix-build and friends, some of which were well known in their nix-build forms (e.g. `nix-build '' -A hello) but are not well known in their nix3 forms (people rarely know that you can `nix build -f '' firefox`). Like the old CLI syntax, as documented in [1], file arguments also accept https:// tarball URLs, `flake:` prefixed flakerefs, and the cursed `channel:` prefixed hardened URLs. [1]: Ib6d68594a16132805ba5d97526e16f7b3633117e Change-Id: Ib81a5db1f60d5916f0f792d82054f3ac65717121 --- doc/manual/src/command-ref/fileish-summary.md | 1 + src/nix/nix.md | 47 ++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/doc/manual/src/command-ref/fileish-summary.md b/doc/manual/src/command-ref/fileish-summary.md index c5db366de..6200dfcc8 100644 --- a/doc/manual/src/command-ref/fileish-summary.md +++ b/doc/manual/src/command-ref/fileish-summary.md @@ -4,6 +4,7 @@ this also links to nix-build.md for the full explanation. This include file is manually duplicated in nix-env/opt-common.md because list indentation sadness. + It is also manually duplicated in src/nix/nix.md, because those files don't support include?? busted. --> - A normal filesystem path, like `/home/meow/nixfiles/default.nix` - Or a directory, like `/home/meow/nixfiles`, equivalent to above diff --git a/src/nix/nix.md b/src/nix/nix.md index 0d588cd01..c33c85dd8 100644 --- a/src/nix/nix.md +++ b/src/nix/nix.md @@ -158,16 +158,61 @@ Example: `/nix/store/p7gp6lxdg32h4ka1q398wd9r2zkbbz2v-hello-2.10.drv^*` Example: `--file /path/to/nixpkgs hello` -When the option `-f` / `--file` *path* \[*attrpath*...\] is given, installables are interpreted as the value of the expression in the Nix file at *path*. +When the option `-f` / `--file` *fileish* \[*attrpath*...\] is given, installables are interpreted as the value of the Nix file specified by *fileish*. If attribute paths are provided, commands will operate on the corresponding values accessible at these paths. The Nix expression in that file, or any selected attribute, must evaluate to a derivation. +The *fileish* itself may take one of a few different forms, the first being a simple filesystem path, e.g. `nix build -f /tmp/some-file.nix`. +Like the [import builtin](../../language/builtins.md#builtins-import), specifying a directory is equivalent to specify `default.nix` within that directory. +It may also be a [search path](../env-common.md#env-NIX_PATH) (also known as a lookup path), like ``. +Unlike using `` in a `--expr` argument, this does not require `--impure`. + To emulate the `nix-build '' -A hello` pattern, use: ```console $ nix build -f '' hello ``` +If a *fileish* starts with `http://` or `https://`, it is interpreted as the URL of a tarball which will be fetched and unpacked. +Lix will then `import` the unpacked directory, so these tarballs must include at least a single top-level directory with a file called `default.nix`. +For example, you could build from a specific version of Nixpkgs with something like: + +```console +$ nix build -f "https://github.com/NixOS/nixpkgs/archive/refs/heads/release-23.11.tar.gz" firefox +``` + +If a *fileish* starts with `flake:`, the rest of the argument is interpreted as a [flakeref](./nix3-flake.md#flake-reference) (see `nix flake --help` or `man nix3-flake`), which requires the "flakes" experimental feature to be enabled. +This is is *not quite* the same as specifying a [flake output attrpath](#flake-output-attribute). +It does *not* access the flake directly, but instead fetches it and `import`s the unpacked directory. +In other words, it assumes that the flake has a `default.nix` file, and then interprets the attribute path relative to what `default.nix` evaluates to. + +For many flakes — including Nixpkgs — this will end up evaluating to the same thing. +These two commands build the same derivation, but one from the flake, and the other from `default.nix`: + +```console +$ nix build 'nixpkgs#firefox' # from flake.nix +$ nix build -f flake:nixpkgs firefox # from default.nix in the flake directory +``` + +Finally, for legacy reasons, if a *fileish* starts with `channel:`, the rest of the argument is interpreted as the name of a channel to fetch from `https://nixos.org/channels/$CHANNEL_NAME/nixexprs.tar.gz`. +This is a **hard coded URL** pattern and is *not* related to the subscribed channels managed by the [nix-channel](../nix-channel.md) command. + +> **Note**: any of the special syntaxes may always be disambiguated by prefixing the path. +> For example: a file in the current directory literally called `` can be addressed as `./`, to escape the special interpretation. + + +In summary, a file path argument may be one of: + +- A normal filesystem path, like `/home/meow/nixfiles/default.nix` + - Or a directory, like `/home/meow/nixfiles`, equivalent to above +- A single lookup path, like `` or `` +- A URL to a tarball, like `https://github.com/NixOS/nixpkgs/archive/refs/heads/release-23.11.tar.gz` +- A [flakeref](@docroot@/command-ref/new-cli/nix3-flake.md#flake-references), introduced by the prefix `flake:`, like `flake:git+https://git.lix.systems/lix-project/lix` +- A channel name, introduced by the prefix `channel:`, like `channel:nixpkgs-unstable`. + - This uses a hard-coded URL pattern and is *not* related to the subscribed channels managed by the [nix-channel](@docroot@/command-ref/nix-channel.md) command. + ### Nix expression Example: `--expr 'import {}' hello` From 252f43b01a1d2a5538bf9cb6cbbc98e768e70481 Mon Sep 17 00:00:00 2001 From: Qyriad Date: Wed, 22 May 2024 22:38:38 -0600 Subject: [PATCH 5/5] add editorconfig for markdown Change-Id: I493fc37fde425fc5c5c24f9b077bdc235271233c --- .editorconfig | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.editorconfig b/.editorconfig index 887ecadba..bcee9cfce 100644 --- a/.editorconfig +++ b/.editorconfig @@ -24,3 +24,8 @@ indent_size = 4 # Match diffs, avoid to trim trailing whitespace [*.{diff,patch}] trim_trailing_whitespace = false + +[*.md] +indent_style = space +indent_size = 2 +max_line_length = 0