Commit Graph

35 Commits

Author SHA1 Message Date
Charlie Moog
0b4c5d23cd
trivial-builders: add meta.mainProgram to writeShellScriptBin
Derivations built with `writeShellScriptBin`
should always be runnable with `nix run`. At present,
the derivation is missing both `meta.mainProgram`
and `pname`– this means that `nix run` falls back
to inferring the bin path from `name`. This is
unreliable and depends on faulty heuristics.

For context, reference the following snippet from
`nix run --help`:

    If installable evaluates to a derivation, it will try to execute the
    program <out>/bin/<name>, where out is the primary output store path
    of the derivation, and name is the first of the following that exists:

      · The meta.mainProgram attribute of the derivation.
      · The pname attribute of the derivation.
      · The name part of the value of the name attribute of the derivation.
2023-08-11 00:40:37 -05:00
Francesco Gazzetta
b2e987dd16
Merge pull request #240348 from fgaz/write-shell-application/check-platforms
writeShellApplication: use shellcheck only where supported
2023-08-09 12:17:46 +02:00
Francesco Gazzetta
2c5990f03a writeShellApplication: use shellcheck only where supported 2023-08-05 18:31:20 +02:00
K900
8bd0cd850b requireFile: fix error message with SRI hashes 2023-08-04 15:34:30 +03:00
Robert Hensing
0dd3989cef tests.trivial-builders.writeTextFile: Test meta.mainProgram logic 2023-07-26 18:45:54 +02:00
Robert Hensing
a6aabd9d28 tests.trivial-builders.references: Only run where supported 2023-07-26 18:22:34 +02:00
Robert Hensing
89bdfd4687 trivial-builders: Move test list closer 2023-07-26 18:22:33 +02:00
Robert Hensing
d1dc8384ca writeCBin: Add meta.mainProgram
... and add tests.
2023-07-26 18:22:26 +02:00
Naïm Favier
9be0bfb5e0
runCommand: don't set meta.position if meta is given
Fixes #242093 without breaking #237589

If `meta` is given we probably already have position information, so no
need to get it from the arguments.
2023-07-07 19:12:35 +02:00
Artturin
fb8fdc33e8 makeSetupHook: unbreak structuredAttrsByDefault 2023-06-30 19:38:26 +03:00
Naïm Favier
2e6013cf1b
runCommand: set meta.position from the arguments
Currently all packages defined by a call to runCommand have their
meta.position pointing to trivial-builders.nix.

