Commit Graph

187 Commits

Author SHA1 Message Date
Robert Hensing
5f8cb21011
Merge pull request #170583 from ncfavier/mkShellVars
lib/strings: add toShellVars
2022-04-27 23:33:28 +02:00
Naïm Favier
226bc99659
lib/strings: add toShellVars
A straightforward piece of plumbing to safely inject Nix variables into
shell scripts:

''
  ${lib.toShellVars { inherit foo bar; }}
  cmd "$foo" --bar "$bar"
''
2022-04-27 16:04:17 +02:00
Artturin
379b9c8be3 lib/meta: add getExe to get the main program of a drv 2022-04-24 04:19:49 +03:00
matthewcroughan
cad8bbe589 lib: init flakes.nix
This commit creates flakes.nix, which is a library containing functions
which relate to interacting with flakes. It also moves related functions
from trivial.nix into it.
2022-04-12 19:28:23 +01:00
matthewcroughan
c190b08bb7 lib: add callLocklessFlake
This is essentially a copy of the function of the same name, from
flake-compat. callLocklessFlake is useful when trying to utilise a
flake.nix without a lock file, often for when you want to create a
subflake from within a parent flake.

Co-authored-by: Tom Bereknyei <tomberek@gmail.com>
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2022-04-12 19:27:24 +01:00
Naïm Favier
9f5796be49
lib/trivial: actually expose warnIfNot and throwIf 2022-03-27 16:48:33 +02:00
Robert Hensing
6c469679f6 Merge remote-tracking branch 'upstream/master' into tests-restrict-arguments 2022-03-21 23:17:17 +01:00
Robert Hensing
84274cbc95 lib: Add toFunction 2022-03-21 23:14:10 +01:00
Robert Hensing
6a0b24b276 lib: applyIfFunction -> applyModuleArgsIfFunction 2022-03-21 23:14:10 +01:00
Kevin Cox
8ce16fcf62
Merge pull request #163451 from hercules-ci/stop-premature-warnings
Stop premature warnings, including `nix.settings` migration
2022-03-21 10:10:40 -04:00
Silvan Mosberger
85003ecdbb lib.attrsets: Introduce updateManyAttrsByPath 2022-03-18 00:08:29 +01:00
Silvan Mosberger
71b130c581 lib.attrsets: Introduce showAttrPath 2022-03-18 00:05:08 +01:00
Robert Hensing
7377ea57ff lib: Add mkRenamedOptionModuleWith
Adds support for sinceRelease
2022-03-09 14:50:51 +01:00
0x4A6F
3362ff0f7b
Merge pull request #157301 from pennae/lib-add-mkPackageOption
lib: add mkPackageOption to default.nix
2022-02-28 20:37:59 +01:00
pennae
1c0918d828 lib: add mkPackageOption to default.nix
this was forgotten in #155669
2022-01-29 18:28:20 +01:00
Naïm Favier
5a07097772
lib/modules: introduce setDefaultModuleLocation
Wraps a module with a default location for reporting errors.
2022-01-27 22:12:53 +01:00
Robert Hensing
ba3e91ed43 lib.types: Add unique like uniq, but custom errors
Couldn't extend types.uniq and it had a silly name anyway.
Now we can have better error messages.
2022-01-24 16:14:55 +01:00
José Romildo
4fc67da841 lib.checkListOfEnum: init 2022-01-09 19:21:08 -03:00
Robert Hensing
f2c5c706f4 lib.throwIfNot: init 2021-12-22 13:13:50 +01:00
Shamrock Lee
60950f739e lib/meta: add getLicenseFromSpdxId function
Move function spdxLicense, internally used in yarn2nix
to lib/meta.nix, and
rename to getLicenseFromSpdxId

A similar function is implemented in poetry2nix,
but the one originally in yarn2nix seems beter.
since it falls back to an license-like attrset
for mismatched case
instead of a plain string
2021-12-02 18:33:48 +08:00
Taeer Bar-Yam
0bef0c38f7 lib.modules: add mkDerivedConfig
mkDerivedConfig : Option a -> (a -> Definition b) -> Definition b

