1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-24 22:11:15 +02:00
Commit graph

20012 commits

Author SHA1 Message Date
Eelco Dolstra
a976a46ee8
Merge pull request #13123 from Mic92/filesystem-refactoring
Drop fs alias in favour of std::filesystem
2025-05-02 12:52:12 +02:00
Jörg Thalheim
95cf0d31df
Merge pull request #13126 from xokdvium/flex-full
libexpr: Improve lexer performance by using full scanner tables (-Cf)
2025-05-02 10:28:37 +02:00
Sergei Zimmerman
86a3fad085
libexpr: Improve lexer performance by using full scanner tables (-Cf)
This trades off some executable size for measurable lexer performance
improvements.

Note on the explicitly enabling 8bit scanner.
This is needed due to the default behavior of flex (excerpt from the manual [1]):

> Flex’s default behavior is to generate an 8-bit scanner unless you
> use the ‘-Cf’ or ‘-CF’, in which case flex defaults to generating
> 7-bit scanners unless your site was always configured to generate 8-bit
> scanners.

Some quantifyable metrics:

Nixpkgs revision: a6e3f45acf4e817532a861ab0eda4ab5485fecc1
Parsing the largest file in nixpkgs: pkgs/development/haskell-modules/hackage-packages.nix.

(Before this patch)

```
$ nix build github:nixos/nix/9fe3077d4#nix-expr
$ du --apparent-size result/lib/libnixexpr.so
2518    result/lib/libnixexpr.so
$ nix build github:nixos/nix/9fe3077d4#nix-cli
$ taskset -c 2,3 hyperfine "GC_INITIAL_HEAP_SIZE=16g \
    result/bin/nix-instantiate --parse               \
    ../nixpkgs/pkgs/development/haskell-modules/hackage-packages.nix > /dev/null"
  Time (mean ± σ):     375.5 ms ±   6.3 ms    [User: 316.9 ms, System: 56.7 ms]
  Range (min … max):   368.5 ms … 388.3 ms    10 runs
```

(After the patch)

```
$ nix build .#nix-expr
$ du --apparent-size result/lib/libnixexpr.so
2685    result/lib/libnixexpr.so
$ nix build .#nix-cli
$ taskset -c 2,3 hyperfine "GC_INITIAL_HEAP_SIZE=16g \
    result/bin/nix-instantiate --parse               \
    ../nixpkgs/pkgs/development/haskell-modules/hackage-packages.nix > /dev/null"
  Time (mean ± σ):     326.8 ms ±   4.9 ms    [User: 269.5 ms, System: 55.3 ms]
  Range (min … max):   319.7 ms … 335.5 ms    10 runs
```

Overall, the change is roughly:

- 2518KiB -> 2685KiB ~ 150 KiB of machine code
- 375ms -> 325ms ~ 50ms

The perf uplift for eval-heavy test cases is obviously less noticeable,
but it doesn't make sense not to take this free perf win.

