Skip to content
/ fp-nm-ws Public

A flake-parts module to access per-system module arguments inside nixos-modules.

License

Notifications You must be signed in to change notification settings

vic/fp-nm-ws

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fp-nm-ws: FlakeParts NixosModule WithSystem'

This flake provides a flake-parts module that allows nixos-modules to access perSystem module parameters without having to rely on global variables.

Mixing the provided nixosModules.default module, will provide you with withSystem', self', and inputs' to your other nixos modules.

Example Usage

# flake.nix
{
  inputs.flake-parts.url = "github:hercules-ci/flake-parts";
  inputs.fp-nm-ws.url = "github:vic/fp-nm-ws";
  outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } ./your-flake-module.nix;
}
# your-flake-module.nix
{inputs, ...}: {
  perSystem = {system, ...}: {
    config._module.args.foo = "moo-${system}"; # suppose you have a per-system module argument named foo.
    options.bar.default = "some per-system option";
  };

  flake.nixosModules.your-nixos-module.imports = [
    inputs.fp-nm-ws.nixosModules.default # mix-in along with your nixos module.
    ./your-nixos-module.nix
  ];

}
# your-nixos-module.nix
{ config, lib, withSystem', inputs', ...}: {

  # an example usage is reusing the same nixpkgs instance.
  nixpkgs.pkgs = inputs'.nixpkgs.legacyPackages;

  accessFoo = withSystem' ({foo, ...}: foo); # use named parameters
  accessBar = withSystem' (sys@{config, ...}: sys.config.bar);

}

About

A flake-parts module to access per-system module arguments inside nixos-modules.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages