aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-10-24 14:59:29 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-10-24 14:59:29 +0200
commit0cc353f49f9c5d0e0bd203a6854b488a58daaa96 (patch)
tree48d4a821a842f94e3614f7c310423d9d2c98cc21 /pkgs
parentrefactor(modules/unison): Migrate to `by-name` and parameterize (diff)
downloadnixos-config-0cc353f49f9c5d0e0bd203a6854b488a58daaa96.zip
refactor({modules,pkgs}/by-name-overlay): De-duplicate in a `nixLib`
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/by-name-overlay.nix70
-rw-r--r--pkgs/default.nix27
2 files changed, 18 insertions, 79 deletions
diff --git a/pkgs/by-name-overlay.nix b/pkgs/by-name-overlay.nix
deleted file mode 100644
index 7eb3d239..00000000
--- a/pkgs/by-name-overlay.nix
+++ /dev/null
@@ -1,70 +0,0 @@
-# Adapted from this: https://github.com/NixOS/nixpkgs/blob/1814b56453c91192f6d5a6276079948f9fe96c18/pkgs/top-level/by-name-overlay.nix
-{
- lib,
- sysLib,
- pkgs,
- baseDirectory,
-}:
-# This file turns the pkgs/by-name directory (see its README.md for more info) into an overlay that adds all the defined packages.
-# No validity checks are done here,
-# instead this file is optimised for performance,
-# and validity checks are done by CI on PRs.
-let
- # FIXME: Check if we override something in the set <2024-05-22>
- callPackage = lib.callPackageWith (pkgs // myPkgs // {inherit sysLib;});
- inherit lib;
-
- inherit
- (builtins)
- readDir
- ;
-
- inherit
- (lib.attrsets)
- mapAttrs
- mapAttrsToList
- mergeAttrsList
- ;
-
- # Package files for a single shard
- # Type: String -> String -> AttrsOf Path
- namesForShard = shard: type:
- if type != "directory"
- then
- # Ignore all non-directories. Technically only README.md is allowed as a file in the base directory, so we could alternatively:
- # - Assume that README.md is the only file and change the condition to `shard == "README.md"` for a minor performance improvement.
- # This would however cause very poor error messages if there's other files.
- # - Ensure that README.md is the only file, throwing a better error message if that's not the case.
- # However this would make for a poor code architecture, because one type of error would have to be duplicated in the validity checks and here.
- # Additionally in either of those alternatives, we would have to duplicate the hardcoding of "README.md"
- {}
- else
- mapAttrs
- (name: _: baseDirectory + "/${shard}/${name}/package.nix")
- (readDir (baseDirectory + "/${shard}"));
-
- # The attribute set mapping names to the package files defining them
- # This is defined up here in order to allow reuse of the value (it's kind of expensive to compute)
- # if the overlay has to be applied multiple times
- packageFiles = mergeAttrsList (mapAttrsToList namesForShard (readDir baseDirectory));
- myPkgs =
- mapAttrs
- (_: path: callPackage path {})
- packageFiles;
-in
- # # TODO: Consider optimising this using `builtins.deepSeq packageFiles`,
- # # which could free up the above thunks and reduce GC times.
- # # Currently this would be hard to measure until we have more packages
- # # and ideally https://github.com/NixOS/nix/pull/8895
- # self: super:
- # {
- # # This attribute is necessary to allow CI to ensure that all packages defined in `pkgs/by-name`
- # # don't have an overriding definition in `all-packages.nix` with an empty (`{ }`) second `callPackage` argument.
- # # It achieves that with an overlay that modifies both `callPackage` and this attribute to signal whether `callPackage` is used
- # # and whether it's defined by this file here or `all-packages.nix`.
- # # TODO: This can be removed once `pkgs/by-name` can handle custom `callPackage` arguments without `all-packages.nix` (or any other way of achieving the same result).
- # # Because at that point the code in ./stage.nix can be changed to not allow definitions in `all-packages.nix` to override ones from `pkgs/by-name` anymore and throw an error if that happens instead.
- # _internalCallByNamePackageFile = file: self.callPackage file {};
- # }
- # //
- myPkgs
diff --git a/pkgs/default.nix b/pkgs/default.nix
index 66803694..39d225a9 100644
--- a/pkgs/default.nix
+++ b/pkgs/default.nix
@@ -1,13 +1,22 @@
{
- pkgs,
- sysLib,
+ pkgs ? (builtins.getFlake "nixpkgs").legacyPackages."x86_64-linux",
+ sysLib ? builtins.trace "Moking `sysLib`" {},
+ nixLib ? import ../lib {},
}: let
- # TODO: Filter the sources of every package in the shards <2024-05-25>
- files = import ./by-name-overlay.nix {
- inherit pkgs sysLib;
- inherit (pkgs) lib;
- baseDirectory =
- ./by-name;
+ inherit (pkgs) lib;
+
+ # FIXME: Make this override check actually work.
+ # I think that some parts of the lazy eval are causing that to not actually evaluate the
+ # error message. <2024-10-23>
+ maybeMergeMessage = "While merging the pkgs in ./pkgs/by-name to the nixpkgs set.";
+ mMM = maybeMergeMessage;
+ callPackage = lib.callPackageWith (nixLib.maybeMerge (nixLib.maybeMerge pkgs myPkgs mMM) {inherit sysLib;} mMM);
+
+ myPkgs = nixLib.mkByName {
+ baseDirectory = ./by-name;
+ fileName = "package.nix";
+ finalizeFunction = name: value: callPackage value {};
};
in
- files
+ # TODO: Filter the sources of every package in the shards <2024-05-25>
+ myPkgs