From ab8a691d059b364c435a1871ae2ef70a578685d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Thu, 28 Jan 2016 11:24:18 +0100 Subject: [PATCH 1/4] 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. --- lib/customisation.nix | 2 +- nixos/modules/config/debug-info.nix | 2 +- nixos/modules/config/system-path.nix | 19 +++++++++---------- nixos/modules/programs/man.nix | 2 +- nixos/modules/security/polkit.nix | 2 +- pkgs/build-support/buildenv/default.nix | 9 ++++++++- 6 files changed, 21 insertions(+), 15 deletions(-) diff --git a/lib/customisation.nix b/lib/customisation.nix index 585495469b24..efe82d786600 100644 --- a/lib/customisation.nix +++ b/lib/customisation.nix @@ -129,7 +129,7 @@ rec { }; outputsList = map outputToAttrListElement outputs; - in commonAttrs.${drv.outputName}; + in commonAttrs // { outputUnspecified = true; }; /* Strip a derivation of all non-essential attributes, returning diff --git a/nixos/modules/config/debug-info.nix b/nixos/modules/config/debug-info.nix index a096a9809cee..777ae71eebfb 100644 --- a/nixos/modules/config/debug-info.nix +++ b/nixos/modules/config/debug-info.nix @@ -38,7 +38,7 @@ with lib; # environment.pathsToLink, and we can't have both. #environment.pathsToLink = [ "/lib/debug/.build-id" ]; - environment.outputsToLink = + environment.extraOutputsToLink = optional config.environment.enableDebugInfo "debug"; }; diff --git a/nixos/modules/config/system-path.nix b/nixos/modules/config/system-path.nix index 3df7d7cdac4f..eb5eba7a042f 100644 --- a/nixos/modules/config/system-path.nix +++ b/nixos/modules/config/system-path.nix @@ -73,11 +73,11 @@ in description = "List of directories to be symlinked in /run/current-system/sw."; }; - outputsToLink = mkOption { + extraOutputsToLink = mkOption { type = types.listOf types.str; default = [ ]; - example = [ "doc" ]; - description = "List of package outputs to be symlinked into /run/current-system/sw."; + example = [ "doc" "info" "docdev" ]; + description = "List of additional package outputs to be symlinked into /run/current-system/sw."; }; }; @@ -120,18 +120,17 @@ in "/share/vim-plugins" ]; - environment.outputsToLink = [ "bin" "lib" "out" ]; - system.path = pkgs.buildEnv { name = "system-path"; paths = - lib.filter (drv: drv != null && drv != (drv.dev or null)) - (lib.concatMap (drv: - [ drv ] ++ map (outputName: drv.${outputName}.outPath or null) config.environment.outputsToLink) - config.environment.systemPackages); - inherit (config.environment) pathsToLink; + # The default output probably shouldn't be globally configurable. + # Services and users should specify them explicitly unless they want this default. + map (p: if p.outputUnspecified or false then p.bin or p.out or p else p) + config.environment.systemPackages; + inherit (config.environment) pathsToLink extraOutputsToLink; ignoreCollisions = true; # !!! Hacky, should modularise. + # outputs TODO: note that the tools will often not be linked by default postBuild = '' if [ -x $out/bin/update-mime-database -a -w $out/share/mime ]; then diff --git a/nixos/modules/programs/man.nix b/nixos/modules/programs/man.nix index b28506538049..94d026fdaef0 100644 --- a/nixos/modules/programs/man.nix +++ b/nixos/modules/programs/man.nix @@ -23,7 +23,7 @@ with lib; environment.pathsToLink = [ "/share/man" ]; - environment.outputsToLink = [ "man" ]; + environment.extraOutputsToLink = [ "man" ]; }; diff --git a/nixos/modules/security/polkit.nix b/nixos/modules/security/polkit.nix index 70e5e8b9fa74..507f81bbf073 100644 --- a/nixos/modules/security/polkit.nix +++ b/nixos/modules/security/polkit.nix @@ -59,7 +59,7 @@ in config = mkIf cfg.enable { - environment.systemPackages = [ pkgs.polkit ]; + environment.systemPackages = [ pkgs.polkit.bin pkgs.polkit.out ]; systemd.packages = [ pkgs.polkit.out ]; diff --git a/pkgs/build-support/buildenv/default.nix b/pkgs/build-support/buildenv/default.nix index 1a0726d15437..bcfa2dd1c5a8 100644 --- a/pkgs/build-support/buildenv/default.nix +++ b/pkgs/build-support/buildenv/default.nix @@ -21,6 +21,10 @@ # directories in the list is not symlinked. pathsToLink ? ["/"] +, # The package outputs to include. By default, only the default + # output is included. + extraOutputsToLink ? [] + , # Root the result in directory "$out${extraPrefix}", e.g. "/share". extraPrefix ? "" @@ -37,7 +41,10 @@ runCommand name rec { inherit manifest ignoreCollisions passthru meta pathsToLink extraPrefix postBuild buildInputs; pkgs = builtins.toJSON (map (drv: { - paths = [ drv ]; + paths = + [ drv ] + ++ lib.filter (p: p!=null) + (builtins.map (outName: drv.${outName} or null) extraOutputsToLink); priority = drv.meta.priority or 5; }) paths); preferLocalBuild = true; From 3342f717da7f660b4695f09034abc175a14fda24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Mon, 14 Mar 2016 11:56:03 +0100 Subject: [PATCH 2/4] stdenv: set meta.outputsToInstall unless overridden --- pkgs/stdenv/generic/default.nix | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix index 8395394f5a87..90cacd036c2a 100644 --- a/pkgs/stdenv/generic/default.nix +++ b/pkgs/stdenv/generic/default.nix @@ -220,12 +220,22 @@ let # The meta attribute is passed in the resulting attribute set, # but it's not part of the actual derivation, i.e., it's not # passed to the builder and is not a dependency. But since we - # include it in the result, it *is* available to nix-env for - # queries. We also a meta.position attribute here to - # identify the source location of the package. - meta = meta // (if pos' != null then { - position = pos'.file + ":" + toString pos'.line; - } else {}); + # include it in the result, it *is* available to nix-env for queries. + meta = { } + # If the packager hasn't specified `outputsToInstall`, choose a default, + # namely `p.bin or p.out or p`; + # if he has specified it, it will be overridden below in `// meta`. + // { outputsToInstall = + let + outs = outputs'; # the value passed to derivation primitive + hasOutput = out: builtins.elem out outs; + in [( lib.findFirst hasOutput null (["bin" "out"] ++ outs) )]; + } + // meta + # Fill `meta.position` to identify the source location of the package. + // lib.optionalAttrs (pos' != null) + { position = pos'.file + ":" + toString pos'.line; } + ; inherit passthru; } // # Pass through extra attributes that are not inputs, but From 2995439003a6473fc6531d09900e183b0d5de425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Mon, 14 Mar 2016 12:15:58 +0100 Subject: [PATCH 3/4] buildEnv: respect meta.outputsToInstall As a result `systemPackages` now also respect it. Only nix-env remains and that has a PR filed: https://github.com/NixOS/nix/pull/815 --- nixos/modules/config/system-path.nix | 6 +----- pkgs/build-support/buildenv/default.nix | 7 ++++++- pkgs/stdenv/generic/default.nix | 3 +++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/nixos/modules/config/system-path.nix b/nixos/modules/config/system-path.nix index eb5eba7a042f..69830683d9c5 100644 --- a/nixos/modules/config/system-path.nix +++ b/nixos/modules/config/system-path.nix @@ -122,11 +122,7 @@ in system.path = pkgs.buildEnv { name = "system-path"; - paths = - # The default output probably shouldn't be globally configurable. - # Services and users should specify them explicitly unless they want this default. - map (p: if p.outputUnspecified or false then p.bin or p.out or p else p) - config.environment.systemPackages; + paths = config.environment.systemPackages; inherit (config.environment) pathsToLink extraOutputsToLink; ignoreCollisions = true; # !!! Hacky, should modularise. diff --git a/pkgs/build-support/buildenv/default.nix b/pkgs/build-support/buildenv/default.nix index 8b8c3e3cbc20..10f7c69c3aa1 100644 --- a/pkgs/build-support/buildenv/default.nix +++ b/pkgs/build-support/buildenv/default.nix @@ -48,7 +48,12 @@ runCommand name meta pathsToLink extraPrefix postBuild buildInputs; pkgs = builtins.toJSON (map (drv: { paths = - [ drv ] + # First add the usual output(s): respect if user has chosen explicitly, + # and otherwise use `meta.outputsToInstall` (guaranteed to exist by stdenv). + (if (drv.outputUnspecified or false) + then map (outName: drv.${outName}) drv.meta.outputsToInstall + else [ drv ]) + # Add any extra outputs specified by the caller of `buildEnv`. ++ lib.filter (p: p!=null) (builtins.map (outName: drv.${outName} or null) extraOutputsToLink); priority = drv.meta.priority or 5; diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix index 90cacd036c2a..547541d28246 100644 --- a/pkgs/stdenv/generic/default.nix +++ b/pkgs/stdenv/generic/default.nix @@ -225,6 +225,9 @@ let # If the packager hasn't specified `outputsToInstall`, choose a default, # namely `p.bin or p.out or p`; # if he has specified it, it will be overridden below in `// meta`. + # Note: This default probably shouldn't be globally configurable. + # Services and users should specify outputs explicitly, + # unless they are comfortable with this default. // { outputsToInstall = let outs = outputs'; # the value passed to derivation primitive From 9a824f2f1dd01450e6f7270246f77210d4c9c2a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Mon, 14 Mar 2016 12:19:37 +0100 Subject: [PATCH 4/4] treewide: rename extraOutputs{ToLink,ToInstall} This is to get more consistent with `meta.outputsToInstall`. --- nixos/modules/config/debug-info.nix | 2 +- nixos/modules/config/system-path.nix | 4 ++-- nixos/modules/programs/man.nix | 2 +- pkgs/build-support/buildenv/default.nix | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/nixos/modules/config/debug-info.nix b/nixos/modules/config/debug-info.nix index 777ae71eebfb..17cb862d2916 100644 --- a/nixos/modules/config/debug-info.nix +++ b/nixos/modules/config/debug-info.nix @@ -38,7 +38,7 @@ with lib; # environment.pathsToLink, and we can't have both. #environment.pathsToLink = [ "/lib/debug/.build-id" ]; - environment.extraOutputsToLink = + environment.extraOutputsToInstall = optional config.environment.enableDebugInfo "debug"; }; diff --git a/nixos/modules/config/system-path.nix b/nixos/modules/config/system-path.nix index 69830683d9c5..d7815324c4c4 100644 --- a/nixos/modules/config/system-path.nix +++ b/nixos/modules/config/system-path.nix @@ -73,7 +73,7 @@ in description = "List of directories to be symlinked in /run/current-system/sw."; }; - extraOutputsToLink = mkOption { + extraOutputsToInstall = mkOption { type = types.listOf types.str; default = [ ]; example = [ "doc" "info" "docdev" ]; @@ -123,7 +123,7 @@ in system.path = pkgs.buildEnv { name = "system-path"; paths = config.environment.systemPackages; - inherit (config.environment) pathsToLink extraOutputsToLink; + inherit (config.environment) pathsToLink extraOutputsToInstall; ignoreCollisions = true; # !!! Hacky, should modularise. # outputs TODO: note that the tools will often not be linked by default diff --git a/nixos/modules/programs/man.nix b/nixos/modules/programs/man.nix index 94d026fdaef0..201144ccb451 100644 --- a/nixos/modules/programs/man.nix +++ b/nixos/modules/programs/man.nix @@ -23,7 +23,7 @@ with lib; environment.pathsToLink = [ "/share/man" ]; - environment.extraOutputsToLink = [ "man" ]; + environment.extraOutputsToInstall = [ "man" ]; }; diff --git a/pkgs/build-support/buildenv/default.nix b/pkgs/build-support/buildenv/default.nix index 10f7c69c3aa1..8b2167a8e74f 100644 --- a/pkgs/build-support/buildenv/default.nix +++ b/pkgs/build-support/buildenv/default.nix @@ -27,7 +27,7 @@ , # The package outputs to include. By default, only the default # output is included. - extraOutputsToLink ? [] + extraOutputsToInstall ? [] , # Root the result in directory "$out${extraPrefix}", e.g. "/share". extraPrefix ? "" @@ -55,7 +55,7 @@ runCommand name else [ drv ]) # Add any extra outputs specified by the caller of `buildEnv`. ++ lib.filter (p: p!=null) - (builtins.map (outName: drv.${outName} or null) extraOutputsToLink); + (builtins.map (outName: drv.${outName} or null) extraOutputsToInstall); priority = drv.meta.priority or 5; }) paths); preferLocalBuild = true;