Extend NixOS: Difference between revisions

imported>Fricklerhandwerk
m Fricklerhandwerk moved page NixOS:extend NixOS to Extend NixOS: do not use category name in title
imported>Qm3ster
m 1. imports is a config attribute, not to be confused with the import keyword 2. Fixed code to correspond to description
Line 76: Line 76:
== Modular Configuration ==
== Modular Configuration ==


To avoid using conditional expressions in our <code>configuration.nix</code> file, we can separate these properties into units and blend them together differently for each host. Nix allows us to do this with the <code>imports</code> keyword (see [https://nixos.org/nixos/manual/index.html#sec-modularity NixOS Manual: Modularity]) to separate each concern into its own file. One way to organize this is to place common properties in the <code>configuration.nix</code> file and move the the IRC-related properties into an <code>irc-client.nix</code> file.
To avoid using conditional expressions in our <code>configuration.nix</code> file, we can separate these properties into units and blend them together differently for each host. Nix allows us to do this with the <code>imports</code> attribute (see [https://nixos.org/nixos/manual/index.html#sec-modularity NixOS Manual: Modularity]) to separate each concern into its own file. One way to organize this is to place common properties in the <code>configuration.nix</code> file and move the the IRC-related properties into an <code>irc-client.nix</code> file.


If we move the IRC stuff into the <code>irc-client.nix</code> file, we change the <code>configuration.nix</code> file like this:
If we move the IRC stuff into the <code>irc-client.nix</code> file, we change the <code>configuration.nix</code> file like this:
Line 174: Line 174:
   ];
   ];
   
   
   services.ircClient.enable = true;
   services.ircClient.enable = config.networking.hostName == "my-server";
   services.ircClient.user = "username";
   services.ircClient.user = "username";
  config.networking.hostName = "my-server";
   
   
   # ... usual configuration ...
   # ... usual configuration ...