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 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); name = builtins.unsafeDiscardStringContext (snowfall-lib.path.get-parent-directory check);
drv = callPackageWith extra-inputs check { }; drv = callPackageWith extra-inputs check { };
}; };

View File

@@ -41,6 +41,8 @@ in
create-module-metadata = module: { create-module-metadata = module: {
name = name =
let 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" ] [ "" "" ] ( path-name = builtins.replaceStrings [ (builtins.toString src) "/default.nix" ] [ "" "" ] (
builtins.unsafeDiscardStringContext module builtins.unsafeDiscardStringContext module
); );

View File

@@ -111,6 +111,8 @@ in
create-overlay = ( create-overlay = (
overlays: file: overlays: file:
let 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); name = builtins.unsafeDiscardStringContext (snowfall-lib.path.get-parent-directory file);
overlay = overlay =
final: prev: final: prev:
@@ -159,6 +161,8 @@ in
create-package-overlay = create-package-overlay =
package-overlays: file: package-overlays: file:
let 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); name = builtins.unsafeDiscardStringContext (snowfall-lib.path.get-parent-directory file);
overlay = overlay =
final: prev: final: prev:

View File

@@ -48,6 +48,8 @@ in
}; };
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); name = builtins.unsafeDiscardStringContext (snowfall-lib.path.get-parent-directory shell);
drv = callPackageWith extra-inputs shell { }; drv = callPackageWith extra-inputs shell { };
}; };