Create config definitions with the same priority as the definition of another option.
This should be used for option definitions where one option sets the value of another as a convenience.
For instance a config file could be set with a `text` or `source` option, where text translates to a `source`
value using `mkDerivedConfig options.text (pkgs.writeText "filename.conf")`.

It takes care of setting the right priority using `mkOverride`.
2021-11-15 07:03:41 -05:00
Robert Hensing
0699530f08
Merge pull request #136909 from ncfavier/cleanup-defaults-examples
nixos/doc: clean up defaults and examples
2021-10-04 20:37:42 +02:00
Naïm Favier
52a2e4136e
lib/options: add literalExpression and literalDocBook, deprecate literalExample 2021-10-03 17:19:19 +02:00
Robert Helgesson
e75f346aa3
lib: add function escapeXML
Given a string, this function returns a string that can be inserted
verbatim in an XML document.
2021-10-03 11:28:03 +02:00
Harrison Houghton
9d71711aec lib: export strings/escapeRegex
I see no reason why I should be disallowed from using it.
2021-08-22 00:01:38 -04:00
lassulus
229ff549e6 lib: inherit mkImageMediaOverride 2021-08-18 14:21:16 +02:00
Robert Hensing
cad20d8983 lib.mkFixStrictness: Deprecate 2021-07-12 07:31:29 +02:00
Robert Hensing
99bc203025 Partially revert "lib/modules: Drop mkStrict and mkFixStrictness"
mkFixStrictness was never properly deprecated and should only be
removed after warning for some time.

This partially reverts commit 8fb9984690.
2021-07-12 07:25:52 +02:00
Janne Heß
8fb9984690
lib/modules: Drop mkStrict and mkFixStrictness
This was deprecated in 2014 and is not used anywhere in the tree.
2021-06-06 20:53:05 +02:00
Alyssa Ross
81e1e68eaf lib.trivial.warnIf: init
It's a common pattern in Nixpkgs to want to emit a warning in certain
cases, but not actually change behaviours.

This is often expressed as either
	if cond then lib.warn "Don't do that thing" x else x
Or
	(if cond then lib.warn "Don't do that thing" else lib.id) x

Neither of which really expresses the intent here, because it looks
like 'x' is being chosen conditionally.

To make this clearer, I introduce a "warnIf" function, which makes it
clear that the only thing being affected by the condition is whether
the warning is generated, not the value being returned.
2021-04-28 21:44:21 +00:00
Jacek Galowicz
123045a570 lib/attrsets: add cartesianProductOfSets function 2021-01-28 23:08:59 +01:00
Profpatsch
41e13149f7 lib/debug: add traceFnSeqN
Immensely helpful when you want to see the changes a function makes to
its value as it passes through.

Example:

```
$ nix-instantiate --strict --eval -E '(with import ./lib; traceFnSeqN 2 "id" (x: x) { a.b.c = 3; })'
trace: {
  fn = "id";
  from = {
    a = {
      b = {…};
    };
  };
  to = {
    a = {
      b = {…};
    };
  };
}
{ a = { b = { c = 3; }; }; }
```
2021-01-25 19:25:50 +01:00
John Ericson
a6218c058b lib: Create makeScopeWithSplicing
It's ugly as hell, but I suppose it is needed to codify how to make
spliced package sets.
2020-11-19 00:07:14 -05:00
Joe Hermaszewski
c3b35f21f7 lib: Add composeManyExtensions 2020-11-13 21:37:57 +01:00
Robert Hensing
fe4a58eec0 lib: Add lib.trace for consistency
This puts it among the trace* family of functions derived from it.
2020-10-22 13:46:48 +02:00
Robert Hensing
9a4bed1a80 lib: Add lib.isFloat for consistency
Unlike the other three is* functions in lib.trivial, it was only
available as lib.trivial.isFloat
2020-10-22 13:46:48 +02:00
Robert Hensing
afa6c51f27 lib: Use Nix's static scope checking, fix error message, optimize
Nix can perform static scope checking, but whenever code is inside
a `with` expression, the analysis breaks down, because it can't
know statically what's in the attribute set whose attributes were
brought into scope. In those cases, Nix has to assume that
everything works out.

