Commit graph

9479 commits

Author SHA1 Message Date
Eelco Dolstra
21140c987b Fix doxygen comments 2023-11-14 14:02:57 +01:00
Eelco Dolstra
4329bdf6a3 Move comment 2023-11-14 14:02:57 +01:00
Eelco Dolstra
25cf8f1071
src/libfetchers/union-input-accessor.cc: Apply suggestion
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-11-14 13:57:24 +01:00
Eelco Dolstra
38b07d6347
src/libfetchers/git.cc: Apply suggestion
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-11-14 13:38:03 +01:00
Eelco Dolstra
d74d2fdaa7 Move statusCallbackTrampoline 2023-11-14 13:35:26 +01:00
Eelco Dolstra
21bb180547 Use libgit2 with ssh-exec support
See https://github.com/libgit2/libgit2/pull/6617. This ensures that we
get support for ~/.ssh/config, known_hosts etc.
2023-11-14 13:30:51 +01:00
Andreas Stührk
ad99c8950b Update comment to reflect bind mounts are now used for store in chroot 2023-11-13 23:29:48 +01:00
Tom Bereknyei
0be84c83b2 key and cat: no need for progressBar
otherwise the output will be invisible in common terminal configurations
2023-11-12 15:40:44 -05:00
Graham Christensen
fd5a4a8467 nix upgrade-nix: make the source URL an option
This new option enables organizations to more easily manage their Nix
fleet's deployment, and ensure a consistent and planned rollout of Nix
upgrades.
2023-11-10 12:12:28 -05:00
John Ericson
20b95d6223 Git object hashing in libutil
This is the core functionality but just unit-tested and not yet made
part of the store layer. This is because there is some tech debt around
(a) repeated boilerplate hashing objects (b) better integration of the
new `SourceAccessor` type that needs to be cleaned up first.

Part of RFC 133

Co-Authored-By: Matthew Bauer <mjbauer95@gmail.com>
Co-Authored-By: Carlo Nucera <carlo.nucera@protonmail.com>
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Florian Klink <flokli@flokli.de>
2023-11-10 11:02:44 -05:00
John Ericson
3d9d5dc189 Create MemorySink
This is for writing to a `MemorySourceAccessor`.
2023-11-10 11:02:37 -05:00
Eelco Dolstra
cf59ea83ec configure: Check for libgit2 2023-11-10 13:58:59 +01:00
Eelco Dolstra
98a120b8b8 Merge remote-tracking branch 'origin/master' into libgit2 2023-11-09 16:48:41 +01:00
Robert Hensing
12953b942c
Fixup docs 2023-11-09 07:08:56 +01:00
John Ericson
f0adb72c23 Mark fetchTree as unstable again
As discussed in our last meeting, we need a bit more time, but we are
"time boxing" the work left to do to ensure there is not unbounded
delay.

Rather than putting it back underneath `flakes`, though, put it
underneath its own `fetch-tree` experimental feature (which `flakes`
includes/implies). This signals our commitment to the plan to stabilize
it first without waiting to go through the rest of Flakes, and also will
give users a "release candidate" when we get closer to stabilization.

