2024-07-20 13:30:25 +02:00
|
|
|
{ lib, config, self, inputs, withSystem, ... }:
|
2024-07-19 00:06:58 +02:00
|
|
|
|
|
|
|
let
|
|
|
|
# TODO: works?
|
|
|
|
outputs = self;
|
|
|
|
inherit (import ./utils.nix { inherit lib self; })
|
|
|
|
and
|
|
|
|
hasFiles
|
|
|
|
hasDirectories;
|
|
|
|
in
|
|
|
|
let
|
2024-07-20 13:30:25 +02:00
|
|
|
homeManagerModule = { root, system, hostname, users ? null }: {
|
|
|
|
home-manager = {
|
|
|
|
# Use same `pkgs` instance as system (i.e. carry over overlays)
|
|
|
|
useGlobalPkgs = true;
|
|
|
|
# Do not keep packages in ${HOME}
|
|
|
|
useUserPackages = true;
|
|
|
|
# Default import all of our exported homeManagerModules
|
|
|
|
sharedModules = builtins.attrValues config.flake.homeManagerModules;
|
|
|
|
# Pass in `inputs`, `outputs` and maybe `meta`
|
|
|
|
extraSpecialArgs = {
|
|
|
|
inherit inputs outputs;
|
|
|
|
# TODO: meta?
|
|
|
|
inherit hostname;
|
|
|
|
};
|
|
|
|
} // (if users == null then {
|
|
|
|
# nixOnDroid
|
|
|
|
config = (lib.path.append root "home.nix");
|
|
|
|
} else {
|
|
|
|
# Not nixOnDroid
|
|
|
|
users = lib.attrsets.genAttrs
|
|
|
|
users
|
|
|
|
(user: import (lib.path.append root "home/${user}.nix"));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2024-07-19 00:06:58 +02:00
|
|
|
# Configuration helpers
|
2024-07-20 13:30:25 +02:00
|
|
|
mkNixosHost = args @ { root, system, hostname, users }: lib.nixosSystem {
|
2024-07-19 00:06:58 +02:00
|
|
|
inherit system;
|
2024-07-20 13:30:25 +02:00
|
|
|
pkgs = withSystem system ({ pkgs, ... }: pkgs);
|
2024-07-19 00:06:58 +02:00
|
|
|
|
|
|
|
modules = [
|
2024-07-20 13:30:25 +02:00
|
|
|
# Main configuration
|
2024-07-19 00:06:58 +02:00
|
|
|
(lib.path.append root "configuration.nix")
|
2024-07-20 13:30:25 +02:00
|
|
|
# Home Manager
|
2024-07-19 00:06:58 +02:00
|
|
|
inputs.home-manager.nixosModules.home-manager
|
2024-07-20 13:30:25 +02:00
|
|
|
(homeManagerModule args)
|
|
|
|
# nix-topology
|
2024-07-19 01:24:20 +02:00
|
|
|
inputs.nix-topology.nixosModules.default
|
2024-07-20 13:30:25 +02:00
|
|
|
# Sane default `networking.hostName`
|
2024-07-19 00:06:58 +02:00
|
|
|
{
|
|
|
|
networking.hostName = lib.mkDefault hostname;
|
|
|
|
}
|
|
|
|
] ++ (builtins.attrValues config.flake.nixosModules);
|
|
|
|
|
|
|
|
specialArgs = {
|
|
|
|
inherit inputs outputs;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-07-20 13:30:25 +02:00
|
|
|
mkNixOnDroidHost = args @ { root, system, hostname }: inputs.nix-on-droid.lib.nixOnDroidConfiguration {
|
|
|
|
# NOTE: inferred by `pkgs.system`
|
|
|
|
# inherit system;
|
|
|
|
pkgs = withSystem system ({ pkgs, ... }: pkgs);
|
2024-07-19 00:06:58 +02:00
|
|
|
|
|
|
|
modules = [
|
2024-07-20 13:30:25 +02:00
|
|
|
# Main configuration
|
2024-07-19 00:06:58 +02:00
|
|
|
(lib.path.append root "configuration.nix")
|
2024-07-20 13:30:25 +02:00
|
|
|
# Home Manager
|
|
|
|
(homeManagerModule args)
|
2024-07-19 00:06:58 +02:00
|
|
|
] ++ (builtins.attrValues config.flake.nixOnDroidModules);
|
|
|
|
|
|
|
|
extraSpecialArgs = {
|
|
|
|
inherit inputs outputs;
|
|
|
|
};
|
|
|
|
|
|
|
|
home-manager-path = inputs.home-manager.outPath;
|
|
|
|
};
|
|
|
|
|
2024-07-20 13:30:25 +02:00
|
|
|
mkNixDarwinHost = args @ { root, system, hostname, users }: inputs.nix-darwin.lib.darwinSystem {
|
2024-07-19 00:06:58 +02:00
|
|
|
inherit system;
|
2024-07-20 13:30:25 +02:00
|
|
|
pkgs = withSystem system ({ pkgs, ... }: pkgs);
|
2024-07-19 00:06:58 +02:00
|
|
|
|
|
|
|
modules = [
|
2024-07-20 13:30:25 +02:00
|
|
|
# Main configuration
|
2024-07-19 00:06:58 +02:00
|
|
|
(lib.path.append root "configuration.nix")
|
2024-07-20 13:30:25 +02:00
|
|
|
# Home Manager
|
2024-07-19 00:06:58 +02:00
|
|
|
inputs.home-manager.darwinModules.home-manager
|
2024-07-20 13:30:25 +02:00
|
|
|
(homeManagerModule args)
|
|
|
|
# # Set `nixpkgs.hostPlatform`
|
|
|
|
# {
|
|
|
|
# nixpkgs.hostPlatform = system;
|
|
|
|
# }
|
2024-07-19 00:06:58 +02:00
|
|
|
] ++ (builtins.attrValues config.flake.nixDarwinModules);
|
|
|
|
|
|
|
|
specialArgs = {
|
|
|
|
inherit inputs outputs;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-07-20 13:30:25 +02:00
|
|
|
mkHomeManagerHost = args @ { root, system, hostname }: inputs.home-manager.lib.homeManagerConfiguration {
|
|
|
|
inherit system;
|
|
|
|
pkgs = withSystem system ({ pkgs, ... }: pkgs);
|
2024-07-19 00:06:58 +02:00
|
|
|
|
|
|
|
modules = [
|
|
|
|
(lib.path.append root "home.nix")
|
|
|
|
] ++ (builtins.attrValues config.flake.homeManagerModules);
|
|
|
|
|
|
|
|
extraSpecialArgs = {
|
|
|
|
inherit inputs outputs;
|
|
|
|
inherit hostname;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
createConfigurations =
|
|
|
|
pred: mkHost: machines:
|
|
|
|
lib.foldAttrs
|
|
|
|
lib.const
|
|
|
|
[ ]
|
|
|
|
(builtins.attrValues
|
|
|
|
(builtins.mapAttrs
|
|
|
|
(system: hosts:
|
|
|
|
lib.concatMapAttrs
|
2024-07-21 14:18:18 +02:00
|
|
|
(host: configurationFiles:
|
2024-07-19 00:06:58 +02:00
|
|
|
lib.optionalAttrs
|
|
|
|
(and [
|
|
|
|
(host != "__template__")
|
2024-07-21 14:18:18 +02:00
|
|
|
(pred { inherit system host configurationFiles; })
|
2024-07-19 00:06:58 +02:00
|
|
|
])
|
|
|
|
{
|
2024-07-21 14:18:18 +02:00
|
|
|
${host} = mkHost { inherit system host configurationFiles; };
|
2024-07-19 00:06:58 +02:00
|
|
|
})
|
|
|
|
hosts)
|
|
|
|
machines));
|
|
|
|
in
|
|
|
|
{
|
|
|
|
flake = {
|
|
|
|
# Configurations
|
|
|
|
nixosConfigurations =
|
|
|
|
createConfigurations
|
2024-07-21 14:18:18 +02:00
|
|
|
({ system, host, configurationFiles, ... }:
|
2024-07-19 00:06:58 +02:00
|
|
|
and
|
|
|
|
[
|
|
|
|
(hasFiles
|
|
|
|
[ "configuration.nix" ]
|
2024-07-21 14:18:18 +02:00
|
|
|
configurationFiles)
|
2024-07-19 00:06:58 +02:00
|
|
|
# (hasDirectories
|
|
|
|
# [ "home" ]
|
|
|
|
# config)
|
|
|
|
])
|
2024-07-21 14:18:18 +02:00
|
|
|
({ system, host, configurationFiles, ... }:
|
2024-07-20 13:30:25 +02:00
|
|
|
mkNixosHost {
|
|
|
|
root = ../machines/nixos/${system}/${host};
|
|
|
|
inherit system;
|
|
|
|
hostname = host;
|
|
|
|
users = (builtins.map
|
2024-07-19 00:06:58 +02:00
|
|
|
(lib.strings.removeSuffix ".nix")
|
2024-07-21 14:18:18 +02:00
|
|
|
(builtins.attrNames (configurationFiles."home" or { })));
|
2024-07-20 13:30:25 +02:00
|
|
|
})
|
2024-07-19 00:06:58 +02:00
|
|
|
config.flake.nixosMachines;
|
|
|
|
|
|
|
|
nixOnDroidConfigurations =
|
|
|
|
createConfigurations
|
2024-07-21 14:18:18 +02:00
|
|
|
({ system, host, configurationFiles, ... }:
|
2024-07-19 00:06:58 +02:00
|
|
|
and
|
|
|
|
[
|
|
|
|
(hasFiles
|
|
|
|
[ "configuration.nix" "home.nix" ]
|
2024-07-21 14:18:18 +02:00
|
|
|
configurationFiles)
|
2024-07-19 00:06:58 +02:00
|
|
|
])
|
2024-07-21 14:18:18 +02:00
|
|
|
({ system, host, configurationFiles, ... }:
|
2024-07-20 13:30:25 +02:00
|
|
|
mkNixOnDroidHost {
|
|
|
|
root = ../machines/nix-on-droid/${system}/${host};
|
|
|
|
inherit system;
|
|
|
|
hostname = host;
|
|
|
|
})
|
2024-07-19 00:06:58 +02:00
|
|
|
config.flake.nixOnDroidMachines;
|
|
|
|
|
|
|
|
darwinConfigurations =
|
|
|
|
createConfigurations
|
2024-07-21 14:18:18 +02:00
|
|
|
({ system, host, configurationFiles, ... }:
|
2024-07-19 00:06:58 +02:00
|
|
|
and
|
|
|
|
[
|
|
|
|
(hasFiles
|
|
|
|
[ "configuration.nix" ]
|
2024-07-21 14:18:18 +02:00
|
|
|
configurationFiles)
|
2024-07-19 00:06:58 +02:00
|
|
|
(hasDirectories
|
|
|
|
[ "home" ]
|
2024-07-21 14:18:18 +02:00
|
|
|
configurationFiles)
|
2024-07-19 00:06:58 +02:00
|
|
|
])
|
2024-07-21 14:18:18 +02:00
|
|
|
({ system, host, configurationFiles, ... }:
|
2024-07-20 13:30:25 +02:00
|
|
|
mkNixDarwinHost {
|
|
|
|
root = ../machines/nix-darwin/${system}/${host};
|
|
|
|
inherit system;
|
|
|
|
hostname = host;
|
|
|
|
users = (builtins.map
|
2024-07-19 00:06:58 +02:00
|
|
|
(lib.strings.removeSuffix ".nix")
|
2024-07-21 14:18:18 +02:00
|
|
|
(builtins.attrNames (configurationFiles."home" or { })));
|
2024-07-20 13:30:25 +02:00
|
|
|
})
|
2024-07-19 00:06:58 +02:00
|
|
|
config.flake.nixDarwinMachines;
|
|
|
|
|
|
|
|
homeConfigurations =
|
|
|
|
createConfigurations
|
2024-07-21 14:18:18 +02:00
|
|
|
({ system, host, configurationFiles, ... }:
|
2024-07-19 00:06:58 +02:00
|
|
|
and
|
|
|
|
[
|
|
|
|
(hasFiles
|
|
|
|
[ "home.nix" ]
|
2024-07-21 14:18:18 +02:00
|
|
|
configurationFiles)
|
2024-07-19 00:06:58 +02:00
|
|
|
])
|
2024-07-21 14:18:18 +02:00
|
|
|
({ system, host, configurationFiles, ... }:
|
2024-07-20 13:30:25 +02:00
|
|
|
mkHomeManagerHost {
|
|
|
|
root = ../machines/home-manager/${system}/${host};
|
|
|
|
inherit system;
|
|
|
|
hostname = host;
|
|
|
|
})
|
2024-07-19 00:06:58 +02:00
|
|
|
config.flake.homeManagerMachines;
|
|
|
|
};
|
|
|
|
}
|