Except it doesnt. Removing `with` from lib/ revealed an undefined
variable in an error message.

If that doesn't convince you that we're better off without `with`,
I can tell you that this PR results in a 3% evaluation performance
improvement because Nix can look up local variables by index.
This adds up with applications like the module system.

Furthermore, removing `with` makes the binding site of each
variable obvious, which helps with comprehension.
2020-10-22 13:46:47 +02:00
zimbatm
947a7d33f9
lib: add importTOML
Complements the `lib.importJSON`. `builtins.readTOML` has been
introduced in Nix 2.1.
2020-09-12 16:37:50 +02:00
Bas van Dijk
6e7822b8f3 lib: toHex -> toHexString & toBase -> toBaseDigits
This makes the type of these functions more apparent from the name.
2020-07-20 13:14:19 +02:00
Bas van Dijk
00022fbeda lib: add the toHex and toBase utility functions
`toHex` converts the given positive integer to a string of the hexadecimal
representation of that integer. For example:

```
toHex 0 => "0"

toHex 16 => "10"

toHex 250 => "FA"
```

`toBase base i` converts the positive integer `i` to a list of it
digits in the given `base`. For example:

```
toBase 10 123 => [ 1 2 3 ]

toBase 2 6 => [ 1 1 0 ]

toBase 16 250 => [ 15 10 ]
```
2020-07-20 13:09:26 +02:00
rnhmjoj
986079275b
lib/attrsets: add getMan function 2020-06-18 10:16:57 +02:00
Emily
aff9979170 lib.fake{Sri => Hash}: fix and rename
The previous hash was too short and caused evaluation-time errors like:

    invalid SRI hash 'sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA='

Additionally, since the fact that this is broken implies that nobody
could have been using it, "SRI" is a bit of a vague and obscure term,
`fakeSriHash` would be somewhat of a mouthful, and the relevant fetcher
parameters are just called `hash`, rename it to `fakeHash`.
2020-05-11 23:11:12 +01:00
Tony Olagbaiye
d2ba3fba69 lib: add shortcut for fake SRI hash 2020-04-05 01:48:20 +01:00
Silvan Mosberger
eff447b321
Merge pull request #70157 from teto/lib_kernel
Add lib.kernel
2020-03-12 23:53:42 +01:00
Jan Tojnar
8515b703cf
Merge pull request #72125 from jtojnar/maintainer-groups
lib: Add lib.maintainer-groups
2020-03-10 21:09:33 +01:00
Robert Hensing
e38a01db5d
Merge pull request #68491 from roberth/fix-dontRecurseIntoAttrs
Fix dontRecurseIntoAttrs + add to lib + doc
2020-03-01 11:05:34 +01:00
Profpatsch
07eb21ceaf
Merge pull request #78337 from Profpatsch/lib-improve-cli-module
lib: improve cli module
2020-01-24 21:05:53 +01:00
Profpatsch
88a7f65c83 lib/cli: unexport symbols & sort with generators
lib/cli is very similar to generators, so it should follow largely the
same interface. Similar to how generators isn’t exported, we should
also namespace cli by default (plus “cli” is only three characters to
type).
2020-01-23 14:47:38 +01:00
Franz Pletz
46773a15b3
nixos/version: fix case where .git is a symlink
Before c9214c394b and
9d396d2e42 if .git is symlink the version
would gracefully default to no git revision. With those changes an
exception is thrown instead.