This reverts commit 4112dd1fc9.
2023-11-08 23:23:56 -05:00
John Ericson
d854e8696b Specify the size of the experimental feature array in a more robust way
See doc comment for details.
2023-11-08 22:58:10 -05:00
Jacek Galowicz
df8bfe84cc Fix consts and casts 2023-11-08 17:29:55 +01:00
Jacek Galowicz
c581143e0c Use structured binding for json iteration 2023-11-08 17:29:55 +01:00
Jacek Galowicz
77dceb2844 Drop obsolete assert and cast 2023-11-08 17:29:55 +01:00
Jacek Galowicz
6a47629530 Fix initialization of struct members (wrong order) 2023-11-08 17:29:55 +01:00
Robert Hensing
ab69dc4da3 Test parseShebangContent round trip 2023-11-07 13:24:01 -05:00
Robert Hensing
589d338776 parseShebangs: Make strings with backtick sequences representable 2023-11-07 13:24:01 -05:00
Robert Hensing
ffd414eb75 Fix nix shebang interaction with #8131 overhaul completions 2023-11-07 13:24:01 -05:00
Robert Hensing
e91fd837ee Move shebang docs from rl-next to nix.md 2023-11-07 13:24:01 -05:00
Robert Hensing
51bb69535b nix/installables.cc: Use getCommandBaseDir() where possible
These usages of the working directory are perhaps unlikely to
interact with shebangs, but the code is more consistent this way,
and we're less likely to miss usages that do interact.
2023-11-07 13:24:01 -05:00
Robert Hensing
466271568b nix: Parse --file relative to shebang script 2023-11-07 13:24:01 -05:00
Robert Hensing
198bc22e3b nix: Add command baseDir to parse --expr relative to shebang script 2023-11-07 13:24:01 -05:00
Robert Hensing
20ff61ab25 nix: Reserve shebang line syntax and only parse double backtick quotes
Being restrictive about syntax leaves opportunity to improve the
syntax and functionality later.
2023-11-07 13:24:01 -05:00
Robert Hensing
cc68ed8ff7 libcmd: lookupFileArg(): add baseDir
This will allow a different base directory to be used, matching
a shebang script location instead of the working directory.
2023-11-07 13:24:01 -05:00
Tom Bereknyei
bbeddf0602 fix: refactor parseCmdline interface 2023-11-07 13:24:01 -05:00
Tom Bereknyei
e6ed729243 doc: remove reference to nix-shell 2023-11-07 13:24:01 -05:00
Tom Bereknyei
06f3583b1c feat: break out of shebang processing for non-comments 2023-11-07 13:24:01 -05:00
Tom Bereknyei
01f61cefcb Read file incrementally 2023-11-07 13:24:01 -05:00
Tom Bereknyei
bfcbf3b5bf doc: shebang release notes, docs, tests
fix: release notes
2023-11-07 13:24:01 -05:00
Eelco Dolstra
5f9b5758b6 src/libutil/util.hh: Formatting 2023-11-07 13:24:01 -05:00
Tom Bereknyei
74210c12fe Shellbang support with flakes
Enables shebang usage of nix shell. All arguments with `#! nix` get
added to the nix invocation. This implementation does NOT set any
additional arguments other than placing the script path itself as the
first argument such that the interpreter can utilize it.

Example below:

```
    #!/usr/bin/env nix
    #! nix shell --quiet
    #! nix nixpkgs#bash
    #! nix nixpkgs#shellcheck
    #! nix nixpkgs#hello
    #! nix --ignore-environment --command bash
    # shellcheck shell=bash
    set -eu
    shellcheck "$0" || exit 1
    function main {
        hello
        echo 0:"$0" 1:"$1" 2:"$2"
    }
    "$@"
```

fix: include programName usage

EDIT: For posterity I've changed shellwords to shellwords2 in order
      not to interfere with other changes during a rebase.
      shellwords2 is removed in a later commit. -- roberth
