2024-07-19 00:06:58 +02:00
|
|
|
{ lib, config, self, inputs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
inherit (inputs)
|
|
|
|
nixpkgs;
|
|
|
|
# TODO: works?
|
|
|
|
outputs = self;
|
|
|
|
inherit (import ./utils.nix { inherit lib self; })
|
|
|
|
and
|
|
|
|
hasFiles
|
|
|
|
hasDirectories;
|
|
|
|
in
|
|
|
|
let
|
|
|
|
# Configuration helpers
|
|
|
|
mkNixosHost = root: system: hostname: users: lib.nixosSystem {
|
|
|
|
inherit system;
|
|
|
|
|
|
|
|
modules = [
|
|
|
|
(lib.path.append root "configuration.nix")
|
|
|
|
inputs.home-manager.nixosModules.home-manager
|
2024-07-19 01:24:20 +02:00
|
|
|
inputs.nix-topology.nixosModules.default
|
2024-07-19 00:06:58 +02:00
|
|
|
{
|
|
|
|
nixpkgs.overlays = builtins.attrValues self.overlays;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
home-manager = {
|
|
|
|
useGlobalPkgs = false;
|
|
|
|
useUserPackages = true;
|
|
|
|
users = lib.attrsets.genAttrs
|
|
|
|
users
|
|
|
|
(user: import (lib.path.append root "home/${user}.nix"));
|
|
|
|
sharedModules = builtins.attrValues config.flake.homeManagerModules;
|
|
|
|
extraSpecialArgs = {
|
|
|
|
inherit inputs outputs;
|
|
|
|
inherit hostname;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
{
|
|
|
|
networking.hostName = lib.mkDefault hostname;
|
|
|
|
}
|
|
|
|
] ++ (builtins.attrValues config.flake.nixosModules);
|
|
|
|
|
|
|
|
specialArgs = {
|
|
|
|
inherit inputs outputs;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
mkNixOnDroidHost = root: system: hostname: inputs.nix-on-droid.lib.nixOnDroidConfiguration {
|
|
|
|
pkgs = import nixpkgs {
|
|
|
|
inherit system;
|
|
|
|
|
|
|
|
overlays = builtins.attrValues self.overlays ++ [
|
|
|
|
inputs.nix-on-droid.overlays.default
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
modules = [
|
|
|
|
(lib.path.append root "configuration.nix")
|
|
|
|
{
|
|
|
|
home-manager = {
|
|
|
|
config = (lib.path.append root "home.nix");
|
|
|
|
backupFileExtension = "hm-bak";
|
|
|
|
useGlobalPkgs = false;
|
|
|
|
useUserPackages = true;
|
|
|
|
sharedModules = builtins.attrValues config.flake.homeManagerModules ++ [
|
|
|
|
{
|
|
|
|
nixpkgs.overlays = builtins.attrValues self.overlays;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
extraSpecialArgs = {
|
|
|
|
inherit inputs outputs;
|
|
|
|
inherit hostname;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
] ++ (builtins.attrValues config.flake.nixOnDroidModules);
|
|
|
|
|
|
|
|
extraSpecialArgs = {
|
|
|
|
inherit inputs outputs;
|
|
|
|
inherit hostname;
|
|
|
|
# rootPath = ./.;
|
|
|
|
};
|
|
|
|
|
|
|
|
home-manager-path = inputs.home-manager.outPath;
|
|
|
|
};
|
|
|
|
|
|
|
|
mkNixDarwinHost = root: system: hostname: users: inputs.nix-darwin.lib.darwinSystem {
|
|
|
|
inherit system;
|
|
|
|
|
|
|
|
modules = [
|
|
|
|
(lib.path.append root "configuration.nix")
|
|
|
|
{
|
|
|
|
nixpkgs.hostPlatform = system;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
nixpkgs.overlays = builtins.attrValues self.overlays;
|
|
|
|
}
|
|
|
|
inputs.home-manager.darwinModules.home-manager
|
|
|
|
{
|
|
|
|
home-manager = {
|
|
|
|
useGlobalPkgs = false;
|
|
|
|
useUserPackages = true;
|
|
|
|
users = lib.attrsets.genAttrs
|
|
|
|
users
|
|
|
|
(user: import (lib.path.append root "home/${user}.nix"));
|
|
|
|
sharedModules = builtins.attrValues config.flake.homeManagerModules;
|
|
|
|
extraSpecialArgs = {
|
|
|
|
inherit inputs outputs;
|
|
|
|
inherit hostname;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
] ++ (builtins.attrValues config.flake.nixDarwinModules);
|
|
|
|
|
|
|
|
specialArgs = {
|
|
|
|
inherit inputs outputs;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
mkHomeManagerHost = root: system: hostname: inputs.home-manager.lib.homeManagerConfiguration {
|
|
|
|
pkgs = nixpkgs.legacyPackages.${system};
|
|
|
|
|
|
|
|
modules = [
|
|
|
|
(lib.path.append root "home.nix")
|
|
|
|
{
|
|
|
|
nixpkgs.overlays = builtins.attrValues self.overlays;
|
|
|
|
}
|
|
|
|
] ++ (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-19 00:33:09 +02:00
|
|
|
(host: configuration:
|
2024-07-19 00:06:58 +02:00
|
|
|
lib.optionalAttrs
|
|
|
|
(and [
|
|
|
|
(host != "__template__")
|
2024-07-19 00:33:09 +02:00
|
|
|
(pred system host configuration)
|
2024-07-19 00:06:58 +02:00
|
|
|
])
|
|
|
|
{
|
2024-07-19 00:33:09 +02:00
|
|
|
${host} = mkHost system host configuration;
|
2024-07-19 00:06:58 +02:00
|
|
|
})
|
|
|
|
hosts)
|
|
|
|
machines));
|
|
|
|
|
|
|
|
in
|
|
|
|
{
|
|
|
|
flake = {
|
|
|
|
# Configurations
|
|
|
|
nixosConfigurations =
|
|
|
|
createConfigurations
|
2024-07-19 00:33:09 +02:00
|
|
|
(system: host: configuration:
|
2024-07-19 00:06:58 +02:00
|
|
|
and
|
|
|
|
[
|
|
|
|
(hasFiles
|
|
|
|
[ "configuration.nix" ]
|
2024-07-19 00:33:09 +02:00
|
|
|
configuration)
|
2024-07-19 00:06:58 +02:00
|
|
|
# (hasDirectories
|
|
|
|
# [ "home" ]
|
|
|
|
# config)
|
|
|
|
])
|
2024-07-19 00:33:09 +02:00
|
|
|
(system: host: configuration:
|
2024-07-19 00:06:58 +02:00
|
|
|
mkNixosHost
|
|
|
|
../machines/nixos/${system}/${host}
|
|
|
|
system
|
|
|
|
host
|
|
|
|
(builtins.map
|
|
|
|
(lib.strings.removeSuffix ".nix")
|
2024-07-19 00:33:09 +02:00
|
|
|
(builtins.attrNames (configuration."home" or { }))))
|
2024-07-19 00:06:58 +02:00
|
|
|
config.flake.nixosMachines;
|
|
|
|
|
|
|
|
nixOnDroidConfigurations =
|
|
|
|
createConfigurations
|
2024-07-19 00:33:09 +02:00
|
|
|
(system: host: configuration:
|
2024-07-19 00:06:58 +02:00
|
|
|
and
|
|
|
|
[
|
|
|
|
(hasFiles
|
|
|
|
[ "configuration.nix" "home.nix" ]
|
2024-07-19 00:33:09 +02:00
|
|
|
configuration)
|
2024-07-19 00:06:58 +02:00
|
|
|
])
|
2024-07-19 00:33:09 +02:00
|
|
|
(system: host: configuration:
|
2024-07-19 00:06:58 +02:00
|
|
|
mkNixOnDroidHost
|
|
|
|
../machines/nix-on-droid/${system}/${host}
|
|
|
|
system
|
|
|
|
host)
|
|
|
|
config.flake.nixOnDroidMachines;
|
|
|
|
|
|
|
|
darwinConfigurations =
|
|
|
|
createConfigurations
|
2024-07-19 00:33:09 +02:00
|
|
|
(system: host: configuration:
|
2024-07-19 00:06:58 +02:00
|
|
|
and
|
|
|
|
[
|
|
|
|
(hasFiles
|
|
|
|
[ "configuration.nix" ]
|
2024-07-19 00:33:09 +02:00
|
|
|
configuration)
|
2024-07-19 00:06:58 +02:00
|
|
|
(hasDirectories
|
|
|
|
[ "home" ]
|
2024-07-19 00:33:09 +02:00
|
|
|
configuration)
|
2024-07-19 00:06:58 +02:00
|
|
|
])
|
2024-07-19 00:33:09 +02:00
|
|
|
(system: host: configuration:
|
2024-07-19 00:06:58 +02:00
|
|
|
mkNixDarwinHost
|
|
|
|
../machines/nix-darwin/${system}/${host}
|
|
|
|
system
|
|
|
|
host
|
|
|
|
(builtins.map
|
|
|
|
(lib.strings.removeSuffix ".nix")
|
2024-07-19 00:33:09 +02:00
|
|
|
(builtins.attrNames (configuration."home" or { }))))
|
2024-07-19 00:06:58 +02:00
|
|
|
config.flake.nixDarwinMachines;
|
|
|
|
|
|
|
|
homeConfigurations =
|
|
|
|
createConfigurations
|
2024-07-19 00:33:09 +02:00
|
|
|
(system: host: configuration:
|
2024-07-19 00:06:58 +02:00
|
|
|
and
|
|
|
|
[
|
|
|
|
(hasFiles
|
|
|
|
[ "home.nix" ]
|
2024-07-19 00:33:09 +02:00
|
|
|
configuration)
|
2024-07-19 00:06:58 +02:00
|
|
|
])
|
2024-07-19 00:33:09 +02:00
|
|
|
(system: host: configuration:
|
2024-07-19 00:06:58 +02:00
|
|
|
mkHomeManagerHost
|
|
|
|
../machines/home-manager/${system}/${host}
|
|
|
|
system
|
|
|
|
host)
|
|
|
|
config.flake.homeManagerMachines;
|
|
|
|
};
|
|
|
|
}
|