Malix
July 9, 2026, 2:35pm
21
See How to use uutils-coreutils instead of the builtin coreutils? - #42 by Malix :
I just crafted the dynamic alternative:
pkgs:
let
inherit (pkgs) lib;
# Generates a name starting with prefix, padded with "v" to match the target's name length exactly
padName =
targetName: prefix:
let
padLength = lib.stringLength targetName - lib.stringLength prefix;
in
# Error messages without this assertion would be gibberish
assert lib.assertMsg (
padLength >= 0
) "Prefix '${prefix}' is longer than target name '${targetName}'";
prefix + lib.strings.replicate padLength "v";
# coreutils-full is the only package we care about that is not in `pkgs.stdenv.initialPath`
candidates = pkgs.stdenv.initialPath ++ [ pkgs.coreutils-full ];
oldDependencies = lib.filter (
old: lib.hasPrefix "coreutils" old.pname || lib.hasAttr "uutils-${old.pname}" pkgs
) candidates;
in
{
system.replaceDependencies.replacements = map (
oldDependency:
let
new =
if lib.hasPrefix "coreutils" oldDependency.pname then
pkgs.uutils-coreutils-noprefix
else
pkgs."uutils-${oldDependency.pname}";
prefix = lib.replaceStrings [ "utils" ] [ "uutils" ] oldDependency.pname + "-";
name = padName oldDependency.name prefix;
in
{
inherit oldDependency;
newDependency = pkgs.symlinkJoin {
inherit name;
paths = [ new ];
};
}
) oldDependencies;
}
I haven’t focused on performance yet
Let me know if anyone can find something better
I think a solution like this is close to what’s the best alternative possible without a dedicated NixOS option to chose which coreutils (and such) to use
Until then, we will always be bottlenecked by replaceDependencies
A blocker for the concern of this thread is a NixOS option to switch coreutils (and such) without having to use replaceDependencies (which is basically a hack that changes the deps AFTER they have already been stored, suboptimal)
The original concern of this thread: “replacing gnu core-utils with uutils by default in nixos” will then basically only be switching some default to true