[1]: https://westes.github.io/flex/manual/Options-Affecting-Scanner-Behavior.html#Options-Affecting-Scanner-Behavior
2025-05-01 23:10:04 +00:00
Thomas Bereknyei
90deb665eb fix: allow redirected HTTP uploads
When a PUT is redirected, some of the data can be sent by curl before headers are read. This means the subsequent PUT operation needs to seek back to origin.
2025-05-01 11:11:49 -04:00
Jörg Thalheim
9fe3077d47
Merge pull request #13014 from jfly/update-nix_fmt-man-page
Update `nix fmt` man page with official formatter example
2025-05-01 15:11:12 +02:00
Jeremy Fleischman
6f71d8a9c2 Update nix fmt man page with official formatter example
The current example relies upon [nixfmt's deprecated tree traversal
behavior](https://github.com/NixOS/nixfmt/pull/240). The simplest
alternative is the new `nixfmt-tree` wrapper for `nixfmt`/`treefmt`.
2025-05-01 14:30:43 +02:00
Jörg Thalheim
979d5a7cae Drop fs alias in favour of std::filesystem
Since we dropped fs::symlink_exists, we no longer have a need for the fs
namespace. Having less abstractions makes it easier to lookup the
functions in reference documentations.
2025-05-01 14:24:34 +02:00
Jörg Thalheim
5b59be914d Replace symlink_exists with pathExists
As it turns out the orignal implementation of symlink_exists cannot be
used in Nix because it did now std::filesystem::filesystem_error.
The new implementation fixes that but is now actually the same as
pathExists except for the path type.
2025-05-01 14:22:35 +02:00
Jörg Thalheim
143fb88ceb
Merge pull request #13122 from Mic92/directory-iterator
Replace all instances of std::filesystem::directory_iterator with DirectoryIterator
2025-05-01 14:22:21 +02:00
Jörg Thalheim
1c4496f4e5 replace all instances of std::filesystem::directory_iterator with DirectoryIterator 2025-05-01 11:54:26 +02:00
Jörg Thalheim
7ccc0d591f add DirectoryIterator to re-throw std::filesystem::filesystem_error
Co-authored-by: Sergei Zimmerman <145775305+xokdvium@users.noreply.github.com>
2025-05-01 11:54:13 +02:00
Jörg Thalheim
b5dc8181b0
Merge pull request #13107 from fricklerhandwerk/ivory-tower
docs: don't mention Haskell
2025-05-01 10:27:42 +02:00
Jörg Thalheim
5b900120a2
Merge pull request #13117 from NixOS/file-pure-eval
Complain when using --pure-eval with --file
2025-05-01 10:26:41 +02:00
Jörg Thalheim
d5cefa625c
Merge pull request #13120 from Mic92/fix-quoting
replaceSymlink: fix quoting in error message
2025-05-01 10:25:22 +02:00
Jörg Thalheim
408746cba6 replaceSymlink: fix quoting in error message 2025-05-01 08:19:18 +02:00
mergify[bot]
4548dd1abb
Merge pull request #13112 from NaN-git/fix-json-getInteger
bugfix in getInteger(const nlohmann::json &) and add bounds checks
2025-04-30 21:20:49 +00:00
Jörg Thalheim
d155bb9012
Merge pull request #13063 from jfly/add-nix-fmt-print-command-option
Add `nix formatter build` and `nix formatter run` commands
2025-04-30 22:39:48 +02:00
Eelco Dolstra
d46f741cdf Complain when using --pure-eval with --file
This never worked and cannot work because in pure eval mode, the
evaluator doesn't have access to the file.
2025-04-30 22:29:27 +02:00
Jeremy Fleischman
5089f1292d
Refactor, use MixOutLinkByDefault 2025-04-29 18:40:02 -07:00
Jeremy Fleischman
7df7bde306
Refactor, extract some shared code into UnresolvedApp::build 2025-04-29 18:40:02 -07:00
Robert Hensing
e14346c7da
Refactor, dedup nix formatter attribute methods 2025-04-29 18:40:02 -07:00
Jeremy Fleischman
ba6b617e75
Add nix formatter build command
`nix formatter build` is sort of like `nix build`: it builds, links, and
prints a path to the formatter program:

    $ nix formatter build
    /nix/store/cb9w44vkhk2x4adfxwgdkkf5gjmm856j-treefmt/bin/treefmt

Note that unlike `nix build`, this prints the full path to the program,
not just the store path (in the example above that would be
`/nix/store/cb9w44vkhk2x4adfxwgdkkf5gjmm856j-treefmt`).

Motivation
----------

I maintain a vim plugin that automatically runs `nix fmt` on files on
save. Since `nix fmt` can be quite slow due to nix evaluation, I choose
to cache the `nix fmt `entrypoint. This was very awkward to do, see the
implementation for details:
7864607231/lua/null-ls/builtins/formatting/nix_flake_fmt.lua (L83-L110).

I recently discovered that my implementation was buggy (it didn't handle
flakes that expose a `formatter` package, such as nixpkgs), so I had to
rework the implementation:
https://github.com/nvimtools/none-ls.nvim/pull/272.

With the new `nix formatter build` command, I can delete all this akward
code, and it will be easier for other folks to build performant editor
integrations for `nix fmt`.
2025-04-29 18:40:02 -07:00
Jeremy Fleischman
5ea7b97147
refactor: create a new nix formatter run command alias for nix fmt
This refactor shouldn't change much except add a new `nix formatter run`
command. This creates space for the new `nix formatter build` command,
which I'll be introducing in the next commit.
2025-04-29 18:40:02 -07:00
Philipp Otterbein
788be3f964 bugfix in getInteger(const nlohmann::json &) and add bounds checks
improve error messages, too
2025-04-30 01:38:48 +02:00
Eelco Dolstra
9099b7dd87
Merge pull request #13109 from trofi/osc-8-xterm-style-fix
libutil: amend OSC 8 escape stripping for xterm-style separator
2025-04-29 22:39:04 +02:00
Jörg Thalheim
0e2dc8774c
Merge pull request #13105 from roberth/refactor-cli-out-link
Factor out `MixOutLinkByDefault`
2025-04-29 21:19:34 +02:00
Sergei Trofimovich
e322b714dc libutil: amend OSC 8 escape stripping for xterm-style separator
Before the change `nix` was stripping warning flags
reported by `gcc-14` too eagerly:

    $ nix build -f. texinfo4
    error: builder for '/nix/store/i9948l91s3df44ip5jlpp6imbrcs646x-texinfo-4.13a.drv' failed with exit code 2;
           last 25 log lines:
           >  1495 | info_tag (mbi_iterator_t iter, int handle, size_t *plen)
           >       |                                            ~~~~~~~~^~~~
           > window.c:1887:39: error: passing argument 4 of 'printed_representation' from incompatible pointer type []
           >  1887 |                                       &replen);
           >       |                                       ^~~~~~~
           >       |                                       |
           >       |                                       int *

