Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

please combine the libs #30

Open
saygo-png opened this issue Jan 12, 2025 · 0 comments
Open

please combine the libs #30

saygo-png opened this issue Jan 12, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@saygo-png
Copy link
Owner

i made 2 custom libs because the one i was using earlier couldnt be made to have config since that only is exposed during module eval, so i had to make another one that exposed. I didnt combine them into one because i was dealing with a stupid sx issue and was sick of it after ~5 hours.

Claude said to do it like this which looks like it would work

# lib/default.nix
{ lib, config, pkgs }:

let
  # Your library functions here
  customLib = {
    mkCustomService = { name }: {
      systemd.services.${name} = {
        description = "Service using ${config.networking.hostName}";
        # ... rest of your service config
      };
    };
    
    mkUserEnv = { username }: {
      users.users.${username} = {
        shell = config.users.defaultShell;
        # ... other user settings
      };
    };
  };
in
# Extend the original lib with your additions
lib.extend (final: prev: customLib)

# flake.nix
{
  description = "System with extended lib";

  outputs = { self, nixpkgs, ... }: {
    nixosConfigurations.myhost = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        # Make the extended lib available to all modules
        ({ lib, config, pkgs, ... }: {
          _module.args.lib = import ./lib {
            inherit (nixpkgs) lib;
            inherit config pkgs;
          };
        })
        
        # Your actual configuration
        ({ lib, ... }: {
          # Now you can use your custom functions directly from lib
          imports = [
            (lib.mkCustomService { name = "myservice"; })
          ];
          
          networking.hostName = "myhost";
        })
      ];
    };
  };
}
@saygo-png saygo-png added the enhancement New feature or request label Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant