mirror of
https://github.com/mjallen18/snowfall-lib.git
synced 2026-04-18 00:55:58 -05:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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,46 +40,57 @@ in
|
||||
}:
|
||||
let
|
||||
user-packages = snowfall-lib.fs.get-default-nix-files-recursive src;
|
||||
create-package-metadata =
|
||||
package:
|
||||
let
|
||||
namespaced-packages = {
|
||||
${namespace} = packages-without-aliases;
|
||||
};
|
||||
extra-inputs =
|
||||
pkgs
|
||||
// namespaced-packages
|
||||
// {
|
||||
inherit channels namespace;
|
||||
lib = snowfall-lib.internal.system-lib;
|
||||
pkgs = pkgs // namespaced-packages;
|
||||
inputs = user-inputs;
|
||||
};
|
||||
in
|
||||
{
|
||||
name = builtins.unsafeDiscardStringContext (snowfall-lib.path.get-parent-directory package);
|
||||
drv =
|
||||
let
|
||||
pkg = callPackageWith extra-inputs package { };
|
||||
in
|
||||
pkg
|
||||
// {
|
||||
meta = (pkg.meta or { }) // {
|
||||
snowfall = {
|
||||
path = package;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
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;
|
||||
packages-without-aliases = fix (
|
||||
packages-without-aliases:
|
||||
let
|
||||
create-package-metadata =
|
||||
package:
|
||||
let
|
||||
namespaced-packages = {
|
||||
${namespace} = packages-without-aliases;
|
||||
};
|
||||
extra-inputs =
|
||||
pkgs
|
||||
// namespaced-packages
|
||||
// {
|
||||
inherit channels namespace;
|
||||
lib = snowfall-lib.internal.system-lib;
|
||||
pkgs = pkgs // namespaced-packages;
|
||||
inputs = user-inputs;
|
||||
};
|
||||
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
|
||||
pkg = callPackageWith extra-inputs package { };
|
||||
in
|
||||
pkg
|
||||
// {
|
||||
meta = (pkg.meta or { }) // {
|
||||
snowfall = {
|
||||
path = package;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
packages-metadata = builtins.map create-package-metadata user-packages;
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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
|
||||
;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user