refactor: remove rec keyword across codebase

Replace rec keyword with modern Nix patterns:
- Use explicit let...in bindings with inherit statements
- Use fix for recursive package bindings in package/default.nix
- This improves maintainability and follows idiomatic Nix patterns

Files modified:
- snowfall-lib/flake/default.nix
- snowfall-lib/fp/default.nix
- snowfall-lib/home/default.nix
- snowfall-lib/system/default.nix
- snowfall-lib/package/default.nix
This commit is contained in:
anntnzrb
2025-10-08 23:11:33 -05:00
parent 973b06a645
commit cedfe30aab
5 changed files with 93 additions and 51 deletions

View File

@@ -18,8 +18,8 @@ let
traceVal
;
in
rec {
flake = rec {
let
flake = let
## Remove the `self` attribute from an attribute set.
## Example Usage:
## ```nix
@@ -43,6 +43,8 @@ rec {
## ```
#@ Attrs -> Attrs
without-src = flake-inputs: builtins.removeAttrs flake-inputs [ "src" ];
in {
inherit without-self without-src;
## Remove the `src` and `self` attributes from an attribute set.
## Example Usage:
@@ -248,4 +250,7 @@ rec {
}) (builtins.attrNames flake-outputs.pkgs)
));
};
in
{
inherit flake mkFlake;
}

View File

@@ -9,7 +9,7 @@ let
inherit (core-inputs.nixpkgs.lib) id foldr flip;
in
{
fp = rec {
fp = let
## Compose two functions.
## Example Usage:
## ```nix
@@ -24,18 +24,6 @@ in
f: g: x:
f (g x);
## Compose many functions.
## Example Usage:
## ```nix
## compose-all [ add-two add-one ]
## ```
## Result:
## ```nix
## (x: add-two (add-one x))
## ```
#@ [(x -> y)] -> a -> b
compose-all = foldr compose id;
## Call a function with an argument.
## Example Usage:
## ```nix
@@ -47,6 +35,20 @@ in
## ```
#@ (a -> b) -> a -> b
call = f: x: f x;
in {
inherit compose call;
## Compose many functions.
## Example Usage:
## ```nix
## compose-all [ add-two add-one ]
## ```
## Result:
## ```nix
## (x: add-two (add-one x))
## ```
#@ [(x -> y)] -> a -> b
compose-all = foldr compose id;
## Apply an argument to a function.
## Example Usage:

View File

@@ -32,7 +32,7 @@ let
user-modules-root = snowfall-lib.fs.get-snowfall-file "modules";
in
{
home = rec {
home = let
# Modules in home-manager expect `hm` to be available directly on `lib` itself.
home-lib =
# NOTE: This prevents an error during evaluation if the input does
@@ -427,5 +427,14 @@ in
++ shared-modules
++ shared-user-modules
++ system-modules;
in {
inherit
home-lib
split-user-and-host
create-home
get-target-homes-metadata
create-homes
create-home-system-modules
;
};
}

View File

@@ -8,6 +8,7 @@ let
inherit (core-inputs.flake-utils-plus.lib) filterPackages allSystems;
inherit (core-inputs.nixpkgs.lib)
assertMsg
fix
foldl
mapAttrs
filterAttrs
@@ -17,7 +18,7 @@ let
user-packages-root = snowfall-lib.fs.get-snowfall-file "packages";
in
{
package = rec {
package = let
## Create flake output packages.
## Example Usage:
## ```nix
@@ -39,6 +40,15 @@ in
}:
let
user-packages = snowfall-lib.fs.get-default-nix-files-recursive src;
merge-packages =
packages: metadata:
packages
// {
${metadata.name} = metadata.drv;
};
packages-without-aliases = fix (
packages-without-aliases:
let
create-package-metadata =
package:
let
@@ -56,6 +66,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 package);
drv =
let
@@ -71,14 +83,14 @@ in
};
};
packages-metadata = builtins.map create-package-metadata user-packages;
merge-packages =
packages: metadata:
packages
// {
${metadata.name} = metadata.drv;
};
packages = snowfall-lib.attrs.merge-with-aliases merge-packages packages-metadata alias // overrides;
in
foldl merge-packages { } packages-metadata
);
aliased-items = mapAttrs (name: value: packages-without-aliases.${value}) alias;
packages = packages-without-aliases // aliased-items // overrides;
in
filterPackages pkgs.stdenv.hostPlatform.system packages;
in {
inherit create-packages;
};
}

View File

@@ -22,7 +22,7 @@ let
user-modules-root = snowfall-lib.fs.get-snowfall-file "modules";
in
{
system = rec {
system = let
## Get the name of a system based on its file path.
## Example Usage:
## ```nix
@@ -349,5 +349,19 @@ in
);
in
created-systems;
in {
inherit
get-inferred-system-name
is-darwin
is-linux
is-virtual
get-virtual-system-type
get-target-systems-metadata
get-system-builder
get-system-output
get-resolved-system-target
create-system
create-systems
;
};
}