From ef1e7ab840eaa50da29ddde7bf990a1ff6a8b185 Mon Sep 17 00:00:00 2001 From: Alexander Bantyev Date: Thu, 1 Jul 2021 00:23:47 +0300 Subject: [PATCH 1/2] flake.nixConfig: fix flake-registry config settings Before this commit, nixConfig.flake-registry didn't have any real effect on the evaluation, since config was applied after inputs were evaluated. Change this behavior: apply the config in the beginning of flake::lockFile. --- src/libcmd/installables.cc | 2 -- src/libexpr/flake/flake.cc | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index fe52912cf..540e53eee 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -575,8 +575,6 @@ std::shared_ptr InstallableFlake::getLockedFlake() const { if (!_lockedFlake) { _lockedFlake = std::make_shared(lockFlake(*state, flakeRef, lockFlags)); - _lockedFlake->flake.config.apply(); - // FIXME: send new config to the daemon. } return _lockedFlake; } diff --git a/src/libexpr/flake/flake.cc b/src/libexpr/flake/flake.cc index 8e6f06949..b57679d3b 100644 --- a/src/libexpr/flake/flake.cc +++ b/src/libexpr/flake/flake.cc @@ -298,6 +298,9 @@ LockedFlake lockFlake( auto flake = getFlake(state, topRef, lockFlags.useRegistries, flakeCache); + flake.config.apply(); + // FIXME: send new config to the daemon. + try { // FIXME: symlink attack From e756a59c72e3e793ed01dec04749fa356f263315 Mon Sep 17 00:00:00 2001 From: Alexander Bantyev Date: Thu, 1 Jul 2021 17:54:22 +0300 Subject: [PATCH 2/2] fixup! flake.nixConfig: fix flake-registry config settings --- src/libcmd/installables.cc | 4 +++- src/libexpr/flake/flake.cc | 6 ++++-- src/libexpr/flake/flake.hh | 4 ++++ src/nix/flake.cc | 4 ++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index 540e53eee..269be11a2 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -573,8 +573,10 @@ InstallableFlake::getCursors(EvalState & state) std::shared_ptr InstallableFlake::getLockedFlake() const { + flake::LockFlags lockFlagsApplyConfig = lockFlags; + lockFlagsApplyConfig.applyNixConfig = true; if (!_lockedFlake) { - _lockedFlake = std::make_shared(lockFlake(*state, flakeRef, lockFlags)); + _lockedFlake = std::make_shared(lockFlake(*state, flakeRef, lockFlagsApplyConfig)); } return _lockedFlake; } diff --git a/src/libexpr/flake/flake.cc b/src/libexpr/flake/flake.cc index b57679d3b..e266bc36d 100644 --- a/src/libexpr/flake/flake.cc +++ b/src/libexpr/flake/flake.cc @@ -298,8 +298,10 @@ LockedFlake lockFlake( auto flake = getFlake(state, topRef, lockFlags.useRegistries, flakeCache); - flake.config.apply(); - // FIXME: send new config to the daemon. + if (lockFlags.applyNixConfig) { + flake.config.apply(); + // FIXME: send new config to the daemon. + } try { diff --git a/src/libexpr/flake/flake.hh b/src/libexpr/flake/flake.hh index d17d5e183..4479e95db 100644 --- a/src/libexpr/flake/flake.hh +++ b/src/libexpr/flake/flake.hh @@ -104,6 +104,10 @@ struct LockFlags references like 'nixpkgs'. */ bool useRegistries = true; + /* Whether to apply flake's nixConfig attribute to the configuration */ + + bool applyNixConfig = false; + /* Whether mutable flake references (i.e. those without a Git revision or similar) without a corresponding lock are allowed. Mutable flake references with a lock are always diff --git a/src/nix/flake.cc b/src/nix/flake.cc index 64fcfc000..9055b07eb 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -84,6 +84,7 @@ struct CmdFlakeUpdate : FlakeCommand lockFlags.recreateLockFile = true; lockFlags.writeLockFile = true; + lockFlags.applyNixConfig = true; lockFlake(); } @@ -114,6 +115,7 @@ struct CmdFlakeLock : FlakeCommand settings.tarballTtl = 0; lockFlags.writeLockFile = true; + lockFlags.applyNixConfig = true; lockFlake(); } @@ -270,6 +272,8 @@ struct CmdFlakeCheck : FlakeCommand settings.readOnlyMode = !build; auto state = getEvalState(); + + lockFlags.applyNixConfig = true; auto flake = lockFlake(); bool hasErrors = false;