From a732a8de1ccb042cc05b1ac7defd7e4c9a91b4ff Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 27 Jan 2022 12:33:10 +0100 Subject: [PATCH 1/5] Revert "nixos/documentation.nix: Use builtins.storePath when appropriate" This reverts commit 5d29853c389b52d75104415060fbeb2cd170a8fa. --- nixos/modules/misc/documentation.nix | 82 +++++----------------------- 1 file changed, 14 insertions(+), 68 deletions(-) diff --git a/nixos/modules/misc/documentation.nix b/nixos/modules/misc/documentation.nix index 2afa43a3fe71..59ded4b01888 100644 --- a/nixos/modules/misc/documentation.nix +++ b/nixos/modules/misc/documentation.nix @@ -61,80 +61,26 @@ let in scrubbedEval.options; baseOptionsJSON = let - filterIntoStore = + filter = builtins.filterSource (n: t: (t == "directory" -> baseNameOf n != "tests") && (t == "file" -> hasSuffix ".nix" n) ); - - # Figure out if Nix runs in pure evaluation mode. May return true in - # impure mode, but this is highly unlikely. - # We need to know because of https://github.com/NixOS/nix/issues/1888 - # and https://github.com/NixOS/nix/issues/5868 - isPureEval = builtins.getEnv "PATH" == "" && builtins.getEnv "_" == ""; - - # Return a nixpkgs subpath with minimal copying. + # When working directly from a checkout, + # produce separate, smaller store paths + # When already in the store, + # avoid copying; reuse the whole nixpkgs sources # - # The sources for the base options json derivation can come in one of - # two forms: - # - single source: a store path with all of nixpkgs, postfix with - # subpaths to access various directories. This has the benefit of - # not creating copies of these subtrees in the Nix store, but - # can cause unnecessary rebuilds if you update the Nixpkgs `pkgs` - # tree often. - # - split sources: multiple store paths with subdirectories of - # nixpkgs that exclude the bulk of the pkgs directory. - # This requires more copying and hashing during evaluation but - # requires fewer files to be copied. This method produces fewer - # unnecessary rebuilds of the base options json. - # - # Flake - # - # Flakes always put a copy of the full nixpkgs sources in the store, - # so we can use the "single source" method. This method is ideal - # for using nixpkgs as a dependency, as the base options json will be - # substitutable from cache.nixos.org. - # - # This requires that the `self.outPath` is wired into `pkgs` correctly, - # which is done for you if `pkgs` comes from the `lib.nixosSystem` or - # `legacyPackages` flake attributes. - # - # Other Nixpkgs invocation - # - # If you do not use the known-correct flake attributes, but rather - # invoke Nixpkgs yourself, set `config.path` to the correct path value, - # e.g. `import nixpkgs { config.path = nixpkgs; }`. - # - # Choosing between single or split source paths - # - # We make assumptions based on the type and contents of `pkgs.path`. - # By passing a different `config.path` to Nixpkgs, you can influence - # how your documentation cache is evaluated and rebuilt. - # - # Single source - # - If pkgs.path is a string containing a store path, the code has no - # choice but to create this store path, if it hasn't already been. - # We assume that the "single source" method is most efficient. - # - If pkgs.path is a path value containing that is a store path, - # we try to convert it to a string with context without copying. - # This occurs for example when nixpkgs was fetched and using its - # default `config.path`, which is `./.`. - # Nix currently does not allow this conversion when evaluating in - # pure mode. If the conversion is not possible, we use the - # "split source" method. - # - # Split source - # - If pkgs.path is a path value that is not a store path, we assume - # that it's unlikely for all of nixpkgs to end up in the store for - # other reasons and try to keep both the copying and rebuilds low. - pull = - if builtins.typeOf pkgs.path == "string" && isStorePath pkgs.path then - dir: "${pkgs.path}/${dir}" - else if !isPureEval && isStorePath pkgs.path then - dir: "${builtins.storePath pkgs.path}/${dir}" - else - dir: filterIntoStore "${toString pkgs.path}/${dir}"; + # We can only avoid copying when pkgs.path is already a string. A path + # value can not be converted to a store path without rehashing it. + # builtins.storePath would be a solution but is currently off-limits + # because of https://github.com/NixOS/nix/issues/1888 + # and https://github.com/NixOS/nix/issues/5868 + pull = dir: + if builtins.typeOf pkgs.path == "string" && isStorePath pkgs.path + then "${pkgs.path}/${dir}" + else filter "${toString pkgs.path}/${dir}"; in pkgs.runCommand "lazy-options.json" { libPath = pull "lib"; From 647b304306b5d483294754faf1951fe788d060c2 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 27 Jan 2022 12:33:15 +0100 Subject: [PATCH 2/5] Revert "nixos/documentation.nix: Only use store non-flake pkgs.path directly when already copied" This reverts commit fecf32505984f4b8feae4c54663f322dcc8bd080. --- nixos/modules/misc/documentation.nix | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/nixos/modules/misc/documentation.nix b/nixos/modules/misc/documentation.nix index 59ded4b01888..361815b48d52 100644 --- a/nixos/modules/misc/documentation.nix +++ b/nixos/modules/misc/documentation.nix @@ -71,14 +71,8 @@ let # produce separate, smaller store paths # When already in the store, # avoid copying; reuse the whole nixpkgs sources - # - # We can only avoid copying when pkgs.path is already a string. A path - # value can not be converted to a store path without rehashing it. - # builtins.storePath would be a solution but is currently off-limits - # because of https://github.com/NixOS/nix/issues/1888 - # and https://github.com/NixOS/nix/issues/5868 pull = dir: - if builtins.typeOf pkgs.path == "string" && isStorePath pkgs.path + if isStorePath pkgs.path then "${pkgs.path}/${dir}" else filter "${toString pkgs.path}/${dir}"; in From aa877346f8cf9a12da8402d5f7e2097b8136890c Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 27 Jan 2022 12:33:16 +0100 Subject: [PATCH 3/5] Revert "nixos/documentation: avoid copying nixpkgs subpaths, iteration 2" This reverts commit 15a00be189be329f488986cd72d7315fa643b89a. --- nixos/modules/misc/documentation.nix | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/nixos/modules/misc/documentation.nix b/nixos/modules/misc/documentation.nix index 361815b48d52..b7746ddc2115 100644 --- a/nixos/modules/misc/documentation.nix +++ b/nixos/modules/misc/documentation.nix @@ -67,19 +67,11 @@ let (t == "directory" -> baseNameOf n != "tests") && (t == "file" -> hasSuffix ".nix" n) ); - # When working directly from a checkout, - # produce separate, smaller store paths - # When already in the store, - # avoid copying; reuse the whole nixpkgs sources - pull = dir: - if isStorePath pkgs.path - then "${pkgs.path}/${dir}" - else filter "${toString pkgs.path}/${dir}"; in pkgs.runCommand "lazy-options.json" { - libPath = pull "lib"; - pkgsLibPath = pull "pkgs/pkgs-lib"; - nixosPath = pull "nixos"; + libPath = filter "${toString pkgs.path}/lib"; + pkgsLibPath = filter "${toString pkgs.path}/pkgs/pkgs-lib"; + nixosPath = filter "${toString pkgs.path}/nixos"; modules = map (p: ''"${removePrefix "${modulesPath}/" (toString p)}"'') docModules.lazy; } '' export NIX_STORE_DIR=$TMPDIR/store From 6b9ef93b98c053ef6390ef96092b3b302773a4aa Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 27 Jan 2022 12:53:29 +0100 Subject: [PATCH 4/5] Revert "flake.nix: Set nixpkgs.config.path" This reverts commit 0b222173dba00680074ef9e98a5bad224f62967e. --- flake.nix | 4 ---- nixos/modules/misc/nixpkgs.nix | 2 -- 2 files changed, 6 deletions(-) diff --git a/flake.nix b/flake.nix index 39553cde0ab5..c2306768d6fe 100644 --- a/flake.nix +++ b/flake.nix @@ -48,10 +48,6 @@ system.nixos.versionSuffix = ".${final.substring 0 8 (self.lastModifiedDate or self.lastModified or "19700101")}.${self.shortRev or "dirty"}"; system.nixos.revision = final.mkIf (self ? rev) self.rev; - - # NOTE: This assumes that `nixpkgs.config` is _not_ used when - # nixpkgs.pkgs is set OR _module.args.pkgs is set. - nixpkgs.config.path = self.outPath; } ]; }); diff --git a/nixos/modules/misc/nixpkgs.nix b/nixos/modules/misc/nixpkgs.nix index 14dd1d816dbe..69967c8a7601 100644 --- a/nixos/modules/misc/nixpkgs.nix +++ b/nixos/modules/misc/nixpkgs.nix @@ -59,8 +59,6 @@ let inherit (cfg) config overlays localSystem crossSystem; }; - # NOTE: flake.nix assumes that nixpkgs.config is only used with ../../.. - # as nixpkgs.config.path should be equivalent to ../../.. finalPkgs = if opt.pkgs.isDefined then cfg.pkgs.appendOverlays cfg.overlays else defaultPkgs; in From 4acad300acfe47598322965f574aef9bff711c98 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 27 Jan 2022 12:53:30 +0100 Subject: [PATCH 5/5] Revert "pkgs.path: Avoid copying when used via flake" This reverts commit 813f9da8ab69f106055dd4a8fead7bc0a21a251b. --- flake.nix | 2 +- pkgs/top-level/all-packages.nix | 2 +- pkgs/top-level/config.nix | 14 -------------- 3 files changed, 2 insertions(+), 16 deletions(-) diff --git a/flake.nix b/flake.nix index c2306768d6fe..29dffa9fa4e4 100644 --- a/flake.nix +++ b/flake.nix @@ -62,7 +62,7 @@ }).nixos.manual.x86_64-linux; }; - legacyPackages = forAllSystems (system: import ./. { inherit system; config.path = self.outPath; }); + legacyPackages = forAllSystems (system: import ./. { inherit system; }); nixosModules = { notDetected = import ./nixos/modules/installer/scan/not-detected.nix; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 54e661d6af0f..413f2ae521e0 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -67,7 +67,7 @@ with pkgs; clangStdenvNoLibs = mkStdenvNoLibs clangStdenv; # For convenience, allow callers to get the path to Nixpkgs. - path = config.path; + path = ../..; ### Helper functions. diff --git a/pkgs/top-level/config.nix b/pkgs/top-level/config.nix index bb4f668d60f1..7a5b4bdd1798 100644 --- a/pkgs/top-level/config.nix +++ b/pkgs/top-level/config.nix @@ -32,20 +32,6 @@ let feature = "run checkPhase by default"; }; - path = mkOption { - type = types.path; - default = ../..; - defaultText = lib.literalDocBook "a path expression"; - internal = true; - description = '' - A reference to Nixpkgs' own sources. - - This is overridable in order to avoid copying sources unnecessarily, - as a path expression that references a store path will not short-circuit - to the store path itself, but copy the store path instead. - ''; - }; - }; in {