mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-08 11:36:05 +01:00
flake-module: add flake-parts module (#5229)
Add a flake-parts module, output as flakeModules.home-manager and flakeModules.default. The module defines options for flake.homeModules and flake.homeConfigurations, based on the respective nixos equivalents; flake.nixosModules and flake.nixosConfigurations.
This commit is contained in:
parent
7a45774684
commit
a5e196d61f
4 changed files with 78 additions and 0 deletions
|
|
@ -30,6 +30,7 @@ nix-flakes/prerequisites.md
|
|||
nix-flakes/standalone.md
|
||||
nix-flakes/nixos.md
|
||||
nix-flakes/nix-darwin.md
|
||||
nix-flakes/flake-parts.md
|
||||
```
|
||||
|
||||
|
||||
|
|
|
|||
40
docs/manual/nix-flakes/flake-parts.md
Normal file
40
docs/manual/nix-flakes/flake-parts.md
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
# flake-parts module {#sec-flakes-flake-parts-module}
|
||||
|
||||
When using [flake-parts](https://flake.parts)
|
||||
you may wish to import home-manager's flake module,
|
||||
`flakeModules.home-manager`.
|
||||
|
||||
``` nix
|
||||
{
|
||||
description = "flake-parts configuration";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||
home-manager.url = "github:nix-community/home-manager";
|
||||
home-manager.inputs.nixpkgs.follows = "nixpkgs";
|
||||
flake-parts.url = "github:hercules-ci/flake-parts";
|
||||
};
|
||||
|
||||
outputs = inputs@{ flake-parts, ... }:
|
||||
flake-parts.lib.mkFlake { inherit inputs; } {
|
||||
imports = [
|
||||
# Import home-manager's flake module
|
||||
inputs.home-manager.flakeModules.home-manager
|
||||
];
|
||||
flake = {
|
||||
# Define `homeModules`, `homeConfigurations`,
|
||||
# `nixosConfigurations`, etc here
|
||||
};
|
||||
# See flake.parts for more features, such as `perSystem`
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
The flake module defines the `flake.homeModules` and `flake.homeConfigurations`
|
||||
options, allowing them to be properly merged if they are defined in multiple
|
||||
modules.
|
||||
|
||||
If you are only defining `homeModules` and/or `homeConfigurations` once in a
|
||||
single module, flake-parts should work fine without importing
|
||||
`flakeModules.home-manager`.
|
||||
|
||||
32
flake-module.nix
Normal file
32
flake-module.nix
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
{ lib, flake-parts-lib, moduleLocation, ... }:
|
||||
let inherit (lib) toString mapAttrs mkOption types;
|
||||
in {
|
||||
options = {
|
||||
flake = flake-parts-lib.mkSubmoduleOptions {
|
||||
homeConfigurations = mkOption {
|
||||
type = types.lazyAttrsOf types.raw;
|
||||
default = { };
|
||||
description = ''
|
||||
Instantiated Home-Manager configurations.
|
||||
|
||||
`homeConfigurations` is for specific installations. If you want to expose
|
||||
reusable configurations, add them to `homeModules` in the form of modules, so
|
||||
that you can reference them in this or another flake's `homeConfigurations`.
|
||||
'';
|
||||
};
|
||||
homeModules = mkOption {
|
||||
type = types.lazyAttrsOf types.unspecified;
|
||||
default = { };
|
||||
apply = mapAttrs (k: v: {
|
||||
_file = "${toString moduleLocation}#homeModules.${k}";
|
||||
imports = [ v ];
|
||||
});
|
||||
description = ''
|
||||
Home-Manager modules.
|
||||
|
||||
You may use this for reusable pieces of configuration, service modules, etc.
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -19,6 +19,11 @@
|
|||
# unofficial; deprecated in Nix 2.8
|
||||
darwinModule = self.darwinModules.default;
|
||||
|
||||
flakeModules = rec {
|
||||
home-manager = import ./flake-module.nix;
|
||||
default = home-manager;
|
||||
};
|
||||
|
||||
templates = {
|
||||
standalone = {
|
||||
path = ./templates/standalone;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue