Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
128 changes: 128 additions & 0 deletions pkgs/top-level/options.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{lib, stdenv}:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use hostPlatform instead?

@matthewbauer matthewbauer Apr 27, 2018

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah definitely! targetPlatform might actually make more sense though. In fact, one of the big reasons for doing this is getting rid of a lot of the stdenv.isDarwin and stdenv.isLinux that is spread accross Nixpkgs. Quite a few should be easily replaced with withApple, withSystemd and withAlsa.


with lib;

# Define some user flags. Note that none of these should be mutually
# exclusive. For instance enabling X11 should not imply that Wayland
# is disabled.

{

lang = mkOption {
default = "en";
type = types.string;
description = ''

The target language to compile packages with support for.

'';
};

withX11 = mkOption {
default = stdenv.isLinux; # also BSDs?
type = types.bool;
description = ''

Whether to compile packages with support for the X Window System.

'';
};

withWayland = mkOption {
default = stdenv.isLinux; # also BSDs?
type = types.bool;
description = ''

Whether to compile packages with support for the Wayland window system.

'';
};

withAlsa = mkOption {
default = stdenv.isLinux;
type = types.bool;
description = ''

Whether to compile packages with support for the ALSA sound system.

'';
};

withPulseAudio = mkOption {
default = stdenv.isLinux;
type = types.bool;
description = ''

Whether to compile packages with support for the PulseAudio sound system.

'';
};

withJack = mkOption {
default = false;
type = types.bool;
description = ''

Whether to compile packages with support for the JACK sound system

'';
};

withQt = mkOption {
default = true;
type = types.bool;
description = ''

Whether to compile packages with support for the Qt graphical toolkit

'';
};

withGTK = mkOption {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably be withGtk since other initialisms also use this style.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do that although I'm not quite sure if that's better. GTK is usually capitilized.

@jtojnar jtojnar Apr 27, 2018

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So is ALSA. See this question discussing the use of acronyms in identifiers. I do not really care which style we choose but the inconsistency is jarring.

@Anton-Latukha Anton-Latukha Apr 27, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. That only first letter capitalizes also bothered me in camelCase.
But it is a trade-off for thisHTTPSUIFFMPEGNames being readable.

Since I have a love towards descriptive names, I adopted this thisHttpsUiFfmpegNames.

https://github.com/NixOS/nixpkgs/search?utf8=%E2%9C%93&q=withgtk+OR+usegtk+OR+withqt+OR+useqt+OR+withalsa+OR+usealsa&type=

default = false;
type = types.bool;
description = ''

Whether to compile packages with support for the GTK graphical toolkit

'';
};

withApple = mkOption {
default = stdenv.isDarwin;
type = types.bool;
description = ''

Whether to compile packages with Apple's proprietary frameworks.

Note that this only supports macOS currently.

'';
};

withSystemd = mkOption {
default = stdenv.isLinux;
type = types.bool;
description = ''

Whether to compile packages with support for the Systemd init system.

Note that this specifically means compiling packages with the
/Systemd/ libraries. Unit files should always be included in
packages.

'';
};

allowUnfree = mkOption {
default = false;
type = types.bool;
description = ''

Whether to support unfree software. This includes everything not
considered free software by the Free Software Foundation.

'';
};

}
12 changes: 12 additions & 0 deletions pkgs/top-level/stage.nix
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ let
lib.optionalAttrs allowCustomOverrides
((config.packageOverrides or (super: {})) super);

# Allow users to specify global use flags that are applied in all
# packages.
options = self: super:
let config' = (config // (if (config.headless or false)
then { withGTK = false; withX11 = false;
withAlsa = false; withPulseAudio = false;
withJack = false; withWayland = false; }
else {}));
in lib.mapAttrs (name: option: config'.${name} or option.default)
(import ./options.nix { inherit (self) lib stdenv; });

# The complete chain of package set builders, applied from top to bottom.
# stdenvOverlays must be last as it brings package forward from the
# previous bootstrapping phases which have already been overlayed.
Expand All @@ -125,6 +136,7 @@ let
stdenvAdapters
trivialBuilders
splice
options
allPackages
aliases
configOverrides
Expand Down