docs: add comments explaining unsafeDiscardStringContext usage

Add clear documentation for all uses of unsafeDiscardStringContext,
explaining that it's necessary when building flake outputs based on
file paths, as Nix doesn't allow using paths as attribute names directly.
This commit is contained in:
anntnzrb
2025-10-08 23:11:44 -05:00
parent cedfe30aab
commit 47c33cfae1
4 changed files with 10 additions and 0 deletions

View File

@@ -48,6 +48,8 @@ in
};
in
{
# We are building flake outputs based on file paths. Nix doesn't allow this
# so we have to explicitly discard the string's path context to use it as an attribute name.
name = builtins.unsafeDiscardStringContext (snowfall-lib.path.get-parent-directory check);
drv = callPackageWith extra-inputs check { };
};

View File

@@ -41,6 +41,8 @@ in
create-module-metadata = module: {
name =
let
# We are building flake outputs based on file paths. Nix doesn't allow this
# so we have to explicitly discard the string's path context for string manipulation.
path-name = builtins.replaceStrings [ (builtins.toString src) "/default.nix" ] [ "" "" ] (
builtins.unsafeDiscardStringContext module
);

View File

@@ -111,6 +111,8 @@ in
create-overlay = (
overlays: file:
let
# We are building flake outputs based on file paths. Nix doesn't allow this
# so we have to explicitly discard the string's path context to use it as an attribute name.
name = builtins.unsafeDiscardStringContext (snowfall-lib.path.get-parent-directory file);
overlay =
final: prev:
@@ -159,6 +161,8 @@ in
create-package-overlay =
package-overlays: file:
let
# We are building flake outputs based on file paths. Nix doesn't allow this
# so we have to explicitly discard the string's path context to use it as an attribute name.
name = builtins.unsafeDiscardStringContext (snowfall-lib.path.get-parent-directory file);
overlay =
final: prev:

View File

@@ -48,6 +48,8 @@ in
};
in
{
# We are building flake outputs based on file paths. Nix doesn't allow this
# so we have to explicitly discard the string's path context to use it as an attribute name.
name = builtins.unsafeDiscardStringContext (snowfall-lib.path.get-parent-directory shell);
drv = callPackageWith extra-inputs shell { };
};