Skip to content

Commit

Permalink
WIP: Allow building a "store-only" nix
Browse files Browse the repository at this point in the history
This is a nix without the expression language or flakes, with just a few
commands.

TODO:

 - Do --help without libexper.

 - Dedup the two `main.cc`s

 - Dedup the two `nix.md`s

 - Dedup the two `help.md`s

Pop out parser

Fix completions
  • Loading branch information
Ericson2314 committed Nov 13, 2023
1 parent 5ac703b commit 5aa081e
Show file tree
Hide file tree
Showing 164 changed files with 821 additions and 1,810 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ perl/Makefile.config
# /src/libutil/
/src/libutil/tests/libnixutil-tests

/src/nix/nix
/src/nix/store/mini-nix
/src/nix/full/nix

/src/nix/doc

Expand Down
19 changes: 15 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
-include Makefile.config
clean-files += Makefile.config

NIX_FULL ?= 1

ifeq ($(ENABLE_BUILD), yes)
makefiles = \
mk/precompiled-headers.mk \
local.mk \
src/libutil/local.mk \
src/libstore/local.mk \
src/libfetchers/local.mk \
src/libmain/local.mk \
src/libexpr/local.mk \
src/libcmd/local.mk \
src/libstore-cmd/local.mk \
src/nix/local.mk \
src/resolve-system-dependencies/local.mk \
scripts/local.mk \
Expand All @@ -22,23 +22,34 @@ makefiles = \
misc/upstart/local.mk \
doc/manual/local.mk \
doc/internal-api/local.mk
ifeq ($(NIX_FULL), 1)
makefiles += \
src/libfetchers/local.mk \
src/libexpr/local.mk \
src/libcmd/local.mk
endif
endif

ifeq ($(ENABLE_BUILD)_$(ENABLE_TESTS), yes_yes)
UNIT_TEST_ENV = _NIX_TEST_UNIT_DATA=unit-test-data
makefiles += \
src/libutil/tests/local.mk \
src/libstore/tests/local.mk \
src/libstore/tests/local.mk
ifeq ($(NIX_FULL), 1)
makefiles += \
src/libexpr/tests/local.mk
endif
endif

ifeq ($(ENABLE_TESTS), yes)
ifeq ($(NIX_FULL), 1)
makefiles += \
tests/functional/local.mk \
tests/functional/ca/local.mk \
tests/functional/dyn-drv/local.mk \
tests/functional/test-libstoreconsumer/local.mk \
tests/functional/plugins/local.mk
endif
else
makefiles += \
mk/disable-tests.mk
Expand Down
8 changes: 8 additions & 0 deletions doc/manual/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ $(d)/src/SUMMARY.md: $(d)/src/SUMMARY.md.in $(d)/src/command-ref/new-cli $(d)/sr
@cp $< $@
@$(call process-includes,$@,$@)

ifeq ($(NIX_FULL), 1)

$(d)/src/command-ref/new-cli: $(d)/nix.json $(d)/utils.nix $(d)/generate-manpage.nix $(d)/generate-settings.nix $(d)/generate-store-info.nix $(bindir)/nix
@rm -rf $@ $@.tmp
$(trace-gen) $(nix-eval) --write-to $@.tmp --expr 'import doc/manual/generate-manpage.nix true (builtins.readFile $<)'
Expand All @@ -106,6 +108,8 @@ $(d)/src/command-ref/conf-file.md: $(d)/conf-file.json $(d)/utils.nix $(d)/gener
$(trace-gen) $(nix-eval) --expr 'import doc/manual/generate-settings.nix { prefix = "conf"; } (builtins.fromJSON (builtins.readFile $<))' >> $@.tmp;
@mv $@.tmp $@

endif

$(d)/nix.json: $(bindir)/nix
$(trace-gen) $(dummy-env) $(bindir)/nix __dump-cli > $@.tmp
@mv $@.tmp $@
Expand All @@ -114,6 +118,8 @@ $(d)/conf-file.json: $(bindir)/nix
$(trace-gen) $(dummy-env) $(bindir)/nix show-config --json --experimental-features nix-command > $@.tmp
@mv $@.tmp $@

ifeq ($(NIX_FULL), 1)

$(d)/src/contributing/experimental-feature-descriptions.md: $(d)/xp-features.json $(d)/utils.nix $(d)/generate-xp-features.nix $(bindir)/nix
@rm -rf $@ $@.tmp
$(trace-gen) $(nix-eval) --write-to $@.tmp --expr 'import doc/manual/generate-xp-features.nix (builtins.fromJSON (builtins.readFile $<))'
Expand All @@ -140,6 +146,8 @@ $(d)/src/language/builtin-constants.md: $(d)/language.json $(d)/generate-builtin
@cat doc/manual/src/language/builtin-constants-suffix.md >> $@.tmp
@mv $@.tmp $@

endif

$(d)/language.json: $(bindir)/nix
$(trace-gen) $(dummy-env) $(bindir)/nix __dump-language > $@.tmp
@mv $@.tmp $@
Expand Down
3 changes: 1 addition & 2 deletions local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ GLOBAL_CXXFLAGS += -Wno-deprecated-declarations -Werror=switch
# Allow switch-enum to be overridden for files that do not support it, usually because of dependency headers.
ERROR_SWITCH_ENUM = -Werror=switch-enum

$(foreach i, config.h $(wildcard src/lib*/*.hh), \
$(eval $(call install-file-in, $(i), $(includedir)/nix, 0644)))
$(eval $(call install-file-in, config.h, $(includedir)/nix, 0644))

$(GCH): src/libutil/util.hh config.h

Expand Down
11 changes: 11 additions & 0 deletions src/libcmd/command-installable-value.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

namespace nix {

InstallableValueCommand::InstallableValueCommand()
: SourceExprCommand()
{
expectArgs({
.label = "installable",
.optional = true,
.handler = {&_installable},
.completer = getCompleteInstallable(),
});
}

void InstallableValueCommand::run(ref<Store> store, ref<Installable> installable)
{
auto installableValue = InstallableValue::require(installable);
Expand Down
4 changes: 3 additions & 1 deletion src/libcmd/command-installable-value.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ namespace nix {
* An InstallableCommand where the single positional argument must be an
* InstallableValue in particular.
*/
struct InstallableValueCommand : InstallableCommand
struct InstallableValueCommand : AbstractInstallableCommand, SourceExprCommand
{
InstallableValueCommand();

/**
* Entry point to this command
*/
Expand Down
Loading

0 comments on commit 5aa081e

Please sign in to comment.