After the change the compiler flag remains:

    $ ~/patched.nix build -f. texinfo4
    error: builder for '/nix/store/i9948l91s3df44ip5jlpp6imbrcs646x-texinfo-4.13a.drv' failed with exit code 2;
       last 25 log lines:
       >  1495 | info_tag (mbi_iterator_t iter, int handle, size_t *plen)
       >       |                                            ~~~~~~~~^~~~
       > window.c:1887:39: error: passing argument 4 of 'printed_representation' from incompatible pointer type [-Wincompatible-pointer-types]
       >  1887 |                                       &replen);
       >       |                                       ^~~~~~~
       >       |                                       |
       >       |                                       int *

Note the difference in flag rendering around the warning.

https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda has a
good sumamry of why it happens. Befomre the change `nix` was handling
just one form or URL separator:

    $ printf '\e]8;;http://example.com\e\\This is a link\e]8;;\e\\\n'

Now it also handled another for (used by gcc-14`):

    printf '\e]8;;http://example.com\aThis is a link\e]8;;\a\n'

While at it fixed accumulation of trailing escape `\e\\` symbol.
2025-04-29 16:12:18 +01:00
Valentin Gagarin
cb9182f9ed docs: don't mention Haskell
sometimes it's these little things that let beginners stumble at the
first step...

mentioning one potentially foreign concept while introducing an entirely
new concept is asking enough already.
2025-04-29 10:58:34 +02:00
Robert Hensing
2ec1303286
Merge pull request #13103 from obsidiansystems/dedup-static-functions
Delete dead code
2025-04-28 18:00:48 +02:00
John Ericson
46030181d4 Delete dead code
We had multiple copies of some static functions after splitting out
`DerivationBuilder` by mistake.
2025-04-28 11:19:36 -04:00
Robert Hensing
9d1f00e31d Factor out MixOutLinkByDefault 2025-04-28 16:54:00 +02:00
mergify[bot]
3d39864b96
Merge pull request #13099 from roberth/doc-evaluation
doc/manual: Add language/evaluation
2025-04-28 08:20:45 +00:00
Eelco Dolstra
5565679b45
Merge pull request #13100 from NaN-git/fix-musl-deadlock
allocate SimpleLogger before forking
2025-04-28 09:01:06 +02:00
Philipp Otterbein
4e95f662db allocate SimpleLogger before forking 2025-04-28 00:46:44 +02:00
Robert Hensing
c81202b358
Merge pull request #13096 from NixOS/no-use-registries
getFlake(): Don't use registries for refetching
2025-04-27 00:42:51 +02:00
Robert Hensing
ee59af99f8
Merge pull request #13098 from roberth/fix-string-ctor
Fix flake-c out of bounds access
2025-04-26 18:46:11 +02:00
Robert Hensing
a525c7e991 doc/manual: Add language/evaluation 2025-04-25 18:06:03 +02:00
Robert Hensing
94916136dc Fix flake-c out of bounds access
The explicit include is needed for clangd to not get confused somehow,
which is also what threw me off initially and made me pick the wrong
constructor.
The (pointer, number, number) constructor first constructs a C string
and then takes a substring from that, but we didn't specify that the
buffer needs to be NUL-terminated, and then what would be the point of
the size argument anyway...

basic_string.h:

>	basic_string(const _Tp& __t, size_type __pos, size_type __n,
>		     const _Alloc& __a = _Alloc())
>	: basic_string(_S_to_string_view(__t).substr(__pos, __n), __a) { }

Valgrind on nixops4/rust/nix-flake tests:

==1344422== Conditional jump or move depends on uninitialised value(s)
==1344422==    at 0x48513E8: strlen (vg_replace_strmem.c:505)
==1344422==    by 0x488E941: UnknownInlinedFun (char_traits.h:391)
==1344422==    by 0x488E941: UnknownInlinedFun (string_view:141)
==1344422==    by 0x488E941: UnknownInlinedFun (basic_string.h:790)
==1344422==    by 0x488E941: nix_flake_reference_and_fragment_from_string (nix_api_flake.cc:81)
==1344422==    by 0x127332: nix_flake::FlakeReference::parse_with_fragment (lib.rs:123)
2025-04-25 17:07:32 +02:00
Eelco Dolstra
3f811c2373
Merge pull request #13094 from xokdvium/file-content-address-fmt-string
libutil: Add missing format arguments to UsageError ctor
2025-04-25 15:21:57 +02:00
Eelco Dolstra
953ec00794 getFlake(): Don't use registries for refetching
`newLockedRef` is already resolved so there is no need to re-resolve
it.
2025-04-25 13:46:42 +02:00
Sergei Zimmerman
9fff868e39
libutil: Add missing format arguments to UsageError ctor
Once again found by an automated migration to `std::format`.
I've tested that boost::format works fine with `std::string_view`
arguments.
2025-04-25 13:35:16 +03:00
Jörg Thalheim
27047570b5
Merge pull request #13086 from xokdvium/bad-format-string
libutil: Fix invalid boost format string in infinite symlink recursion error
2025-04-25 11:20:04 +02:00
Jörg Thalheim
96a1740942
Merge pull request #13088 from NixOS/fix-ignore-local-registries
Fix ignore local registries
2025-04-25 11:19:25 +02:00
Jörg Thalheim
94edfb1a3b
Merge pull request #13087 from xokdvium/libutil-git-permission-format
libutil: Use correct argument to Error format ctor
2025-04-25 11:18:58 +02:00
Jörg Thalheim
6405d6822d tests/flakes: add regression test for resolving user flakes 2025-04-25 10:34:41 +02:00
Sergei Zimmerman
1b5c8aac12
libutil: Use correct argument to Error format ctor
It seems that the intention was to format a number in base 8 (as
suggested by the %o format specifier), but `perms` is a `std::string`
and not a number. Looks like `rawMode` is the correct thing to use here.
2025-04-24 22:27:03 +00:00
Sergei Zimmerman
bfb357c40b
libutil: Fix invalid boost format string in infinite symlink recursion error
Found while working on an automated migration to `std::format`.
2025-04-24 21:00:24 +00:00
mergify[bot]
b287f33090
Merge pull request #13085 from NixOS/bump-nixpkgs
flake.lock: Update
2025-04-24 20:23:53 +00:00
John Ericson
3e7d85dfdb flake.lock: Update
Flake lock file updates:

• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/f675531bc7e6657c10a18b565cfebd8aa9e24c14?narHash=sha256-gbl9hE39nQRpZaLjhWKmEu5ejtQsgI5TWYrIVVJn30U%3D' (2025-04-09)
  → 'github:NixOS/nixpkgs/8a2f738d9d1f1d986b5a4cd2fd2061a7127237d7?narHash=sha256-sPwcCYuiEopaafePqlG826tBhctuJsLx/mhKKM5Fmjo%3D' (2025-04-23)
2025-04-24 13:43:53 -04:00
Jörg Thalheim
a8fb23b716
Merge pull request #13079 from cole-h/cole-h/push-romznoxnzppy
nix-cli: restore binary-dist artifact to Hydra static builds
2025-04-24 19:29:59 +02:00