Skip to content

Commit

Permalink
4/5: export mkLib (will update post latter)
Browse files Browse the repository at this point in the history
  • Loading branch information
srid committed Feb 26, 2024
1 parent fc4fa3d commit 331664a
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 35 deletions.
36 changes: 20 additions & 16 deletions global/nix-modules/4/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,31 @@
# TODO: Change this to x86_64-linux if you are on Linux
system = "aarch64-darwin";
pkgs = nixpkgs.legacyPackages.${system};
lib = pkgs.lib;
lsdFor = settings:
let
result = lib.evalModules {
modules = [
./lsd.nix
settings
];
specialArgs = { inherit pkgs; };
mkLib = pkgs: {
lsdFor = settings:
let
result = pkgs.lib.evalModules {
modules = [
./lsd.nix
settings
];
specialArgs = { inherit pkgs; };
};
in
result.config.lsd.package;
# ⤵️ A common module for re-use in other modules (see below)
common = {
lsd = {
long = pkgs.lib.mkDefault true;
};
in
result.config.lsd.package;
# ⤵️ A common module for re-use in other modules (see below)
common = {
lsd = {
long = lib.mkDefault true;
};
};
inherit (mkLib pkgs) lsdFor common;
in
{
inherit common; # For use in 5/flake.nix
# Let's export some things for use in 5/flake.nix
inherit mkLib;

packages.${system} = {
default = lsdFor {
# ⤵️ Here, we import the common module
Expand Down
34 changes: 33 additions & 1 deletion global/nix-modules/5/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 6 additions & 18 deletions global/nix-modules/5/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,19 @@
# TODO: Change this to x86_64-linux if you are on Linux
system = "aarch64-darwin";
pkgs = nixpkgs.legacyPackages.${system};
lib = pkgs.lib;
lsdFor = settings:
let
result = lib.evalModules {
modules = [
# ⤵️ We import flake4's module directly here, by file path.
(flake4 + /lsd.nix)
# ⤵️ We can also reference the module directly.
flake4.common
settings
];
specialArgs = { inherit pkgs; };
};
in
result.config.lsd.package;
# ⤵️ We import the library from 4/flake.nix
lsdLib = flake4.mkLib pkgs;
in
{
packages.${system} = {
default = lsdFor {
default = lsdLib.lsdFor {
imports = [ lsdLib.common ];
lsd.dir = "/";
};
home = lsdFor {
home = lsdLib.lsdFor {
lsd.dir = "$HOME";
};
downloads = lsdFor {
downloads = lsdLib.lsdFor {
lsd = {
dir = "$HOME/Downloads";
tree = true;
Expand Down

0 comments on commit 331664a

Please sign in to comment.