Compare commits

...

5 commits

Author SHA1 Message Date
f7e91dc1b9 WIP: flake: home-manager: export NixOS homes
All checks were successful
ci/woodpecker/push/check Pipeline was successful
WIP: this does not take into account the `profiles` which *also* setup
home-manager modules...

And here is what the last few commits were building up to.

This is neat, but won't be useful *very* often.
2023-12-07 22:24:29 +00:00
f73212de38 flake: home-manager: refactor 'mkHome'
This will allow making a similar function for NixOS homes.
2023-12-07 22:00:14 +00:00
06492fa138 flake: home-manager: use 'hosts' option 2023-12-07 22:00:14 +00:00
1c5a775da1 flake: nixos: use 'hosts' option 2023-12-07 22:00:14 +00:00
9a3a105ee2 flake: add hosts
This will allow other modules to cross-reference which hosts exist on
which system.

My main use-case is to automatically declare home-manager configuration
for the home configuration of NixOS hosts.

I also include Darwin in case I ever want to use that in the future,
though that is unlikely for the moment.
2023-12-07 22:00:14 +00:00
4 changed files with 53 additions and 14 deletions

View file

@ -13,6 +13,7 @@ flake-parts.lib.mkFlake { inherit inputs; } {
./checks.nix
./dev-shells.nix
./home-manager.nix
./hosts.nix
./lib.nix
./nixos.nix
./overlays.nix

View file

@ -1,5 +1,7 @@
{ self, inputs, lib, ... }:
{ self, config, inputs, lib, ... }:
let
inherit (config) hosts;
defaultModules = [
# Include generic settings
"${self}/modules/home"
@ -16,7 +18,7 @@ let
}
];
mkHome = name: system: inputs.home-manager.lib.homeManagerConfiguration {
mkHomeCommon = mainModule: system: inputs.home-manager.lib.homeManagerConfiguration {
# Work-around for home-manager
# * not letting me set `lib` as an extraSpecialArgs
# * not respecting `nixpkgs.overlays` [1]
@ -29,9 +31,7 @@ let
];
};
modules = defaultModules ++ [
"${self}/hosts/homes/${name}"
];
modules = defaultModules ++ [ mainModule ];
extraSpecialArgs = {
# Inject inputs to use them in global registry
@ -39,24 +39,37 @@ let
};
};
homes = {
mkHome = name: mkHomeCommon "${self}/hosts/homes/${name}";
mkNixosHome = name: mkHomeCommon "${self}/hosts/nixos/${name}/home.nix";
in
{
hosts.homes = {
"ambroisie@bazin" = "x86_64-linux";
"ambroisie@mousqueton" = "x86_64-linux";
};
in
{
perSystem = { system, ... }: {
# Work-around for https://github.com/nix-community/home-manager/issues/3075
legacyPackages = {
homeConfigurations =
let
filteredHomes = lib.filterAttrs (_: v: v == system) homes;
filteredHomes = lib.filterAttrs (_: v: v == system) hosts.homes;
allHomes = filteredHomes // {
# Default configuration
ambroisie = system;
};
homeManagerHomes = lib.mapAttrs mkHome allHomes;
filteredNixosHosts = lib.filterAttrs (_: v: v == system) hosts.nixos;
nixosHomes' = lib.mapAttrs mkNixosHome filteredNixosHosts;
nixosHomes = lib.mapAttrs' (host: lib.nameValuePair "ambroisie@${host}") nixosHomes';
in
lib.mapAttrs mkHome allHomes;
lib.foldl' lib.mergeAttrs { }
[
homeManagerHomes
nixosHomes
];
};
};
}

21
flake/hosts.nix Normal file
View file

@ -0,0 +1,21 @@
# Define `hosts.{darwin,home,nixos}` options for consumption in other modules
{ lib, ... }:
let
mkHostsOption = description: lib.mkOption {
inherit description;
type = with lib.types; attrsOf str;
default = { };
example = { name = "x86_64-linux"; };
};
in
{
options = {
hosts = {
darwin = mkHostsOption "Darwin hosts";
homes = mkHostsOption "Home Manager hosts";
nixos = mkHostsOption "NixOS hosts";
};
};
}

View file

@ -1,4 +1,4 @@
{ self, inputs, lib, ... }:
{ self, config, inputs, lib, ... }:
let
defaultModules = [
{
@ -28,8 +28,12 @@ let
};
in
{
flake.nixosConfigurations = lib.mapAttrs buildHost {
aramis = "x86_64-linux";
porthos = "x86_64-linux";
config = {
hosts.nixos = {
aramis = "x86_64-linux";
porthos = "x86_64-linux";
};
flake.nixosConfigurations = lib.mapAttrs buildHost config.hosts.nixos;
};
}