From 555d0c60949bc702bf37b41f137c827c4690a74d Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Thu, 26 Apr 2018 17:40:32 -0500 Subject: [PATCH 1/7] stage.nix: implement "use flags" This uses overlays to implement "user flags" for Nixpkgs. Note that this just allows packages to use these flags. No packages flags are renamed but that is planned (with backward compatibility). Eventually I want to generate some manual from the mkOptions but no time right now. Fixes #12877. --- pkgs/top-level/stage.nix | 7 ++ pkgs/top-level/use-flags.nix | 128 +++++++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+) create mode 100644 pkgs/top-level/use-flags.nix diff --git a/pkgs/top-level/stage.nix b/pkgs/top-level/stage.nix index de676c5a42105..cb83473b0b6b3 100644 --- a/pkgs/top-level/stage.nix +++ b/pkgs/top-level/stage.nix @@ -116,6 +116,12 @@ let lib.optionalAttrs allowCustomOverrides ((config.packageOverrides or (super: {})) super); + # Allow users to specify global use flags that are applied in all + # packages. + useFlags = self: super: + lib.mapAttrs (name: option: config.${name} or option.default) + (import ./use-flags.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. @@ -125,6 +131,7 @@ let stdenvAdapters trivialBuilders splice + useFlags allPackages aliases configOverrides diff --git a/pkgs/top-level/use-flags.nix b/pkgs/top-level/use-flags.nix new file mode 100644 index 0000000000000..985df654b607f --- /dev/null +++ b/pkgs/top-level/use-flags.nix @@ -0,0 +1,128 @@ +{lib, stdenv}: + +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 || stdenv.isBSD; + type = types.bool; + description = '' + + Whether to compile packages with support for the X Window System. + + ''; + }; + + withWayland = mkOption { + default = stdenv.isLinux || stdenv.isBSD; + 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 { + 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. + + ''; + }; + +} From 69a2a5e1b81750afd14be7ad19d4e7e8f2db9d81 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Thu, 26 Apr 2018 17:49:55 -0500 Subject: [PATCH 2/7] stage: add headless config This should be solved by something like the module system, but for now I am just implementing this as an example. --- pkgs/top-level/{use-flags.nix => options.nix} | 4 ++-- pkgs/top-level/stage.nix | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) rename pkgs/top-level/{use-flags.nix => options.nix} (96%) diff --git a/pkgs/top-level/use-flags.nix b/pkgs/top-level/options.nix similarity index 96% rename from pkgs/top-level/use-flags.nix rename to pkgs/top-level/options.nix index 985df654b607f..3edca63c30be6 100644 --- a/pkgs/top-level/use-flags.nix +++ b/pkgs/top-level/options.nix @@ -19,7 +19,7 @@ with lib; }; withX11 = mkOption { - default = stdenv.isLinux || stdenv.isBSD; + default = stdenv.isLinux; # also BSDs? type = types.bool; description = '' @@ -29,7 +29,7 @@ with lib; }; withWayland = mkOption { - default = stdenv.isLinux || stdenv.isBSD; + default = stdenv.isLinux; # also BSDs? type = types.bool; description = '' diff --git a/pkgs/top-level/stage.nix b/pkgs/top-level/stage.nix index cb83473b0b6b3..b84fbaa7ab5ff 100644 --- a/pkgs/top-level/stage.nix +++ b/pkgs/top-level/stage.nix @@ -118,9 +118,14 @@ let # Allow users to specify global use flags that are applied in all # packages. - useFlags = self: super: - lib.mapAttrs (name: option: config.${name} or option.default) - (import ./use-flags.nix { inherit (self) lib stdenv; }); + 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 @@ -131,7 +136,7 @@ let stdenvAdapters trivialBuilders splice - useFlags + options allPackages aliases configOverrides From 3f8943f38e3d0f55ea9f24b32fc228cbad177f15 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Sun, 29 Apr 2018 15:20:49 -0500 Subject: [PATCH 3/7] options: revise based on code review --- pkgs/top-level/options.nix | 23 ++++++++++++----------- pkgs/top-level/stage.nix | 7 +------ 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/pkgs/top-level/options.nix b/pkgs/top-level/options.nix index 3edca63c30be6..defe881c30bc0 100644 --- a/pkgs/top-level/options.nix +++ b/pkgs/top-level/options.nix @@ -1,10 +1,11 @@ -{lib, stdenv}: +{lib, targetPlatform}: 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. +# Define some user flags. Each one will be passed as an argument to +# callPackage and can be used directly by packages to configure +# themselves. Note that none of these should be mutually exclusive. +# For instance enabling X11 should not imply that Wayland is disabled. { @@ -19,7 +20,7 @@ with lib; }; withX11 = mkOption { - default = stdenv.isLinux; # also BSDs? + default = targetPlatform.isLinux; # also BSDs? type = types.bool; description = '' @@ -29,7 +30,7 @@ with lib; }; withWayland = mkOption { - default = stdenv.isLinux; # also BSDs? + default = targetPlatform.isLinux; # also BSDs? type = types.bool; description = '' @@ -39,7 +40,7 @@ with lib; }; withAlsa = mkOption { - default = stdenv.isLinux; + default = targetPlatform.isLinux; type = types.bool; description = '' @@ -49,7 +50,7 @@ with lib; }; withPulseAudio = mkOption { - default = stdenv.isLinux; + default = targetPlatform.isLinux; type = types.bool; description = '' @@ -78,7 +79,7 @@ with lib; ''; }; - withGTK = mkOption { + withGtk = mkOption { default = false; type = types.bool; description = '' @@ -89,7 +90,7 @@ with lib; }; withApple = mkOption { - default = stdenv.isDarwin; + default = targetPlatform.isDarwin; type = types.bool; description = '' @@ -101,7 +102,7 @@ with lib; }; withSystemd = mkOption { - default = stdenv.isLinux; + default = targetPlatform.isLinux; type = types.bool; description = '' diff --git a/pkgs/top-level/stage.nix b/pkgs/top-level/stage.nix index b84fbaa7ab5ff..92d7ee43d838b 100644 --- a/pkgs/top-level/stage.nix +++ b/pkgs/top-level/stage.nix @@ -119,12 +119,7 @@ let # 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) + 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. From b985ab664884ae253e20a2c4cc4828c03485c0b7 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Sun, 29 Apr 2018 16:01:51 -0500 Subject: [PATCH 4/7] options: use splicing Still not sure how well this works- but POC for putting the options in splice.nix. --- pkgs/top-level/options.nix | 14 +++++++------- pkgs/top-level/splice.nix | 8 +++++++- pkgs/top-level/stage.nix | 7 ------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/pkgs/top-level/options.nix b/pkgs/top-level/options.nix index defe881c30bc0..9f9293025c228 100644 --- a/pkgs/top-level/options.nix +++ b/pkgs/top-level/options.nix @@ -1,4 +1,4 @@ -{lib, targetPlatform}: +{lib, hostPlatform}: with lib; @@ -20,7 +20,7 @@ with lib; }; withX11 = mkOption { - default = targetPlatform.isLinux; # also BSDs? + default = hostPlatform.isLinux; # also BSDs? type = types.bool; description = '' @@ -30,7 +30,7 @@ with lib; }; withWayland = mkOption { - default = targetPlatform.isLinux; # also BSDs? + default = hostPlatform.isLinux; # also BSDs? type = types.bool; description = '' @@ -40,7 +40,7 @@ with lib; }; withAlsa = mkOption { - default = targetPlatform.isLinux; + default = hostPlatform.isLinux; type = types.bool; description = '' @@ -50,7 +50,7 @@ with lib; }; withPulseAudio = mkOption { - default = targetPlatform.isLinux; + default = hostPlatform.isLinux; type = types.bool; description = '' @@ -90,7 +90,7 @@ with lib; }; withApple = mkOption { - default = targetPlatform.isDarwin; + default = hostPlatform.isDarwin; type = types.bool; description = '' @@ -102,7 +102,7 @@ with lib; }; withSystemd = mkOption { - default = targetPlatform.isLinux; + default = hostPlatform.isLinux; type = types.bool; description = '' diff --git a/pkgs/top-level/splice.nix b/pkgs/top-level/splice.nix index 1fde08d1d48b4..f1bcca137cb49 100644 --- a/pkgs/top-level/splice.nix +++ b/pkgs/top-level/splice.nix @@ -36,7 +36,13 @@ let # whether `nativeDrv` or `crossDrv` is the default in `defaultScope`. pkgsWithoutFetchers = lib.filterAttrs (n: _: !lib.hasPrefix "fetch" n) pkgs; targetPkgsWithoutFetchers = lib.filterAttrs (n: _: !lib.hasPrefix "fetch" n) pkgs.targetPackages; - defaultHostTargetScope = pkgsWithoutFetchers // pkgs.xorg; + + # Allow users to specify global use flags that are applied in all + # packages. + options = lib.mapAttrs (name: option: pkgs.config.${name} or option.default) + (import ./options.nix { inherit lib; inherit (pkgs) hostPlatform; }); + + defaultHostTargetScope = pkgsWithoutFetchers // pkgs.xorg // options; defaultTargetTargetScope = targetPkgsWithoutFetchers // targetPkgsWithoutFetchers.xorg or {}; splicer = pkgsBuildBuild: pkgsBuildHost: pkgsBuildTarget: diff --git a/pkgs/top-level/stage.nix b/pkgs/top-level/stage.nix index 92d7ee43d838b..de676c5a42105 100644 --- a/pkgs/top-level/stage.nix +++ b/pkgs/top-level/stage.nix @@ -116,12 +116,6 @@ 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: - 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. @@ -131,7 +125,6 @@ let stdenvAdapters trivialBuilders splice - options allPackages aliases configOverrides From c44ecd4ad30a2b6712aa73f4af79dfead1165503 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Thu, 7 Jun 2018 12:13:26 -0400 Subject: [PATCH 5/7] options: add enableDynamic && enableStatic options This should make it easier to build lots of packages statically when you want. --- pkgs/top-level/options.nix | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/pkgs/top-level/options.nix b/pkgs/top-level/options.nix index 9f9293025c228..b74b05415cd6e 100644 --- a/pkgs/top-level/options.nix +++ b/pkgs/top-level/options.nix @@ -126,4 +126,29 @@ with lib; ''; }; + enableDynamic = mkOption { + default = true; + type = types.bool; + description = '' + + Whether to build packages with dynamic linking. This has + historically been the default everywhere in Nixpkgs. + + ''; + }; + + enableStatic = mkOption { + default = targetPlatform.isiOS; + type = types.bool; + description = '' + + Whether to build packages with static linking if available. Note + that not all packages support this. + + Packages using this option may or may not also build dynamic + libraries. Set enableDynamic to disable those. + + ''; + }; + } From 4ff72fd3738372ae299bbfda51b1a64607a99dd5 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Thu, 7 Jun 2018 17:25:57 -0400 Subject: [PATCH 6/7] toplevel: add release-options.nix --- pkgs/top-level/release-options.nix | 45 ++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 pkgs/top-level/release-options.nix diff --git a/pkgs/top-level/release-options.nix b/pkgs/top-level/release-options.nix new file mode 100644 index 0000000000000..2d76b66fbd652 --- /dev/null +++ b/pkgs/top-level/release-options.nix @@ -0,0 +1,45 @@ +{ pkgs ? import ../.. +, lib ? import ../../lib }: + +lib.mapAttrs (n: v: pkgs v) { + headlessLinux = { + config = { + withGtk = false; + withQt = false; + withPulseAudio = false; + withJack = false; + withAlsa = false; + withWayland = false; + withX11 = false; + }; + localSystem = { system = "x86_64-linux"; }; + }; + freeDarwin = { + config = { + withApple = false; + allowUnfree = false; + }; + localSystem = { system = "x86_64-darwin"; }; + }; + slnosLinux = { + config = { + withSystemd = false; + withPulseAudio = false; + }; + localSystem = { system = "x86_64-linux"; }; + }; + staticLinux = { + config = { + enableStatic = true; + enableDynamic = false; + }; + localSystem = { system = "x86_64-linux"; }; + }; + staticDarwin = { + config = { + enableStatic = true; + enableDynamic = false; + }; + localSystem = { system = "x86_64-darwin"; }; + }; +} From 0da616891874ac93a5fcb4d37e079fb970c29c29 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Mon, 25 Jun 2018 14:11:24 -0400 Subject: [PATCH 7/7] options: enableDynamic -> enableShared This is a better name --- pkgs/top-level/options.nix | 8 ++++---- pkgs/top-level/release-options.nix | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkgs/top-level/options.nix b/pkgs/top-level/options.nix index b74b05415cd6e..fe7291e843634 100644 --- a/pkgs/top-level/options.nix +++ b/pkgs/top-level/options.nix @@ -126,12 +126,12 @@ with lib; ''; }; - enableDynamic = mkOption { + enableShared = mkOption { default = true; type = types.bool; description = '' - Whether to build packages with dynamic linking. This has + Whether to build packages with shared linking. This has historically been the default everywhere in Nixpkgs. ''; @@ -145,8 +145,8 @@ with lib; Whether to build packages with static linking if available. Note that not all packages support this. - Packages using this option may or may not also build dynamic - libraries. Set enableDynamic to disable those. + Packages using this option may or may not also build shared + libraries. Set enableShare to disable those. ''; }; diff --git a/pkgs/top-level/release-options.nix b/pkgs/top-level/release-options.nix index 2d76b66fbd652..8c94b8a2d1086 100644 --- a/pkgs/top-level/release-options.nix +++ b/pkgs/top-level/release-options.nix @@ -31,14 +31,14 @@ lib.mapAttrs (n: v: pkgs v) { staticLinux = { config = { enableStatic = true; - enableDynamic = false; + enableShared = false; }; localSystem = { system = "x86_64-linux"; }; }; staticDarwin = { config = { enableStatic = true; - enableDynamic = false; + enableShared = false; }; localSystem = { system = "x86_64-darwin"; }; };