This introduces a new function `pathIsGitRepo` that checks if
`commitIdFromGitRepo` fails without error so we don't have to
reimplement this logic again and can fail gracefully.
2020-01-20 00:53:44 +01:00
Robert Hensing
8da81465c1
Merge pull request #75539 from Gabriel439/gabriel/renderOptions
Add `pkgs.lib.encodeGNUCommandLine`
2020-01-14 12:04:05 +01:00
elseym
c9214c394b
lib.commitIdFromGitRepo: support git-worktree
lib.commitIdFromGitRepo now resolves the refs from the
parent repository in case the supplied path is a file
containing the path to said repository. this adds support
for git-worktree and things alike. see gitrepository-layout(5).

this also:
- adds a new boolean function lib.pathIsRegularFile to
  check whether a path is a regular file
- patches lib.revisionWithDefault and
  the revision and versionSuffix attributes in
  config.system.nixos in order to support git-worktrees
2020-01-10 22:29:48 +01:00
Silvan Mosberger
de5f73d434
lib/modules: Recursive disabledModules
With this change, disabledModules applies recursively, meaning if you
have a module "foo.nix" with

    imports = [ ./bar.nix ];

then setting

  disabledModules = [ "foo.nix" ];

will disable both "foo.nix" and "bar.nix", whereas previously only
"foo.nix" would be disabled.

This change along with https://github.com/NixOS/nixpkgs/pull/61570 allows
modules to be fully disabled even when they have some `mkRenamedOption`
imports.
2020-01-09 17:26:05 +01:00
Gabriel Gonzalez
a46679facd
Export toGNUCommandLine
... as suggested by @roberth

Co-Authored-By: Robert Hensing <roberth@users.noreply.github.com>
2020-01-05 14:44:42 -08:00
Silvan Mosberger
5414b4018b
lib/modules: Don't pack submodules specially
This has the beneficial side effect of allowing paths to be used as modules in
types.{submodule,submoduleWith}
2020-01-01 01:13:03 +01:00
Gabriel Gonzalez
8c6a05c8c9 Rename renderOptions to encodeGNUCommandLine
... as suggested by @edolstra
2019-12-13 18:19:24 -08:00
Gabriel Gonzalez
183a99734f Add pkgs.lib.renderOptions
This adds a new utility to intelligently convert Nix records to
command line options to reduce boilerplate for simple use cases and to
also reduce the likelihood of malformed command lines
2019-12-11 16:30:05 -08:00
John Ericson
d0d5136cce Merge remote-tracking branch 'upstream/master' into wrapper-pname-support 2019-11-24 17:25:07 +00:00
John Ericson
84a105254d lib: Add getName to mirror getVersion 2019-11-24 16:24:50 +00:00
Jan Tojnar
10ac558ca1
lib: Add lib.teams
Also add a freedesktop maintainer group as an example.
2019-11-23 00:07:28 +01:00
Profpatsch
8252861507 lib/trivial: add pipe function
`pipe` is a useful operator for creating pipelines of functions.

It works around the usual problem of e.g. string operations becoming
deeply nested functions.

In principle, there are four different ways this function could be
written:

pipe val [ f1 .. fn ]
pipe val [ fn .. f1 ]
compose [ f1 .. fn ] val
compose [ fn .. f1 ] val