This change makes uses of runCommand that supply at least one attribute
in the second argument point to the right file.
2023-06-14 23:27:45 +02:00
figsoda
137dd249c5 writeTextFile: revert workaround for executable = null 2023-05-31 09:25:18 -04:00
figsoda
4431bab003 writeTextFile: fix when executable is not a bool 2023-05-29 15:48:49 -04:00
figsoda
4b94ae4bc6 writeTextFile: set meta.mainProgram based on destination 2023-05-27 12:39:53 -04:00
Yueh-Shun Li
b29d5f60b8 writeScriptBin, writeShellScriptBin: add meta.mainProgram automatically 2023-05-26 04:54:03 +08:00
Sandro
cac19e0266
trivial-builders: move into the directory named alike (#223429)
While searching for something different I wondered why there is a
trivial-builders.nix file next to the trivial-builders directory where
only tests live. Lets fix that.
2023-05-06 00:16:26 +02:00
Naïm Favier
e6f19ea429
writeTextFile: chmod before checkPhase
Set the executable bit before running the check phase, so that the check
phase can run the script to test its behaviour.

This aligns with what `concatTextFile` is doing.

Also use explicit `if` statements so that we don't silently ignore
`chmod` failures.
2023-03-29 14:06:45 +02:00
Adam Joseph
1a657f18f7 trivial-builders/test/references.nix: fix eval
The command

```
nix-build -A tests.trivial-builders.references --show-trace
```

fails eval with

```
in job ‘nixpkgs.tests.trivial-builders.references’:
error: The option `meta.description' does not exist. Definition values:
       - In `makeTest parameters': "Run the Nixpkgs trivial builders tests"
```

because `meta.description` and `meta.license` are not valid for
`nixosTest`s (they are valid for `mkDerivation` of course).

This has been causing Hydra eval failures:

  https://hydra.nixos.org/jobset/nixos/pr-209870-gcc-external-bootstrap#tabs-errors

Let's fix eval by removing these attributes.
2023-03-17 20:56:20 -07:00
Bernardo Meurer
43bf542ccd
tests.trivial-builders.linkFarm: init 2022-11-15 11:47:36 -05:00
Robert Hensing
ae172a2bb4 treewide: nixosTest -> testers.nixosTest 2022-05-09 14:16:06 +02:00
K900
7e3c503257 build-support/writeTextFile: add test for weird file names 2022-03-10 13:30:46 +03:00
polykernel
4a9d9928dc nixos/nix-daemon: use structural settings
The `nix.*` options, apart from options for setting up the
daemon itself, currently provide a lot of setting mappings
for the Nix daemon configuration. The scope of the mapping yields
convience, but the line where an option is considered essential
is blurry. For instance, the `extra-sandbox-paths` mapping is
provided without its primary consumer, and the corresponding
`sandbox-paths` option is also not mapped.

The current system increases the maintenance burden as maintainers have to
closely follow upstream changes. In this case, there are two state versions
of Nix which have to be maintained collectively, with different options
avaliable.

This commit aims to following the standard outlined in RFC 42[1] to
implement a structural setting pattern. The Nix configuration is encoded
at its core as key-value pairs which maps nicely to attribute sets, making
it feasible to express in the Nix language itself. Some existing options are
kept such as `buildMachines` and `registry` which present a simplified interface
to managing the respective settings. The interface is exposed as `nix.settings`.

Legacy configurations are mapped to their corresponding options under `nix.settings`
for backwards compatibility.

Various options settings in other nixos modules and relevant tests have been
updated to use structural setting for consistency.

The generation and validation of the configration file has been modified to
use `writeTextFile` instead of `runCommand` for clarity. Note that validation
is now mandatory as strict checking of options has been pushed down to the
derivation level due to freeformType consuming unmatched options. Furthermore,
validation can not occur when cross-compiling due to current limitations.

A new option `publicHostKey` was added to the `buildMachines`
submodule corresponding to the base64 encoded public host key settings
exposed in the builder syntax. The build machine generation was subsequently
rewritten to use `concatStringsSep` for better performance by grouping
concatenations.

[1] - https://github.com/NixOS/rfcs/blob/master/rfcs/0042-config-option.md
2022-01-26 21:04:50 -05:00
Jan Tojnar
f7aa55946b Merge branch 'staging-next' into staging
; Conflicts:
;	nixos/doc/manual/from_md/release-notes/rl-2205.section.xml
;	nixos/doc/manual/release-notes/rl-2205.section.md
;	pkgs/build-support/libredirect/default.nix
2022-01-10 01:26:05 +01:00
Pasquale
86e2880d11
tests.concat: added empty case 2022-01-04 23:14:50 +01:00
Pasquale
5187d2cd8f
concatText: test now works 2021-12-30 13:12:34 +01:00
Naïm Favier
10ec5da56e tests.trivial-builders.overriding: update after shellDryRun 2021-12-27 20:30:01 -05:00
Pasquale
1bc5179d1e
concatText: add test 2021-12-02 21:55:23 +01:00
Robert Hensing
51f7c15df9 test.trivial-builders: Add test cases, fix test runner, rename
The writeStringReferencesToFile didn't handle non-unique references
to the same path correctly.
2021-11-01 00:06:03 +01:00
talyz
aa22fa9c0b trivial-builders: Add writeStringReferencesToFile
Add writeStringReferencesToFile, a builder which extracts a string's
references to derivations and paths and writes them to a text file,
removing the input string itself from the dependency graph. This is
useful when you want to make a derivation depend on the string's
references, but not its content (to avoid unnecessary rebuilds, for
example).
2021-10-28 12:55:01 +02:00
deliciouslytyped
a71e906e3a trivial-builders: refactor writeTextFile to be overridable
This fixes #126344, specifically with the goal of enabling overriding the
checkPhase argument. See `design notes` at the end for details.

This allows among other things, enabling bash extension for the `checkPhase`.
Previously using such bash extensions was prohibited by the `writeShellScript`
code because there was no way to enable the extension in the checker.

As an example:

```nix
(writeShellScript "foo" ''
  shopt -s extglob
  echo @(foo|bar)
'').overrideAttrs (old: {
  checkPhase = ''
    # use subshell to preserve outer environment
    (
      export BASHOPTS
      shopt -s extglob
      ${old.checkPhase}
    )
  '';
})
```

This commit also adds tests for this feature to `pkgs/tests/default.nix`,
under `trivial-overriding`. The test code is located at
`pkgs/build-support/trivial-builders/test-overriding.nix`.

Design notes:
-------------

Per discussion with @sternenseemann, the original approach of just wrapping
`writeTextFile` in `makeOverridable` had the issue that combined with `callPackage`
in the following form, would shadow the `.override` attribute of the `writeTextFile`:

```nix
with import <nixpkgs>;
callPackage ({writeShellScript}: writeShellScript "foo" "echo foo")
```

A better approach can be seen in this commit, where `checkPhase` is moved
from an argument of `writeTextFile`, which is substituted into `buildCommand`,
into an `mkDerivation` argument, which is substituted from the environment
and `eval`-ed. (see the source)

This way we can simple use `.overideAttrs` as usual, and this also makes
`checkPhase` a bit more conformant to `mkDerivation` naming, with respect to
phases generally being overridable attrs.

Co-authored-by: sterni <sternenseemann@systemli.org>
Co-authored-by: Naïm Favier <n@monade.li>
2021-06-18 01:39:59 +02:00
Robert Hensing
c38c5dba10 tests.trivial: Add emptyFile, emptyDirectory to samples 2021-06-12 17:29:27 +02:00
Robert Hensing
14f54a8b3c tests.trivial: Add meta 2021-05-19 11:41:45 +02:00
Robert Hensing
35406647fd tests.trivial: Avoid evaluation and ${pkgs.path} dep
> There is an issue in the test added by #123111.
> [it] introduces a dependency on the contents of nixpkgs,
> making every change evaluate with a different hash.
2021-05-19 01:06:09 +02:00
Robert Hensing
ed4523186e writeReferencesToFile: docs and tests 2021-05-15 17:04:25 +02:00
Robert Hensing
cc60f81e69 writeDirectReferencesToFile: init 2021-05-15 17:04:25 +02:00