Commit Graph

55 Commits

Author SHA1 Message Date
Vladimír Čunát
b63f684b3d
lib.callPackages(With): guard against a repeated mistake
For example see the parent commit.
2020-03-12 09:40:15 +01:00
Silvan Mosberger
1230fc8674
Merge pull request #67809 from Infinisil/propagate-override-args
lib.makeOverridable: Propagate function arguments
2019-10-22 14:37:40 +02:00
Silvan Mosberger
a4896cb4aa
lib/makeOverridable: Refactor
- Rename ff to result because that's what it is
- Better indentation
- Less parens
- Comment what overrideWith does
2019-09-05 00:57:55 +02:00
Silvan Mosberger
23e72eff41
lib/makeOverridable: Remove unimplemented overrideDerivation for functions
- Apparently nobody ever needed this
- We already have enough ways to override things
- Using overrideDerivation is discouraged
2019-09-05 00:57:22 +02:00
Silvan Mosberger
c638dac226
lib/makeOverridable: Propagate function args of the callPackage'd function
This allows querying function arguments of things like fetchFromGitHub:

  nix-repl> lib.functionArgs pkgs.fetchFromGitHub
  { fetchSubmodules = true; githubBase = true; ... }
2019-09-05 00:57:04 +02:00
Silvan Mosberger
d54bdf5504
lib/makeOverridable: Propagate function arguments to override functions
This allows querying the arguments you can .override:

  nix-repl> lib.functionArgs pkgs.hello.override
  { fetchurl = false; stdenv = false; }
2019-09-05 00:56:39 +02:00
Silvan Mosberger
e140d709c4
lib/makeOverridable: Abstract result overriding 2019-09-05 00:56:11 +02:00
Silvan Mosberger
a75080f58c
lib/makeOverridable: Deduplicate override definition
And call it overrideArgs in the let binding because that's what it does
2019-09-05 00:54:03 +02:00
Gabriel Féron
4b5afe54de
Fix typo in customisation.nix 2019-09-02 13:39:40 +02:00
Jan Malakhovski
51687d9a7f lib: tiny cleanup 2019-02-03 15:30:15 +00:00
Bas van Dijk
fceab3ec62 lib: fix wording of the overrideScope warning 2018-10-11 17:23:47 +02:00
John Ericson
b9dce11712 lib: Make overrideScope' which takes arguments in the conventional order
The `overrideScope` bound by `makeScope` (via special `callPackage`)
took an override in the form `super: self { … }`. But this is
dangerously close to the `self: super { … }` form used by *everything*
else, even other definitions of `overrideScope`! Since that
implementation did not even share any code either until I changed it
recently in 3cf43547f4, this inconsistency
is almost certainly an oversight and not intentional.

Unfortunately, just as the inconstency is hard to debug if one just
assumes the conventional order, any sudden fix would break existing
overrides in the same hard-to-debug way. So instead of changing the
definition a new `overrideScope'` with the conventional order is added,
and old `overrideScope` deprecated with a warning saying to use
`overrideScope'` instead. That will hopefully get people to stop using
`overrideScope`, freeing our hand to change or remove it in the future.
2018-09-24 17:50:11 -04:00
John Ericson
3cf43547f4
lib: Use lib.fixed-points.extends to avoid repetition
Another attempt after my sloppy 48ccdf322d.

@Infinisil, thanks again, reverted in 4794aa5de2 and explained my mistakes in 48ccdf322d (commitcomment-29678643). I start with their work and provide this proof of this commit's correctness:
```nix
(lib.fixedPoints.extends (lib.flip g) f) # now
((f: rattrs: self: let super = rattrs self; in super // f self super) (lib.flip g) f) # inline extends
(self: let super = f self; in super // (lib.flip g) self super) # beta reduce
(self: let super = f self; in super // g super self)  # beta reduce
(self_: let super = f self_; in super // g super self_)  # alpha rename
(self_: let super = f self_; in super // g super self_) # original, same
```

Eventually we might harmonize `overrideScope`'s `g` parameter with the general pattern, but I leave that breaking change as a separate step. Best not to refactor and break at once, and at least the abstractions make the oddity clearer.
2018-08-20 13:09:15 -04:00
volth
6d2857a311 [bot] treewide: remove unused 'inherit' in let blocks 2018-07-20 19:38:19 +00:00
Silvan Mosberger
4794aa5de2
Revert "lib: Use lib.fixed-points.extends to avoid repetition"
This reverts commit 48ccdf322d.
2018-07-12 02:04:06 +02:00
John Ericson
48ccdf322d lib: Use lib.fixed-points.extends to avoid repetition 2018-07-09 12:33:43 -04:00
Vladimír Čunát
7b2cf5b12e
lib.addPassthru: removed as scheduled 2018-03-03 17:57:38 +01:00
Shea Levy
943592f698
Add setFunctionArgs lib function.
Among other things, this will allow *2nix tools to output plain data
while still being composable with the traditional
callPackage/.override interfaces.
2018-01-31 14:02:19 -05:00
Orivej Desh
ce1d740fa6 addPassthru: fix argument order
addPassthru became unused in #33057, but its signature was changed at the same
time.  This commit restores the original signature and updates the warning and
the changelog.
2018-01-24 23:06:12 +00:00
Jan Malakhovski
41df994001 lib: deprecate addPassthru 2018-01-14 19:54:47 +00:00
Jan Malakhovski
85cd22cf7d treewide: replace addPassthru 2018-01-14 19:53:57 +00:00
Jan Malakhovski
8606dd8556 lib: change the order of arguments of addPassthru 2018-01-14 13:24:30 +00:00
Jan Malakhovski
b1ca8517ee lib: generalize addPassthru to extendDerivation 2018-01-03 12:20:24 +00:00
Shea Levy
1a1ad1a17d Revert "Merge branch 'improved-make-overridable' of git://github.com/ElvishJerricco/nixpkgs"
This reverts commit c3af1210b4, reversing
changes made to 49f175cd0c.
2017-09-29 09:11:26 -04:00
Shea Levy
d96da5af87 Revert "Avoid polluting lib namespace unncessarily"
Reverting #27319

This reverts commit 01a3f0b8aa.
2017-09-29 09:09:53 -04:00
Shea Levy
01a3f0b8aa Avoid polluting lib namespace unncessarily 2017-09-28 18:51:20 -04:00
Shea Levy
c3af1210b4 Merge branch 'improved-make-overridable' of git://github.com/ElvishJerricco/nixpkgs 2017-09-28 18:10:50 -04:00
Graham Christensen
152c63c9ff
Convert libs to a fixed-point
This does break the API of being able to import any lib file and get
its libs, however I'm not sure people did this.

I made this while exploring being able to swap out docFn with a stub
in #2305, to avoid functor performance problems. I don't know if that
is going to move forward (or if it is a problem or not,) but after
doing all this work figured I'd put it up anyway :)

Two notable advantages to this approach:

1. when a lib inherits another lib's functions, it doesn't
   automatically get put in to the scope of lib
2. when a lib implements a new obscure functions, it doesn't
   automatically get put in to the scope of lib

Using the test script (later in this commit) I got the following diff
on the API:

  + diff master fixed-lib
  11764a11765,11766
  > .types.defaultFunctor
  > .types.defaultTypeMerge
  11774a11777,11778
  > .types.isOptionType
  > .types.isType
  11781a11786
  > .types.mkOptionType
  11788a11794
  > .types.setType
  11795a11802
  > .types.types

This means that this commit _adds_ to the API, however I can't find a
way to fix these last remaining discrepancies. At least none are
_removed_.

Test script (run with nix-repl in the PATH):

  #!/bin/sh

  set -eux

  repl() {
      suff=${1:-}
      echo "(import ./lib)$suff" \
          | nix-repl 2>&1
  }

  attrs_to_check() {
      repl "${1:-}" \
          | tr ';'  $'\n' \
          | grep "\.\.\." \
          | cut -d' ' -f2 \
          | sed -e "s/^/${1:-}./" \
          | sort
  }

  summ() {
      repl "${1:-}" \
          | tr ' ' $'\n' \
          | sort \
          | uniq
  }

  deep_summ() {
      suff="${1:-}"
      depth="${2:-4}"
      depth=$((depth - 1))
      summ "$suff"

      for attr in $(attrs_to_check "$suff" | grep -v "types.types"); do
          if [ $depth -eq 0 ]; then
              summ "$attr" | sed -e "s/^/$attr./"
          else
              deep_summ "$attr" "$depth" | sed -e "s/^/$attr./"
          fi
      done
  }

  (
      cd nixpkgs

      #git add .
      #git commit -m "Auto-commit, sorry" || true
      git checkout fixed-lib
      deep_summ > ../fixed-lib
      git checkout master
      deep_summ > ../master
  )

  if diff master fixed-lib; then
      echo "SHALLOW MATCH!"
  fi

  (
      cd nixpkgs
      git checkout fixed-lib
      repl .types
  )
2017-09-16 21:36:43 -04:00
Will Fancher
05f9db601a Added self views of the interface in makeExtensibleWithInterface
Fixing the `overrideScope` in `haskellpackages`.
2017-07-14 06:43:33 -04:00
Will Fancher
8b764960e9 Added overrideScope for callPackageWith
Consequently removing several ad-hoc definitions of the same concept.
2017-07-13 14:56:13 -04:00
Will Fancher
5a5f8613e0 Re-added overrideAttrs in makeOverridable 2017-07-12 18:38:22 -04:00
Will Fancher
af479c182f Added callPackageWithSelfWith and callPackageWithSelf 2017-07-12 18:35:23 -04:00
Will Fancher
927c4f83d8 Improved makeOverridable with extend and overridePackage 2017-07-12 18:35:23 -04:00
Gleb Peregud
0123200dee stdenv: add stawman docs for makeOverridable
Also fix a typo in docs in haskell-modules.
2017-06-24 12:47:57 +02:00
Vladimír Čunát
57174178c9
lib.makeScope: sync comment after rename in #25285 2017-04-30 15:56:29 +02:00
Thomas Tuegel
901a778c77
makeScope: prevent name collision with makeOverridable 2017-04-28 05:54:30 -05:00
Tom Saeger
5989515b94 lib: trivial spelling fixes 2017-04-19 19:37:55 -05:00
Thomas Tuegel
b39e491eb5
lib.makeScope: Save package set function 2017-02-27 11:49:43 -06:00
danbst
9d55479e07 add .overrideDerivation and .overrideAttrs to packages created with callPackages/callPackagesWith
nix/nixUnstable, tomcatN and postgresqlNN use `callPackages` pattern, they have .override
attribute, but lack .overrideDerivation and recent .overrideAttrs.
Packages created with `callPackage` have all of those. Because .overrideDerivation function
is used in public, without this we can break code when refactoring callPackage -> callPackages.
2017-02-12 14:00:28 +00:00
Eelco Dolstra
9d6a55aefd
~/.nixpkgs -> ~/.config/nixpkgs
The former is still respected as a fallback for config.nix for
backwards compatibility (but not for overlays because they're a new
feature).
2017-02-01 16:07:55 +01:00
Aneesh Agrawal
39b64b52ed mkDerivation: add overrideAttrs function
This is similar to `overrideDerivation`, but overrides the arguments to
`mkDerivation` instead of the underlying `derivation` call.

Also update `makeOverridable` so that uses of `overrideAttrs` can be
followed by `override` and `overrideDerivation`, i.e. they can be
mix-and-matched.
2016-10-02 11:08:34 -04:00
Vladimír Čunát
ab8a691d05 nixos systemPackages: rework default outputs
- Now `pkg.outputUnspecified = true` but this attribute is missing in
  every output, so we can recognize whether the user chose or not.
  If (s)he didn't choose, we put `pkg.bin or pkg.out or pkg` into
  `systemPackages`.
- `outputsToLink` is replaced by `extraOutputsToLink`.
  We add extra outputs *regardless* of whether the user chose anything.
  It's mainly meant for outputs with docs and debug symbols.
- Note that as a result, some libraries will disappear from system path.
2016-01-28 11:24:18 +01:00
Thomas Tuegel
f9e5745efa lib: add makeScope 2015-09-27 09:45:23 -05:00
Eelco Dolstra
b89b6b2a7b Add function callPackagesWith
This is like callPackageWith, except that it expects the supplied
function to return a *set* of packages. It will then make the
individual packages overridable.
2015-07-28 21:42:25 +02:00
Eelco Dolstra
314e8e49ec Remove deepOverride
It's unused, and also a bad idea: because it recursively recomputes
every function argument and there is no sharing, you can get an
exponential (?) blowup in evaluation time. For example, evaluating
‘linuxPackages.kernel’ takes 0.09s and ~13 MiB, but evaluating
‘linuxPackages.kernel.deepOverride {}’ takes 3.6s and ~305 MiB.
2015-07-28 21:42:25 +02:00
Eelco Dolstra
3096d03435 Revert "Refactor mkFlag / shouldUsePkg into the nixpkgs libraries"
This reverts commit 25a148fa19.
2015-06-04 14:54:48 +02:00
William A. Kennington III
25a148fa19 Refactor mkFlag / shouldUsePkg into the nixpkgs libraries 2015-05-22 13:26:55 -07:00
Jan Malakhovski
5990cce95f lib: cleanup a little bit, add traceIf 2015-03-26 12:43:42 +00:00
Eelco Dolstra
0461f35894 Rename scrubDrv -> hydraJob and make it more effective
It now strictly evaluates all remaining attributes, preventing
unevaluated thunks that cannot be garbage-collected. It's also applied
to all jobs in Nixpkgs' release.nix.

This reduces hydra-eval-jobs' memory consumption on the 14.12
release-combined jobset from 5.1 GB to 2.0 GB.
2015-03-20 19:46:18 +01:00
Shea Levy
8921a8f53b Revert "Revert "mkOverridable: Use functors to allow overridable functions""
Original commit was reverted due to using features from a newer nix than
hydra had, hydra has since been updated

This reverts commit 07e726c85c.
2015-01-13 08:39:54 -05:00