From e95279f45ce4f150d6dcc60edcbc535476b863de Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Tue, 9 Jul 2024 06:34:10 +0200 Subject: [PATCH] pkgs/top-level: allow overrides through by-name and check for file existence before using path --- outputs.nix | 2 +- pkgs/top-level/by-name-overlay.nix | 50 ++++++++++++++++++++++++++++++ pkgs/top-level/default.nix | 2 +- 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 pkgs/top-level/by-name-overlay.nix diff --git a/outputs.nix b/outputs.nix index 6793c9d..aced032 100644 --- a/outputs.nix +++ b/outputs.nix @@ -45,7 +45,7 @@ self = { { config.nixpkgs.overlays = [ ( import ./pkgs/overlays/selfExpr.nix { nixpkgsPath = "${self}/pkgs/top-level/impure.nix"; } ) - ( import "${inputs.nixpkgs}/pkgs/top-level/by-name-overlay.nix" "${self}/pkgs/by-name" ) + ( import ./pkgs/top-level/by-name-overlay.nix "${self}/pkgs/by-name" ) self.overlays.versionInfoFixup ]; } diff --git a/pkgs/top-level/by-name-overlay.nix b/pkgs/top-level/by-name-overlay.nix new file mode 100644 index 0000000..ed63216 --- /dev/null +++ b/pkgs/top-level/by-name-overlay.nix @@ -0,0 +1,50 @@ +# Modified copy of github:NixOS/nixpkgs pkgs/top-level/by-name-overlay.nix +# as of commit c0d0be00d4ecc4b51d2d6948e37466194c1e6c51 + +# This file turns the pkgs/by-name directory into an overlay that adds all the defined packages. +# No validity checks are done here. + +# Type: Path -> Overlay +baseDirectory: +let + lib = (import ../../outputs.nix {}).lib; + + inherit (builtins) + readDir + ; + + inherit (lib.attrsets) + mapAttrs + mapAttrsToList + mergeAttrsList + ; + + # Package files for a single shard + # Type: String -> String -> String -> AttrsOf Path + namesForShard = nixFilename: shard: type: + if type != "directory" then + # Ignore all non-directories. + { } + else + mapAttrs + (name: _: baseDirectory + "/${shard}/${name}/${nixFilename}") + (readDir (baseDirectory + "/${shard}")); + + # The attribute set mapping names to the package files defining them + # Type: String -> AttrsOf Path + packageFiles = nixFilename: lib.pipe baseDirectory [ + readDir + (mapAttrsToList (namesForShard nixFilename)) + mergeAttrsList + # Filter out paths that don't have a ${nixFilename} file + (lib.filterAttrs (_: lib.pathExists)) + ]; +in +self: super: +mapAttrs (name: file: + self.callPackage file { inherit self super; package = super.${name}; } +) (packageFiles "override.nix") +// mapAttrs (name: file: + self.callPackage file { } +) (packageFiles "package.nix") + diff --git a/pkgs/top-level/default.nix b/pkgs/top-level/default.nix index 85abb2e..fd3e12a 100644 --- a/pkgs/top-level/default.nix +++ b/pkgs/top-level/default.nix @@ -16,7 +16,7 @@ let ( import ../overlays/selfExpr.nix { nixpkgsPath = "${builtins.toString ../..}/pkgs/top-level/impure.nix"; } ) ( import ../overlays/unstable.nix ) ( import ../overlays/version-info-fixup.nix { inherit inputs; } ) - ( import "${inputs.nixpkgs}/pkgs/top-level/by-name-overlay.nix" ../by-name ) + ( import ./by-name-overlay.nix ../by-name ) ]; }; in