mirror of
https://github.com/mjallen18/snowfall-lib.git
synced 2026-04-18 09:05: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
|
traceVal
|
||||||
;
|
;
|
||||||
in
|
in
|
||||||
rec {
|
let
|
||||||
flake = rec {
|
flake = let
|
||||||
## Remove the `self` attribute from an attribute set.
|
## Remove the `self` attribute from an attribute set.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
## ```nix
|
## ```nix
|
||||||
@@ -43,6 +43,8 @@ rec {
|
|||||||
## ```
|
## ```
|
||||||
#@ Attrs -> Attrs
|
#@ Attrs -> Attrs
|
||||||
without-src = flake-inputs: builtins.removeAttrs flake-inputs [ "src" ];
|
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.
|
## Remove the `src` and `self` attributes from an attribute set.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -248,4 +250,7 @@ rec {
|
|||||||
}) (builtins.attrNames flake-outputs.pkgs)
|
}) (builtins.attrNames flake-outputs.pkgs)
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
inherit flake mkFlake;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ let
|
|||||||
inherit (core-inputs.nixpkgs.lib) id foldr flip;
|
inherit (core-inputs.nixpkgs.lib) id foldr flip;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
fp = rec {
|
fp = let
|
||||||
## Compose two functions.
|
## Compose two functions.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
## ```nix
|
## ```nix
|
||||||
@@ -24,18 +24,6 @@ in
|
|||||||
f: g: x:
|
f: g: x:
|
||||||
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.
|
## Call a function with an argument.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
## ```nix
|
## ```nix
|
||||||
@@ -47,6 +35,20 @@ in
|
|||||||
## ```
|
## ```
|
||||||
#@ (a -> b) -> a -> b
|
#@ (a -> b) -> a -> b
|
||||||
call = f: x: f x;
|
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.
|
## Apply an argument to a function.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ let
|
|||||||
user-modules-root = snowfall-lib.fs.get-snowfall-file "modules";
|
user-modules-root = snowfall-lib.fs.get-snowfall-file "modules";
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
home = rec {
|
home = let
|
||||||
# Modules in home-manager expect `hm` to be available directly on `lib` itself.
|
# Modules in home-manager expect `hm` to be available directly on `lib` itself.
|
||||||
home-lib =
|
home-lib =
|
||||||
# NOTE: This prevents an error during evaluation if the input does
|
# NOTE: This prevents an error during evaluation if the input does
|
||||||
@@ -427,5 +427,14 @@ in
|
|||||||
++ shared-modules
|
++ shared-modules
|
||||||
++ shared-user-modules
|
++ shared-user-modules
|
||||||
++ system-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.flake-utils-plus.lib) filterPackages allSystems;
|
||||||
inherit (core-inputs.nixpkgs.lib)
|
inherit (core-inputs.nixpkgs.lib)
|
||||||
assertMsg
|
assertMsg
|
||||||
|
fix
|
||||||
foldl
|
foldl
|
||||||
mapAttrs
|
mapAttrs
|
||||||
filterAttrs
|
filterAttrs
|
||||||
@@ -17,7 +18,7 @@ let
|
|||||||
user-packages-root = snowfall-lib.fs.get-snowfall-file "packages";
|
user-packages-root = snowfall-lib.fs.get-snowfall-file "packages";
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
package = rec {
|
package = let
|
||||||
## Create flake output packages.
|
## Create flake output packages.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
## ```nix
|
## ```nix
|
||||||
@@ -39,46 +40,57 @@ in
|
|||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
user-packages = snowfall-lib.fs.get-default-nix-files-recursive src;
|
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 =
|
merge-packages =
|
||||||
packages: metadata:
|
packages: metadata:
|
||||||
packages
|
packages
|
||||||
// {
|
// {
|
||||||
${metadata.name} = metadata.drv;
|
${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
|
in
|
||||||
filterPackages pkgs.stdenv.hostPlatform.system packages;
|
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";
|
user-modules-root = snowfall-lib.fs.get-snowfall-file "modules";
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
system = rec {
|
system = let
|
||||||
## Get the name of a system based on its file path.
|
## Get the name of a system based on its file path.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
## ```nix
|
## ```nix
|
||||||
@@ -349,5 +349,19 @@ in
|
|||||||
);
|
);
|
||||||
in
|
in
|
||||||
created-systems;
|
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