2023-11-07 13:24:01 -05:00
Mel Zuser
61d6fe059e
Fix boost::bad_format_string exception in builtins.addErrorContext (#9291)
* Fix boost::bad_format_string exception in builtins.addErrorContext

The message passed to addTrace was incorrectly being used as a format
string and this this would cause an exception when the string contained
a '%', which can be hit in places where arbitrary file paths are
interpolated.

* add test
2023-11-06 19:13:40 +00:00
Robert Hensing
1fa87c6aa8
Merge pull request #9283 from obsidiansystems/mememory-source-accessor
Factor out `MemorySourceAccessor`, implement missing features
2023-11-06 19:51:02 +01:00
John Ericson
dcc49744ed
Merge pull request #9293 from ThinkChaos/ssh-misc-improvments
SSH small improvments
2023-11-06 13:33:51 -05:00
John Ericson
dea63bb810
Merge pull request #9299 from tfc/config-improvements
Improvements in src/libutil/config.*
2023-11-06 13:03:54 -05:00
John Ericson
cc46ea1630 Make nix path-info --json return an object not array
Before it returned a list of JSON objects with store object information,
including the path in each object. Now, it maps the paths to JSON
objects with the metadata sans path.

This matches how `nix derivation show` works.

Quite hillariously, none of our existing functional tests caught this
change to `path-info --json` though they did use it. So just new
functional tests need to be added.
2023-11-06 11:06:31 -05:00
John Ericson
a7212e169b Include compression in the NarInfo JSON format
It was forgotten before.
2023-11-06 11:06:31 -05:00
John Ericson
937e02e7b9 Shuffle ValidPathInfo JSON rendering
`Store::pathInfoToJSON` was a rather baroque functions, being full of
parameters to support both parsed derivations and `nix path-info`. The
common core of each, a simple `dValidPathInfo::toJSON` function, is
factored out, but the rest of the logic is just duplicated and then
specialized to its use-case (at which point it is no longer that
duplicated).

This keeps the human oriented CLI logic (which is currently unstable)
and the core domain logic (export reference graphs with structured
attrs, which is stable), separate, which I think is better.
2023-11-06 11:06:31 -05:00
Jacek Galowicz
a4b7df7bfa More const, scope reductions, move fixes 2023-11-06 16:00:25 +01:00
Jacek Galowicz
f404e9b3b3 Make toJSONObject const 2023-11-06 16:00:25 +01:00
Jacek Galowicz
ad385f9ec4 Minor improvements 2023-11-06 16:00:25 +01:00
Jacek Galowicz
07ac53732b Fix moves in appendOrSet 2023-11-06 16:00:25 +01:00
John Ericson
0b0d1b5214 Add comparison functions for NarInfo
We will need these for tests.
2023-11-06 09:51:21 -05:00
ThinkChaos
2fb49759b8
fix(ssh): log first line of stdout
Spent a while debugging why `nix-copy-closure` wasn't working anymore
and it was my shell RC printing something I added for debug.
Hopefully this can save someone else some time.
2023-11-06 08:46:19 -05:00
ThinkChaos
6472c3bf0d
fix(ssh): extraneous master processes 2023-11-06 08:45:14 -05:00
John Ericson
ac89bb064a Split up util.{hh,cc}
All OS and IO operations should be moved out, leaving only some misc
portable pure functions.

This is useful to avoid copious CPP when doing things like Windows and
Emscripten ports.

Newly exposed functions to break cycles:

 - `restoreSignals`
 - `updateWindowSize`
2023-11-05 12:20:02 -05:00
John Ericson
2678b51b31 Narrower scope for nativeSystem
I don't think we need a CPP defininition and a header entry, and this
way allows constant expression elimination.
2023-11-05 12:18:28 -05:00
John Ericson
9b880e3e29 Factor out MemorySourceAccessor, implement missing features
The new `MemorySourceAccessor` rather than being a slightly lossy flat
map is a complete in-memory model of file system objects.

Co-authored-by: Eelco Dolstra <edolstra@gmail.com>
2023-11-04 15:24:20 -04:00
Valentin Gagarin
8e222fbb12
Merge pull request #8848 from BootRhetoric/flake-authentication 2023-11-04 00:23:28 +01:00
BootRhetoric
098f0615c9
fetchGit and flake: add publicKeys list input
This adds publicKeys as an optional fetcher input attribute to flakes
and builtins.fetchGit to provide a nix interface for the json-encoded
`publicKeys` attribute of the git fetcher.

Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-11-03 20:23:31 +01:00
BootRhetoric
6df32889a5
Add git commit verification input attributes
This implements the git input attributes `verifyCommit`, `keytype`,
`publicKey` and `publicKeys` as experimental feature
`verified-fetches`. `publicKeys` should be a json string.
This representation was chosen because all attributes must be of type bool,
int or string so they can be included in flake uris (see definition of
fetchers::Attr).
2023-11-03 20:15:12 +01:00
r-vdp
60b363936d
libstore/ssh-ng: Fix phase reporting in log files.
When doing local builds, we get phase reporting lines in the log file,
they look like '@nix {"action":"setPhase","phase":"unpackPhase"}'.
With the ssh-ng protocol, we do have access to these messages, but since we
are only including messages of type resBuildLogLine in the logs, the phase
information does not end up in the log file.

The phase reporting could probably be improved altoghether (it looks like it
is kind of accidental that these JSON messages for phase reporting show up
but others don't, just because they are actually emitted by nixpkgs' stdenv),
but as a first step I propose to make ssh-ng behave in the same way as local builds do.
2023-11-03 12:30:25 +01:00
Eelco Dolstra
b0455e9931 Fix uninitialized variable warnings on i686-linux
https://hydra.nixos.org/build/239849607
2023-11-03 12:04:20 +01:00
Eelco Dolstra
55dd1244d2 parseDerivation(): Fix warning about uninitialized 'version' variable 2023-11-03 12:04:20 +01:00
John Ericson
d15c3a33e6 Don't use std::invocable C++ concept yet
It s not supported on all platforms yet. Can revert this once it is.
2023-11-02 12:06:29 -04:00
John Ericson
b107431816 Systematize characterization tests a bit more
Deduplicating code moreover enforcing the pattern means:

 - It is easier to write new characterization tests because less boilerplate

 - It is harder to mess up new tests because there are fewer places to
   make mistakes.

Co-authored-by: Jacek Galowicz <jacek@galowicz.de>
2023-11-02 12:06:08 -04:00
Eelco Dolstra
39ea46abb1 Merge remote-tracking branch 'origin/master' into libgit2 2023-11-02 16:16:37 +01:00
John Ericson
90de958637
Merge pull request #9265 from obsidiansystems/better-parse-sink
Make `ParseSink` a bit better
2023-11-02 09:28:29 -04:00
Eelco Dolstra
5223114c93
Merge pull request #9269 from edolstra/unify-accessor
Unify `FSAccessor` and `SourceAccessor`
2023-11-02 14:23:10 +01:00
Zbigniew Jędrzejewski-Szmek
55ed09c4f2 Remove stray executable permissions on source files
Noticed because of a warning during an rpm build:
*** WARNING: ./usr/src/debug/nix-2.18.1-1.fc40.x86_64/src/nix-copy-closure/nix-copy-closure.cc is executable but has no shebang, removing executable bit
*** WARNING: ./usr/src/debug/nix-2.18.1-1.fc40.x86_64/src/nix-channel/nix-channel.cc is executable but has no shebang, removing executable bit
2023-11-02 09:24:21 +01:00
Eelco Dolstra
e47984ce0b
Fix whitespace
Co-authored-by: John Ericson <git@JohnEricson.me>
2023-11-01 20:19:08 +01:00
Zbigniew Jędrzejewski-Szmek
eab9292738 fix: gcc complains about if which doesn't guard the indented statement 2023-11-01 18:10:06 +01:00
Eelco Dolstra
2f5c1a27dc LocalStoreAccessor: Reuse PosixSourceAccessor 2023-11-01 17:22:25 +01:00
Eelco Dolstra
1a902f5fa7 Merge FSAccessor into SourceAccessor 2023-11-01 17:09:28 +01:00
Eelco Dolstra
581693bdea fmt(): Handle std::string_view 2023-11-01 16:33:22 +01:00
Eelco Dolstra
50aae0a14c FSAccessor: Make the fileSize and narOffset fields optional
The narOffset field only applies to NAR accessors. The fileSize field
may be too expensive to compute for certain accessors (e.g. libgit).
2023-11-01 15:39:40 +01:00
Eelco Dolstra
5381123879 Unify DirEntries types 2023-11-01 15:33:35 +01:00
Eelco Dolstra
cdb27c1519 SourceAccessor: Change the main interface from lstat() to maybeLstat() 2023-11-01 15:26:07 +01:00
Eelco Dolstra
8ffd1695ce Unify FSAccessor::Type and SourceAccessor::Type 2023-11-01 14:43:20 +01:00
John Ericson
0707db2b1c
Merge pull request #9255 from NixOS/libfetcher-docs-json
libfetcher doc automation
2023-11-01 09:38:02 -04:00
Eelco Dolstra
b2ac6fc040 Remove FSAccessor::Type::tMissing
Instead stat() now returns std::nullopt to denote that the file
doesn't exist.
2023-11-01 14:36:40 +01:00
John Ericson
1093d6585f Make ParseSink a bit better
I wouldn't call it *good* yet, but this will do for now.

- `RetrieveRegularNARSink` renamed to `RegularFileSink` and moved
  accordingly because it actually has nothing to do with NARs in
  particular.

  - its `fd` field is also marked private

- `copyRecursive` introduced to dump a `SourceAccessor` into a
  `ParseSink`.

- `NullParseSink` made so `ParseSink` no longer has sketchy default
  methods.

This was done while updating #8918 to work with the new
`SourceAccessor`.
2023-11-01 02:36:43 -04:00
John Ericson
b2cae33aef Remove bug-avoiding StoreConfig * casts for settings
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80431 has been fixed, and
per the previous commit we now check that is the case at build time.
2023-10-31 12:09:46 -04:00
Eelco Dolstra
0c5eac9c45 Git fetcher: Handle submodules for workdirs 2023-10-31 15:59:25 +01:00
Felix Uhl
f282ef5a56 fix: segfault in positional arg completion
Adding the inputPath as a positional feature uncovered this bug.
As positional argument forms were discarded from the `expectedArgs`
list, their closures were not. When the `.completer` closure was then
called, part of the surrounding object did not exist anymore.

This didn't cause an issue before, but with the new call to
`getEvalState()` in the "inputs" completer in nix/flake.cc, a segfault
was triggered reproducibly on invalid memory access to the `this`
pointer, which was always 0.

The solution of splicing the argument forms into a new list to extend
their lifetime is a bit of a hack, but I was unable to get the "nicer"
iterator-based solution to work.
2023-10-31 15:33:57 +01:00
Felix Uhl
c7dcdb8325 Overhaul nix flake update and lock commands
Closes #5110
2023-10-31 15:33:57 +01:00
Felix Uhl
c762b65dc5 Fix documentation of flake command output 2023-10-31 15:33:57 +01:00
Felix Uhl
1fd0867389 Fix missing output when creating lockfile 2023-10-31 15:33:50 +01:00
Eelco Dolstra
669b074f51 Cleanup 2023-10-31 14:52:21 +01:00
Eelco Dolstra
d88106df24 Git fetcher: Improve submodule handling
Instead of making a complete copy of the repo, fetching the
submodules, and writing the result to the store (which is all
superexpensive), we now fetch the submodules recursively using the Git
fetcher, and return a union accessor that "mounts" the accessors for
the submodules on top of the root accessor.
2023-10-31 14:52:21 +01:00
Eelco Dolstra
ee36a44bf2 GitInputScheme: Use libgit2
This replaces most calls to the "git" binary with libgit2.
2023-10-31 14:52:21 +01:00
Eelco Dolstra
1d0e3d84b6 Provide a InputScheme::fetch() built on top of InputScheme::getAccessor()
This is for graceful migration to lazy-trees fetchers (which are all
accessor-based). Eventually fetch() will be removed.
2023-10-31 14:52:17 +01:00
Eelco Dolstra
e1b8442fa1 Fetcher cache: Add support for caching facts not related to store paths 2023-10-31 14:51:39 +01:00
Eelco Dolstra
fa6bc33604
Merge pull request #9239 from edolstra/putFile
Input: Replace markFileChanged() by putFile()
2023-10-31 14:49:42 +01:00
Eelco Dolstra
05316d401f Cleanup 2023-10-30 17:03:06 +01:00
John Ericson
077de2968e Include fetcher input scheme info in the CLI dump
Leverages the previous commit.
2023-10-30 10:30:59 -04:00
John Ericson
8381eeda6f Systematize fetcher input attribute validation
We now have `schemeName` and `allowedAttrs` functions for this purpose.
We look up the schema with the former; we restrict the set of input
attributes with the latter.
2023-10-30 10:17:24 -04:00
John Ericson
a419b61497 Turn derivation unit tests into unit characterization tests
The brings a number of advantages, including:

- Easier to update test data if design changes (and I do think our
  derivation JSON is not yet complaint with the guidelines).

- Easier to reuse test data in other implementations, inching closer to
  compliance tests for Nix *the concept* rather than any one
  implementation.
2023-10-26 18:09:01 -04:00
Sergei Trofimovich
e69c764708 local-derivation-goal.cc: slightly clarify waiting message
Before the change builder ID exhaustion printed the following message:

    [0/1 built] waiting for UID to build '/nix/store/hiy9136x0iyib4ssh3w3r5m8pxjnad50-python3.11-breathe-4.35.0.drv'

After the change it should be:

    [0/1 built] waiting for a free build user ID for '/nix/store/hiy9136x0iyib4ssh3w3r5m8pxjnad50-python3.11-breathe-4.35.0.drv'
2023-10-26 20:54:21 +01:00
John Ericson
1dc6a65d36
Merge pull request #9238 from tfc/small-improvements2
Small improvements 2
2023-10-26 09:35:03 -04:00
Jacek Galowicz
28c39c370c Provide default value for id to fix warning 2023-10-26 09:47:40 +02:00
Jacek Galowicz
b66381e8d8 Use using instead of typedef 2023-10-26 09:47:40 +02:00
Silvan Mosberger
46028ff764
doc: Fix fetchGit default name (#9241) 2023-10-26 07:05:48 +02:00
Eelco Dolstra
622191c2b5
Merge pull request #8965 from Artturin/bindfilesinchroot
Bindmount files instead of hardlinking or copying to chroot
2023-10-25 19:10:03 +02:00
Eelco Dolstra
15c430f389 Remove unused LockFile::write() 2023-10-25 18:44:09 +02:00