-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use host and user directories for mapping outputs
- Loading branch information
Showing
6 changed files
with
115 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,29 @@ | ||
# flake-parts Module for multi-system and multi-user configuration | ||
# flake-parts module for multi-system and multi-user configuration | ||
|
||
ez-configs flake-parts module provides a flexible framework for managing configurations across multiple systems using nixosSystem, darwinSystem (nix-darwin), and homeManagerConfiguration (home-manager). | ||
ez-configs flake-parts module provides a flexible framework for managing configurations across multiple systems using nixosSystem, darwinSystem (nix-darwin), and homeManagerConfiguration (home-manager), as well as exporting individual modules. | ||
|
||
## Overview | ||
|
||
The module allows users to define system and user-specific configurations that are automatically when present. It is designed to work with a directory structure where configurations are organized by each configuration's hostname and username. | ||
This module allows for defining configuration and module outputs in your flake, for use in nixos, nix-darwin and home-manager, using your directory structure. | ||
This results in 6 directories the module can use: | ||
|
||
It's pretty opinionated, but aims to offer a degree of customizability. | ||
- [nixosModules](https://flake.parts/options/ez-configs#opt-ezConfigs.nixos.modulesDirectory) | ||
- [nixosHosts](https://flake.parts/options/ez-configs#opt-ezConfigs.nixos.hostsDirectory) | ||
- [darwinModules](https://flake.parts/options/ez-configs#opt-ezConfigs.darwin.modulesDirectory) | ||
- [darwinHosts](https://flake.parts/options/ez-configs#opt-ezConfigs.darwin.hostsDirectory) | ||
- [homeModules](https://flake.parts/options/ez-configs#opt-ezConfigs.hm.modulesDirectory) | ||
- [users](https://flake.parts/options/ez-configs#opt-ezConfigs.hm.usersDirectory) | ||
|
||
## Features | ||
|
||
### nixosConfigurations and darwinConfigurations | ||
|
||
Those two are created in quite analogous ways. Assuming most options are kept default and `ezConfigs.root` is set to `./.`, host defined in `ezConfigs.nixos.hosts` / `ezConfigs.darwin.hosts` get created using the following modules: | ||
|
||
- `./nixos(.nix)` or `./dariwn(.nix)` respectively, if present in your root | ||
- `./hosts/${hostname}(.nix)` if present in your root | ||
|
||
This lets you define both platform specific and host specific configuration by simply adding nix files or directories to appropriate locations. | ||
You're also able to define `specialArgs` that will be passed to the appropriate system builders. A useful example would be passing in `{ inherit inputs; }`. | ||
That way you can access your flake inputs from inside your nixos/darwin modules. They can either be set individually for each builder using `ezConfigs.darwin.specialArgs`/ `ezConfigs.nixos.specialArgs` or globally for all configuration builders with `ezConfigs.globalArgs`. | ||
|
||
### homeManagerConfigurations | ||
|
||
It gets created using each user and system pair, with a name `${username}@${hostname}`. Users are defined in `ezConfigs.hs.users`, while hosts are all the nixos and darwin configuration. | ||
With the same assumptions as in the above section, the home manager configuration gets created using the package set of generated by the host system and using the following modules: | ||
|
||
- `./home(.nix)` if present in your root | ||
- `./home/darwin(.nix)` or `./home/linux(.nix)` respectively, if present in your root | ||
- `./users/${username}(.nix)` if present in your root | ||
- `./users/${username}/darwin(.nix)` or `./users/${username}/linux(.nix)` respectively, if present in your root | ||
|
||
This lets you define user and platform specific configurations in the same manner as with nixos and darwin configurations. You can also pass in `extraSpecialArgs` which are the equivalent of `specialArgs` of system builders. | ||
|
||
## Goals | ||
|
||
Some of these are features that I'd like to look into, with no guarantee they get implemented since I'm not sure about how ergonomic to use they would be. | ||
|
||
- Automatically discover hosts and users when a file is created the appropriate directory | ||
- Allow for loading home manager as a nixos module when specified in user config, rather than creating a `homeManagerConfigurations` output | ||
- More configurability, like architecture dependent imports, changing the default `${username}@${hostname}` home manager configuration names, etc. | ||
- Extracting individual modules to flake outputs, so that then can be consumed by other flakes. | ||
Each `.nix` file, or a directory containing `default.nix` file gets included in the respective outputs. | ||
When building configurations, the default module (ie. `<modulesDirectory>/default.nix` or `<modulesDirectory>/default/default.nix`) is imported, unless `importDefault` is set to `false` for that user or host configuration. | ||
In case of home manager configurations, it also includes the `darwin` or `linux` modules depending on the system that configuration is built from. | ||
|
||
## Usage | ||
|
||
See the [example directory](https://github.com/ehllie/ez-configs/blob/main/example/flake.nix) for a documented example. | ||
I also use this module in my [own dotfiles](https://github.com/ehllie/dotfiles/blob/main/flake.nix). | ||
|
||
## TODO | ||
|
||
- Allow for loading home manager as a nixos module when specified in user config, rather than creating a `homeManagerConfigurations` output | ||
- Warn when configuring users or hosts that are not present in the directory tree. |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters