Commit Graph

76 Commits

Author SHA1 Message Date
Philip Taron
efb603b277 Avoid top-level with ...; in pkgs/build-support/writers/test.nix 2024-03-19 22:31:19 +01:00
annalee
636ed70ab3
Merge remote-tracking branch 'upstream/staging-next' into staging 2024-03-16 00:07:22 +00:00
Philip Taron
dc59ca2bd9
Avoid lib.or in pkgs/build-support/writers/ 2024-03-14 14:11:11 -07:00
DavHau
9a5b86c189 writers: add support for wrapping
Add a makeWrapperArgs argument to all script writers under pkgs.writers.

This can be used to set, prefix, or suffix the PATH or other environment variables which improves the ability to generate scripts with reproducible behavior.

Some of the writers (writeBash, writeDash, writeFish, writeNu) previously did not support passing an argument set, for example
```
writeBash "example" "echo hello"

```

In order to add the new capability to these writers as well, their call signature is now overloaded in order to allow the following:
(The old call style from the example above remains intact)
```
writeBash "example"
  { makeWrapperArgs = [ "--prefix" "PATH" ":" "${pkgs.hello}/bin" ]; }
  ''
    hello
  ''
```

Done as well:
- add tests
- add more docs
- fix some misleading docs
- extend existing docs with more examples
2024-03-05 14:25:42 +07:00
Vladimír Čunát
ea4b95755d
Revert "writers: add support for wrapping" 2024-03-04 07:05:23 +01:00
lassulus
97345af560
Merge pull request #291854 from DavHau/writers-wrap
writers: add support for wrapping
2024-03-04 08:37:18 +07:00
DavHau
3e3ae4ecf5 writers: add support for wrapping
Add a makeWrapperArgs argument to all script writers under pkgs.writers.

This can be used to set, prefix, or suffix the PATH or other environment variables which improves the ability to generate scripts with reproducible behavior.

Some of the writers (writeBash, writeDash, writeFish, writeNu) previously did not support passing an argument set, for example
```
writeBash "example" "echo hello"

```

In order to add the new capability to these writers as well, their call signature is now overloaded in order to allow the following:
(The old call style from the example above remains intact)
```
writeBash "example"
  { makeWrapperArgs = [ "--prefix" "PATH" ":" "${pkgs.hello}/bin" ]; }
  ''
    hello
  ''
```

Done as well:
- add tests
- add more docs
- fix some misleading docs
- extend existing docs with more examples
2024-02-29 17:31:58 +07:00
Johannes Kirschbauer
54658a47d0
doc: improve pkgs.writers comments 2024-02-29 10:38:03 +01:00
Tulili
1e7dc0e1b8 pkgs.writers: fix type in description for writeHaskellBin 2024-01-30 06:48:51 +01:00
Tulili
703a085c0a pkgs.writers: tests for lua ruby, and remove failed tests because of external package errors 2024-01-30 06:48:43 +01:00
Tulili
f6e0ee5545 pkgs.writers: remove tests that dont work anymore and add comments tracking issues 2024-01-30 06:48:35 +01:00
Tulili
05ad04bdd3 pkgs.writers add snu, lua and ruby 2024-01-30 06:48:15 +01:00
Raphael Robatsch
5ba1e86bb0 tests.writers.simple.fsharp: Add missing dependency
This test currently fails because `FSharp.SystemTextJson` depends on
`System.Text.Json`. Fix the test by adding the missing dependency.
2023-12-11 09:47:06 +01:00
Robert Hensing
a6622bf00a writers/test: Refactor
It now also checks the executable bit.
2023-10-24 11:17:38 +02:00
Robert Hensing
e64f987fd6 writers.makeDataWriter: Deprecate 2023-10-24 11:17:38 +02:00
Robert Hensing
79130267d3 writers/data.nix: Remove duplicate implementations 2023-10-24 11:17:38 +02:00
Vladimír Čunát
d5732d9669
Merge branch 'staging-next' into staging 2023-08-05 07:45:29 +02:00
Simon Žlender
8e912feb29 codesign_allocate: reference cctools 2023-08-01 21:27:09 +02:00
Robert Hensing
0ed9e35a22 writers: Set mainProgram
Part of https://github.com/NixOS/nixpkgs/pull/246386
2023-08-01 12:21:06 +02:00
Ben Wolsieffer
025af47303 writers: use runCommand instead of runCommandNoCC
runCommandNoCC is now an alias for runCommand, which was causing ofborg
failures with allowAliases = false.
2023-07-28 00:39:21 -04:00
Ben Wolsieffer
09dd973987 writers: use callPackages to import sub-groups of writers
Use callPackages instead of plain import to get proper splicing. Without this,
writeNginxConfig fails when cross-compiling.
2023-07-27 22:54:41 -04:00
zimbatm
504e42b559 writers: introduce data writers
Make it easy to write structured data back to disk.
2023-07-22 17:54:41 +02:00
zimbatm
d0c7ffc596 writers: make room for other types of writers 2023-07-22 17:54:41 +02:00
zimbatm
73ee03cbc5 writers: split out the tests
Make it easier to run and debug individual tests.
2023-07-22 17:53:52 +02:00
zimbatm
c04c43ccd1 writers: fix fsharp writer
dotnet needs a writable $HOME to operate
2023-07-22 13:36:31 +02:00
Artturin
3ea5e83373 writers.makePythonWriter: fix interpreter executable 2023-06-17 22:58:14 +03:00
sternenseemann
192d03bee4 writers: fix aarch64-darwin workaround if content is a string
When authoring #220966, I missed that the `//` would take effect solely
in the else branch, fixing hledger-check-fancyassertions, but not
tests.writers.bin.haskell.
2023-03-29 03:29:13 +02:00
sternenseemann
86dbc928fb writers: make codesign_allocate available in PATH on aarch64-darwin
codesign_allocate is assumed to be in PATH:

https://github.com/NixOS/nixpkgs/issues/154203
https://github.com/NixOS/nixpkgs/issues/148189

Using an absolute reference in post-link-sign-hook would be another
possibility, but hasn't been fruitful so far:
https://github.com/NixOS/nixpkgs/pull/148282
https://github.com/NixOS/nixpkgs/pull/208120
2023-03-14 19:45:53 +01:00
Jeremy Schlatter
2581bc08da
writers: fix typo in comment 2023-01-05 20:26:25 -08:00
lassulus
85a36f9146 writers.writeJS: pass arguments to script 2022-10-11 20:16:37 +02:00
pacien
0495b0217b writers.writeFish: avoid loading user config files
This makes the Fish interpreter ignore user configuration files.
This was not desirable for running scripts, especially system ones.
2022-10-10 23:10:36 +02:00
pacien
6e4a14b54f writers: add writeFish and writeFishBin
This adds writers for Fish shell scripts, with syntax checking.
2022-10-10 15:59:23 +02:00
squalus
4246654992 writers.makePythonWriter: fix cross compile
The check script needs to run at build time. Add a new argument to
makePythonWriter for the appropriate buildPackages version of pythonPackages,
and use this to run the check script.
2022-08-25 17:46:34 -07:00
Profpatsch
a1aed2a716 builders/writeHaskell: build with threaded GHC runtime
Some haskell code starts silently hanging when not built with a
threaded runtime, so let’s assume people using `writeHaskell` don’t
care about micro-optimizations like this and do the expected thing.

Some architectures don’t support a threaded runtime, for these we
provide the `threadedRuntime` option to turn it off (it should fail at
build time in that case, easy to detect).

If somebody already passed `"-threaded"` before via ghcArgs, this
will not add the flag a second time. Thus it’s backward-compatible in
this regard.

I tested out both branches (with `-threaded` set and not set before),
on an example I had where the runtime would hang when not compiled
with `-threaded`.
2022-06-30 10:12:50 +02:00
Ben Siraphob
259fa13d53 treewide: remove nativeBuildInputs that are in stdenv 2022-04-16 21:46:46 +03:00
Robert Hensing
200175a701 config.allowAliases: Define as option
This simplifies usages and makes the default value consistent.

In a few cases, the default value was interpreted to be `false`,
but this is useless, because virtually nobody will explicitly
set `allowAliases = true;`.
2022-04-01 11:33:10 +02:00
Moises Nessim
81998d0a1d Add writeFSharp and makeFSharpWriter functions to writers
Uses fsharp interactive (fsi) to run fsx script

Expose mkNugetSource and mkNugetDeps functions

Use them in writers.writeFSharp and buildDotnetModule

Add tests
2022-02-28 17:40:43 -05:00
Markus S. Wamser
b93e478777 writers.PyPy{2,3}: init 2021-12-15 10:01:08 +01:00
Markus S. Wamser
4e42f6bcb3 writers.writePython2: remove 2021-12-15 09:56:14 +01:00
Enno Richter
10c725dc6b writers.makePythonWriter: drop flake8 checks for Python 2 scripts 2021-12-05 09:59:47 +01:00
Uri Baghin
7111193ee6 writers: fix writeRust on darwin 2021-11-13 11:04:36 +11:00
sternenseemann
b1197ac729 writers: run fixupPhase for darwin bin writers
mach-o executables we produce in writers are not always fully valid for
some reason. In normal derivation this is fixed in fixupPhase and we can
replicate this behavior here easily.

Resolves #132660.
2021-10-29 12:34:48 +02:00
sternenseemann
3090ed3f40 writers: use platform's default strip
bintools points to the default bintools (e. g. cctools, binutils,
llvmPackages.bintools) for the next stage. So instead of using GNU
binutils' strip which may not support the current platform, we need to
use buildPackages.bintools-unwrapped.

Additionally we need to use `-S` over `--strip-unneeded` as the latter
is a GNU binutils-specific flag and not supported by cctools.

Also add the correct targetPrefix in order to support cross-compilation
correctly here at least.
2021-10-29 12:18:58 +02:00
Jörg Thalheim
982f46985e writers: drop writeC
This function is fundamentally broken.
Not even the ncurses example will compile.
The interface needs to be rethought for it to work (i.e. don't
unconditionally include all pc files, set include path and ld path and
rpath).
Since it is unlikely that in the current this has any user, just drop it for now.
2021-08-25 20:16:31 +02:00
sternenseemann
6bd0c16f89 tests.writers: also expose path via passthru 2021-07-13 15:22:34 +02:00
Yureka
7f07b70d08 Revert "writers: Allow string paths"
This reverts commit 33ffb05d39.
2021-06-28 22:40:40 +02:00
Silvan Mosberger
33ffb05d39 writers: Allow string paths
Before this change, it was not possible to use string paths,
because then the `types.str.check` would succeed. So the only paths that
could be used were ones from the local filesystem via e.g.
`./some/path`.

We can easily fix this by using `types.path.check` instead to determine
whether we are dealing with a path.

This notably also allows using Nix-fetched sources as the content, e.g.
`fetchFromGitHub { ... } + "/some/file"`
2021-06-25 14:39:59 +02:00
sternenseemann
3bc8e5cd23 tests.writers: use dashes instead of underscores in drv names
This is more in line with standard derivation name policy in nixpkgs.
2021-06-08 14:06:41 +02:00
sternenseemann
f46a1e353a tests.writers: give all test derivations unique names
This makes it easier to debug test failures since the derivation name
will give an indication which writer it belongs to.
2021-06-08 14:06:41 +02:00
rnhmjoj
61b7cab481
treewide: use perl.withPackages when possible
Since 03eaa48 added perl.withPackages, there is a canonical way to
create a perl interpreter from a list of libraries, for use in script
shebangs or generic build inputs. This method is declarative (what we
are doing is clear), produces short shebangs[1] and needs not to wrap
existing scripts.

Unfortunately there are a few exceptions that I've found:

  1. Scripts that are calling perl with the -T switch. This makes perl
  ignore PERL5LIB, which is what perl.withPackages is using to inform
  the interpreter of the library paths.

  2. Perl packages that depends on libraries in their own path. This
  is not possible because perl.withPackages works at build time. The
  workaround is to add `-I $out/${perl.libPrefix}` to the shebang.

In all other cases I propose to switch to perl.withPackages.

[1]: https://lwn.net/Articles/779997/
2021-03-31 21:35:37 +02:00