LANG: EN -> CN
Rikki's NixOS Config
You can seen _module.args
or specialArgs
as your best solution.
The differents between above is here:
-
specialArgs
just used inflake.nix
{ description = "description"; inputs = { }; outputs = { self, nixpkgs, ... } @ inputs: { nixosConfigurations = { "<sub-config-name>" = nixpkgs.lib.nixosSystem { system = "x86_64-linux"; specialArgs = {inherit inputs;}; # <- here modules = [ ]; }; }; }; }
In this example, you inherit inputs set as your extra arguments, then all the modules can get variables which in your inputs set.
You can use below to help your module to get variables:
{ self, nixpkgs, ... }: { }
Just list variables in the header of file, then your module got it.
-
_module.args
must be used in an module{...} @ upstream: let trackerList = import ./aria2-tracker; in { _module.args = {inherit trackerList;}; imports = [ ]; }
In this example, we created a variable named
trackerList
.We use
_module.args = {inherit trackerList;};
which equal to_module.args.trackerList = trackerList;
to expose the variabletrackerList
to another module.If we want to import
trackerList
, we can simply use the same code in paragraph one.extra: If you want to replace
specialArgs
to_module.args
You can just use below to achieve your goal.
{ description = "description"; inputs = { }; outputs = { self, nixpkgs, ... } @ inputs: { nixosConfigurations = { "<sub-config-name>" = nixpkgs.lib.nixosSystem { system = "x86_64-linux"; modules = [ { _module.args = {inherit inputs;}; # <- here } ]; }; }; }; }
You can easily find that we created an inline module, and it not against the rules.
Use alejandra as the official formatter for this repo.
You can try it in your browser. here