Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Demo, RFC] Gentoo-like use-flags #56110

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions lib/customisation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ rec {
}
else ff;

/* This function applies use-flags to packages of the following form

{ stdenv, ... }:
{ useFlag ? true, ... }:
stdenv.mkDerivation { };

while keeping the rest of makeOverridable mechanics intact.
*/
makeOverridableWithUseFlags = useFlags: f: origArgs:
let
ff = f origArgs;
use = builtins.intersectAttrs (lib.functionArgs ff) useFlags;
in if lib.isFunction ff
then makeOverridable (origArgs: f origArgs use) origArgs
else makeOverridable f origArgs;

/* Call the package function in the file `fn' with the required
arguments automatically. The function is called with the
Expand All @@ -105,25 +120,27 @@ rec {
enableX11 = true;
};
*/
callPackageWith = autoArgs: fn: args:
callPackageWith' = makeOverridableFun: autoArgs: fn: args:
let
f = if lib.isFunction fn then fn else import fn;
auto = builtins.intersectAttrs (lib.functionArgs f) autoArgs;
in makeOverridable f (auto // args);
in makeOverridableFun f (auto // args);

callPackageWith = callPackageWith' makeOverridable;

/* Like callPackage, but for a function that returns an attribute
set of derivations. The override function is added to the
individual attributes. */
callPackagesWith = autoArgs: fn: args:
callPackagesWith' = makeOverridableFun: autoArgs: fn: args:
let
f = if lib.isFunction fn then fn else import fn;
auto = builtins.intersectAttrs (lib.functionArgs f) autoArgs;
origArgs = auto // args;
pkgs = f origArgs;
mkAttrOverridable = name: _: makeOverridable (newArgs: (f newArgs).${name}) origArgs;
mkAttrOverridable = name: _: makeOverridableFun (newArgs: (f newArgs).${name}) origArgs;
in lib.mapAttrs mkAttrOverridable pkgs;

callPackagesWith = callPackagesWith' makeOverridable;

/* Add attributes to each output of a derivation without changing
the derivation itself and check a given condition when evaluating. */
Expand Down
7 changes: 5 additions & 2 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ let
toInt readPathsFromFile fileContents;
inherit (stringsWithDeps) textClosureList textClosureMap
noDepEntry fullDepEntry packEntry stringAfter;
inherit (customisation) overrideDerivation makeOverridable
callPackageWith callPackagesWith extendDerivation hydraJob
inherit (customisation) overrideDerivation
makeOverridable makeOverridableWithUseFlags
callPackageWith' callPackageWith
callPackagesWith' callPackagesWith
extendDerivation hydraJob
makeScope;
inherit (meta) addMetaAttrs dontDistribute setName updateName
appendToName mapDerivationAttrset setPrio lowPrio lowPrioSet hiPrio
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/editors/jetbrains/common.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ stdenv, makeDesktopItem, makeWrapper, patchelf, p7zip
, coreutils, gnugrep, which, git, unzip, libsecret, libnotify
}:
}: {}:

{ name, product, version, src, wmClass, jdk, meta }:

Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/editors/neovim/wrapper.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
, nodePackages
, pythonPackages
, python3Packages
}:
}: {}:
with stdenv.lib;

neovim:
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/graphics/sane/config.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv }:
{ stdenv }: {}:

{ paths }:

Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/kde/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ let
sname = args.sname or name;
inherit (srcs."${sname}") src version;
mkDerivation =
libsForQt5.callPackage ({ mkDerivation }: mkDerivation) {};
libsForQt5.callPackage ({ mkDerivation }: {}: mkDerivation) {};
in
mkDerivation (args // {
name = "${name}-${version}";
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/networking/browsers/chromium/common.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
, pulseSupport ? false, libpulseaudio ? null

, upstream-info
}:
}: {}:

buildFun:

Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/networking/browsers/firefox/wrapper.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
, browserpass, chrome-gnome-shell, uget-integrator, plasma-browser-integration, bukubrow
, udev
, kerberos
}:
}: {}:

## configurability of the wrapper itself

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, bitlbee }:
{ stdenv, bitlbee }: {}:

with stdenv.lib;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{ stdenv, jq }: { src, nodejs, sha256 }:
{ stdenv, jq }: {}:

{ src, nodejs, sha256 }:

# Only npm >= 5.4.2 is deterministic, see:
# https://github.com/npm/npm/issues/17979#issuecomment-332701215
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/networking/irc/weechat/wrapper.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ stdenv, lib, runCommand, writeScriptBin, buildEnv
, pythonPackages, perlPackages
}:
}: {}:

weechat:

Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/science/electronics/bitscope/common.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
, pango
, stdenv
, xorg
}:
}: {}:

{ src, toolName, version, ... } @ attrs:
let
Expand Down
8 changes: 5 additions & 3 deletions pkgs/applications/video/mpv/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
, dvdnavSupport ? stdenv.isLinux, libdvdnav ? null
, dvdreadSupport ? stdenv.isLinux, libdvdread ? null
, libpngSupport ? true, libpng ? null
, pulseSupport ? config.pulseaudio or stdenv.isLinux, libpulseaudio ? null
, libpulseaudio ? null
, rubberbandSupport ? stdenv.isLinux, rubberband ? null
, screenSaverSupport ? true, libXScrnSaver ? null
, sdl2Support ? true, SDL2 ? null
Expand All @@ -48,6 +48,8 @@
, jackaudioSupport ? false, libjack2 ? null
, openalSupport ? false, openalSoft ? null
, vapoursynthSupport ? false, vapoursynth ? null
}: {
pulseaudio ? stdenv.isLinux
}:

with stdenv.lib;
Expand All @@ -68,7 +70,7 @@ assert dvdreadSupport -> available libdvdread;
assert jackaudioSupport -> available libjack2;
assert libpngSupport -> available libpng;
assert openalSupport -> available openalSoft;
assert pulseSupport -> available libpulseaudio;
assert pulseaudio -> available libpulseaudio;
assert rubberbandSupport -> available rubberband;
assert screenSaverSupport -> available libXScrnSaver;
assert sdl2Support -> available SDL2;
Expand Down Expand Up @@ -153,7 +155,7 @@ in stdenv.mkDerivation rec {
++ optional jackaudioSupport libjack2
++ optional libpngSupport libpng
++ optional openalSupport openalSoft
++ optional pulseSupport libpulseaudio
++ optional pulseaudio libpulseaudio
++ optional rubberbandSupport rubberband
++ optional screenSaverSupport libXScrnSaver
++ optional sdl2Support SDL2
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/build-bazel-package/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, bazel, cacert, enableNixHacks ? true }:
{ stdenv, bazel, cacert, enableNixHacks ? true }: {}:

args@{ name, bazelFlags ? [], bazelTarget, buildAttrs, fetchAttrs, ... }:

Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/build-dotnet-package/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, lib, makeWrapper, pkgconfig, mono, dotnetbuildhelpers }:
{ stdenv, lib, makeWrapper, pkgconfig, mono, dotnetbuildhelpers }: {}:

attrsOrig @
{ baseName
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/build-fhs-userenv/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ callPackage, runCommand, writeScript, stdenv, coreutils }:
{ callPackage, runCommand, writeScript, stdenv, coreutils }: {}:

let buildFHSEnv = callPackage ./env.nix { }; in

Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/build-fhs-userenv/env.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, buildEnv, writeText, pkgs, pkgsi686Linux }:
{ stdenv, buildEnv, writeText, pkgs, pkgsi686Linux }: {}:

{ name, profile ? ""
, targetPkgs ? pkgs: [], multiPkgs ? pkgs: []
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/build-maven.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, maven, runCommand, writeText, fetchurl, lib, requireFile }:
{ stdenv, maven, runCommand, writeText, fetchurl, lib, requireFile }: {}:
/* Takes an info file generated by mvn2nix
* (https://github.com/NixOS/mvn2nix-maven-plugin) and builds the maven
* project with it.
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/buildenv/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# a fork of the buildEnv in the Nix distribution. Most changes should
# eventually be merged back into the Nix distribution.

{ buildPackages, runCommand, lib }:
{ buildPackages, runCommand, lib }: {}:

lib.makeOverridable
({ name
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/closure-info.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# "nix-store --load-db" and "nix-store --register-validity
# --hash-given".

{ stdenv, coreutils, jq, buildPackages }:
{ stdenv, coreutils, jq, buildPackages }: {}:

{ rootPaths }:

Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/dhall-to-nix.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Note that this uses "import from derivation", meaning that Nix will perform
a build during the evaluation phase if you use this `dhallToNix` utility
*/
{ stdenv, dhall-nix }:
{ stdenv, dhall-nix }: {}:

let
dhallToNix = code :
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/emacs/melpa.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# builder for Emacs packages built for packages.el
# using MELPA package-build.el

{ lib, stdenv, fetchFromGitHub, emacs, texinfo }:
{ lib, stdenv, fetchFromGitHub, emacs, texinfo }: {}:

with lib;

Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/fetchbitbucket/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ fetchzip }:
{ fetchzip }: {}:

{ owner, repo, rev, name ? "source"
, ... # For hash agility
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/fetchbower/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenvNoCC, lib, bower2nix, cacert }:
{ stdenvNoCC, lib, bower2nix, cacert }: {}:
let
bowerVersion = version:
let
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/fetchbzr/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenvNoCC, bazaar }:
{ stdenvNoCC, bazaar }: {}:
{ url, rev, sha256 }:

stdenvNoCC.mkDerivation {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/fetchcvs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# tag="<tagname>" (get version by tag name)
# If you don't specify neither one date="NOW" will be used (get latest)

{stdenvNoCC, cvs, openssh}:
{stdenvNoCC, cvs, openssh}: {}:

{cvsRoot, module, tag ? null, date ? null, sha256}:

Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/fetchdarcs/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{stdenvNoCC, darcs, cacert}:
{stdenvNoCC, darcs, cacert}: {}:

{url, rev ? null, context ? null, md5 ? "", sha256 ? ""}:

Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/fetchdocker/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, lib, coreutils, bash, gnutar, writeText }:
{ stdenv, lib, coreutils, bash, gnutar, writeText }: {}:
let
stripScheme =
builtins.replaceStrings [ "https://" "http://" ] [ "" "" ];
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/fetchdocker/fetchDockerConfig.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pkgargs@{ stdenv, lib, haskellPackages, writeText, gawk }:
pkgargs@{ stdenv, lib, haskellPackages, writeText, gawk }: {}:
let
generic-fetcher =
import ./generic-fetcher.nix pkgargs;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/fetchdocker/fetchDockerLayer.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pkgargs@{ stdenv, lib, haskellPackages, writeText, gawk }:
pkgargs@{ stdenv, lib, haskellPackages, writeText, gawk }: {}:
let
generic-fetcher =
import ./generic-fetcher.nix pkgargs;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/fetchfossil/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{stdenv, fossil}:
{stdenv, fossil}: {}:

{name ? null, url, rev, sha256}:

Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/fetchgit/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{stdenvNoCC, git, cacert}: let
{stdenvNoCC, git, cacert}: {}: let
urlToName = url: rev: let
inherit (stdenvNoCC.lib) removeSuffix splitString last;
base = last (splitString ":" (baseNameOf (removeSuffix "/" url)));
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/fetchgit/private.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ fetchgit, runCommand, makeWrapper, openssh }: args: derivation ((fetchgit args).drvAttrs // {
{ fetchgit, runCommand, makeWrapper, openssh }: {}: args: derivation ((fetchgit args).drvAttrs // {
SSH_AUTH_SOCK = if (builtins.tryEval <ssh-auth-sock>).success
then builtins.toString <ssh-auth-sock>
else null;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/fetchgithub/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ lib, fetchgit, fetchzip }:
{ lib, fetchgit, fetchzip }: {}:

{ owner, repo, rev, name ? "source"
, fetchSubmodules ? false, private ? false
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/fetchgitlab/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ fetchzip, lib }:
{ fetchzip, lib }: {}:

# gitlab example
{ owner, repo, rev, domain ? "gitlab.com", name ? "source", group ? null
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/fetchgitlocal/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ runCommand, git }: src:
{ runCommand, git }: {}: src:

let
srcStr = toString src;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/fetchgx/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenvNoCC, gx, gx-go, go, cacert }:
{ stdenvNoCC, gx, gx-go, go, cacert }: {}:

{ name, src, sha256 }:

Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/fetchhg/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenvNoCC, mercurial }:
{ stdenvNoCC, mercurial }: {}:
{ name ? null
, url
, rev ? null
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/fetchipfs/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ stdenv
, curl
}:
}: {}:

{ ipfs
, url ? ""
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/fetchmavenartifact/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Adaptation of the MIT-licensed work on `sbt2nix` done by Charles O'Farrell

{ fetchurl, stdenv }:
{ fetchurl, stdenv }: {}:
let
defaultRepos = [
http://central.maven.org/maven2
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/fetchmtn/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# You can specify some extra mirrors and a cache DB via options
{stdenvNoCC, monotone, defaultDBMirrors ? [], cacheDB ? "./mtn-checkout.db"}:
{stdenvNoCC, monotone, defaultDBMirrors ? [], cacheDB ? "./mtn-checkout.db"}: {}:
# dbs is a list of strings
# each is an url for sync

Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/fetchnuget/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ fetchurl, buildDotnetPackage, unzip }:
{ fetchurl, buildDotnetPackage, unzip }: {}:

attrs @
{ baseName
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/fetchpatch/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# often change with updating of git or cgit.
# stripLen acts as the -p parameter when applying a patch.

{ lib, fetchurl, buildPackages }:
{ lib, fetchurl, buildPackages }: {}:
{ stripLen ? 0, extraPrefix ? null, excludes ? [], includes ? [], revert ? false, ... }@args:

fetchurl ({
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/fetchrepoorcz/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ fetchzip }:
{ fetchzip }: {}:

# gitweb example, snapshot support is optional in gitweb
{ repo, rev, name ? "source"
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/fetchrepoproject/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenvNoCC, gitRepo, cacert, copyPathsToStore }:
{ stdenvNoCC, gitRepo, cacert, copyPathsToStore }: {}:

{ name, manifest, rev ? "HEAD", sha256
# Optional parameters:
Expand Down
Loading