The third and fourth form mirror composition of functions, they would
be the same as e.g. `(f1 << f2 << f3 .. << fn) val`.
However, it is not clear which direction the list should have (as one
can see in the second form, which is the most absurd.

In order not to confuse users, we decide for the most “intuitive”
form, which mirrors the way unix pipes work (thus the name `pipe`).
The flow of data goes from left to right.

Co-Authored-By: Silvan Mosberger <infinisil@icloud.com>
2019-10-21 13:19:16 +02:00
Matthieu Coudron
afa0e02d64 lib.kernel: make public
Remove the "version" parameter in order to make it more widely
available.
Starts making some kernel configuration helpers available.
The intent is to be able to better build and check the linux kernel
configuration.
2019-10-01 15:57:14 +09:00
Joachim Fasting
fd3052901c
lib/versions: expose splitVersion 2019-09-26 17:42:42 +02:00
Robert Hensing
fc64cf65ab top-level: Fix dontRecurseIntoAttrs and include in lib
dontRecurseIntoAttrs was a noop (x: x), causing the expression
dontRecurseIntoAttrs (recurseIntoAttrs a) to have the wrong effect.
2019-09-11 13:12:06 +02:00
Robert Hensing
8935bfb4ac lib: Add recurseIntoAttrs
This makes the function available without having to evaluate the
Nixpkgs fix-point, making it available in a more natural way for
code that deals with multiple Nixpkgs invocations.

Its definition is coupled to Nix rather than Nixpkgs, so it will
feel right at home in lib.
2019-09-11 13:12:06 +02:00
danbst
210c57883e and one more place 2019-08-05 14:14:40 +03:00
danbst
69920dafbf lib: introduce foreach = flip map
The main purpose is to bring attention to `flip map`, which improves
code readablity. It is useful when ad-hoc anonymous function
grows two or more lines in `map` application:

```
      map (lcfg:
        let port = lcfg.port;
            portStr = if port != defaultPort then ":${toString port}" else "";
            scheme = if cfg.enableSSL then "https" else "http";
        in "${scheme}://cfg.hostName${portStr}"
      ) (getListen cfg);
```
Compare this to `foreach`-style:
```
      foreach (getListen cfg) (lcfg:
        let port = lcfg.port;
            portStr = if port != defaultPort then ":${toString port}" else "";
            scheme = if cfg.enableSSL then "https" else "http";
        in "${scheme}://cfg.hostName${portStr}"
      );
```
This is similar to Haskell's `for` (http://hackage.haskell.org/package/base-4.12.0.0/docs/Data-Traversable.html#v:for)
2019-07-14 13:29:58 +03:00
Matthew Bauer
a52e317200 check-meta: use system tuple in platforms
Fixes #60345
2019-04-30 12:59:03 -04:00
Corbin
5719f892e1 python: Make .isPyPy flag more accurate.
nix-repl> map (s: s.isPyPy) [ python python3 pypy pypy3 ]
[ false false true true ]
2019-04-09 20:41:08 +02:00
Jan Malakhovski
570aed4b46 lib: add showWarnings 2019-03-08 11:19:18 +02:00
(cdep)illabout
81fa1e392b lib/modules: Change mkAliasOptionModule to use the priority for the alias.
This commit changes the `mkAliasOptionModule` function to make sure that
the priority for the aliased option is propagated to the non-aliased
option.

This also affects the `mkRenamedOptionModule` function in a similar
fashion.

This also removes the `mkAliasOptionModuleWithPriority` function, since
its functionality is now subsumed by `mkAliasOptionModule`.

This change was recommended by @nbp:
https://github.com/NixOS/nixpkgs/pull/53397#discussion_r245487432
2019-01-24 13:02:16 +09:00
Michael Raskin
4d0e1b792f
Merge pull request #50561 from oxij/lib/setPrio
lib: implement `setPrio`
2019-01-18 08:23:31 +00:00
Nicolas B. Pierron
a3beabf327
Merge pull request #53397 from cdepillabout/aliasoptionmodule-set-priority
lib/modules: Add function to create option alias that respects priority
2019-01-14 20:28:28 +01:00
Jörg Thalheim
b75aff7202
Merge pull request #53754 from danbst/lib-fake-hashes
lib: add fake hashes
2019-01-10 17:56:09 +00:00
danbst
68a6b47b8c lib: add shortcuts for fake hashes (fakeSha256, fakeSha512)
Fake hashes can be used as placeholders for all the places, where
Nix expression requires a hash, but we don't yet have one.

This should be more convenient than following:
- echo|sha256sum, copy into clipboard, go to editor, paste into previously
  edited place
- search nixpkgs for a random package, copy it's hash to cliboard, go to
  editor, paste into previously edited place

Nix can add support for these fake hashes. In that case printed error should contain
only 1 hash, so no more problem "which of two hashes from error should I use?"

Idea by irc:Synthetica
2019-01-10 19:27:35 +02:00
(cdep)illabout
b81b3ad1b0
lib/modules: Add a function to create an option alias that respects the priority
This commit adds a function `mkAliasOptionModuleWithPriority`.  This
function will make an alias to an existing option and copy over the
priority.

This functionality is needed for PRs like #53041.  In that case
`nixos-generate-config` added an option to `hardware-configuration.nix`
with `mkDefault`.  That option was then changed and an alias created for
the old name.

The end user should be able to set the non-alias option in their
`configuration.nix` and have everything work correctly.  Without this
function, the priority for the option won't be copied over correctly
and the end-user will get a message saying they have the same option
set to two different values.
2019-01-04 18:35:10 +09:00
Frederik Rietdijk
070290bda7 Merge master into staging-next 2018-12-31 12:00:36 +01:00
Frederik Rietdijk
c6e043d57c Remove composableDerivation, closes #18763 2018-12-30 12:33:45 +00:00
volth
fed7914539
Merge branch 'staging' into make-perl-pathd 2018-12-18 17:13:27 +00:00
volth
bb9557eb7c lib.makePerlPath -> perlPackages.makePerlPath 2018-12-15 03:50:31 +00:00
Alyssa Ross
67b1265fb3
bundlerEnv: ensure dependencies always included
Suppose I have a Gemfile like this:

    source "https://rubygems.org"
    gem "actioncable"
    gem "websocket-driver", group: :test

The gemset.nix generated by Bundix 2.4.1 will set ActionCable's groups
to [ "default" ], and websocket-driver's to [ "test" ]. This means that
the generated bundlerEnv wouldn't include websocket-driver unless the
test group was included, even though it's required by the default group.

This is arguably a bug in Bundix (websocket-driver's groups should
probably be [ "default" "test" ] or just [ "default" ]), but there's no
reason bundlerEnv should omit dependencies even given such an input --
it won't necessarily come from Bundix, and it would be good for
bundlerEnv to do the right thing.

To fix this, filterGemset is now a recursive function, that adds
dependencies of gems in the group to the filtered gemset until it
stabilises on the gems that match the required groups, and all of their
recursive dependencies.
2018-12-11 21:26:07 +00:00
Jan Malakhovski
1b3629ef34 lib: implement setPrio
For when `hiPrio` and `lowPrio` are not enough.
2018-11-22 08:59:48 +00:00
Profpatsch
efdf618330 lib: move assertMsg and assertOneOf to their own library file
Since the `assertOneOf` uses `lib.generators`, they are not really trivial
anymore and should go into their own library file.
2018-09-06 18:14:27 +02:00
Profpatsch
320cdecd16 lib/trivial: add assertOneOf 2018-09-06 18:14:27 +02:00
Profpatsch
0e2aa97f3a lib/trivial: add assertMsg 2018-09-06 18:14:27 +02:00
Aaron Andersen
74d446176e as requested:
- moved function into strings.nix
- renamed function from makePerl5Lib
- removed duplicates entries in the resulting value
- rewrote the function from scratch after learning a few things (much cleaner now)
2018-08-21 20:11:28 +02:00
volth
3c2bbe217c lib: bitAnd, bitOr, bitXor (bitsize-agnostic fallback function) (#41491)
* lib: bitAnd, bitOr, bitXor

* lib: test for bitAnd, bitOr, bitXor

* lib: bitsize-agnostic zipIntBits

* lib: bitNot

* lib: bitNot
2018-06-10 21:25:48 +02:00
volth
4e85c4ff27 lib: add groupBy (#38612) 2018-06-10 19:31:09 +02:00
Profpatsch
f98272d6e2 Revert "lib: bitAnd, bitOr, bitXor" 2018-06-05 18:45:20 +02:00
volth
0addac3b0a lib: bitAnd, bitOr, bitXor 2018-06-01 21:36:31 +00:00
John Ericson
9e9cdd7027 lib: Add more configure flag helpers
Add with/without to match enable/disable, and add
`--{enable,with}-key=value` versions of both.
2018-05-11 17:43:35 +02:00
Maximilian Bosch
9274ea3903
treewide: rename version attributes
As suggested in https://github.com/NixOS/nixpkgs/pull/39416#discussion_r183845745
the versioning attributes in `lib` should be consistent to
`nixos/version` which implicates the following changes:

* `lib.trivial.version` -> `lib.trivial.release`
* `lib.trivial.suffix` -> `lib.trivial.versionSuffix`
* `lib.nixpkgsVersion` -> `lib.version`

As `lib.nixpkgsVersion` is referenced several times in `NixOS/nixpkgs`,
`NixOS/nix` and probably several user's setups. As the rename will cause
a notable impact it's better to keep `lib.nixpkgsVersion` as alias with
a warning yielded by `builtins.trace`.
2018-04-28 14:23:53 +02:00
Profpatsch
a455637d28 lib/debug: remove the deprecated strict function
The grace period was long enough.
2018-04-27 18:59:39 +02:00
Profpatsch
a5f6cdfd7e lib/debug: add traceValFn, traceValSeqFn, traceValSeqNFn
Being able to modify the value on-the-fly before printing is very useful in
practice.
2018-04-27 18:59:39 +02:00
Jörg Thalheim
0fe11dbedd
Merge pull request #38611 from volth/nat-sort
lib: add naturalSort
2018-04-08 22:44:15 +01:00
volth
25c2fd80b1 lib: add naturalSort 2018-04-08 13:18:13 +00:00
Silvan Mosberger
e1dee4efcb lib: make extensible
This allows the lib fixed point to be extended with

  myLib = lib.extend (self: super: {
    foo = "foo";
  })

With this it's possible to have the new modified lib attrset available to all
modules when using evalModules

  myLib.evalModules {
    modules = [ ({ lib, ... }: {
      options.bar = lib.mkOption {
	default = lib.foo;
      };
    }) ];
  }

  => { config = { bar = "foo"; ... }; options = ...; }
2018-04-07 13:21:49 -04:00
John Ericson
2fa2197a96
Merge pull request #34444 from obsidiansystems/meta-check
lib: Fix #30902
2018-03-18 13:51:03 -04:00
John Ericson
c26252af3e lib, stdenv: Check meta.platforms against host platform and be open world
First, we need check against the host platform, not the build platform.
That's simple enough.

Second, we move away from exahustive finite case analysis (i.e.
exhaustively listing all platforms the package builds on). That only
work in a closed-world setting, where we know all platforms we might
build one. But with cross compilation, we may be building for arbitrary
platforms, So we need fancier filters. This is the closed world to open
world change.

The solution is instead of having a list of systems (strings in the form
"foo-bar"), we have a list of of systems or "patterns", i.e. attributes
that partially match the output of the parsers in `lib.systems.parse`.
The "check meta" logic treats the systems strings as an exact whitelist
just as before, but treats the patterns as a fuzzy whitelist,
intersecting the actual `hostPlatform` with the pattern and then
checking for equality. (This is done using `matchAttrs`).

The default convenience lists for `meta.platforms` are now changed to be
lists of patterns (usually a single pattern) in
`lib/systems/for-meta.nix` for maximum flexibility under this new
system.

Fixes #30902
2018-03-15 00:44:34 -04:00
Jan Malakhovski
610b5b8045 rename lib/maintainers-list.nix into maintainers/maintainer-list.nix
Many commits unrelated to `lib` touch that file, this will make `git log ./lib` much saner.

This is what I meant in https://github.com/NixOS/nixpkgs/pull/36119#issuecomment-370184101.
2018-03-06 14:15:21 +00:00
Jörg Thalheim
73774ef8f9
Merge pull request #36168 from ryantm/majorminor
a single version attribute for expressions previously using "majorVersion"
2018-03-04 20:06:48 +00:00