refactor(flake)!: machines
-> hosts
This commit is contained in:
parent
703cd0264b
commit
a881c5d7e1
33 changed files with 52 additions and 45 deletions
|
@ -36,7 +36,6 @@
|
|||
# keep-derivations = true
|
||||
# '';
|
||||
|
||||
|
||||
settings = {
|
||||
# Enable flakes and new 'nix' command
|
||||
experimental-features = [
|
|
@ -12,9 +12,16 @@
|
|||
./mindustry.nix
|
||||
# ./home-assistant
|
||||
./samba.nix
|
||||
# ./steam.nix
|
||||
# ./ollama.nix
|
||||
# ./sunshine.nix
|
||||
# ./photoprism.nix
|
||||
# ./immich.nix
|
||||
# ./nextcloud.nix
|
||||
];
|
||||
|
||||
# services.kanidm = { };
|
||||
|
||||
age.rekey = {
|
||||
hostPubkey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPopSTZ81UyKp9JSljCLp+Syk51zacjh9fLteqxQ6/aB";
|
||||
# masterIdentities = [ "${inputs.self}/secrets/privkey.age" ];
|
|
@ -53,4 +53,6 @@
|
|||
linkConfig.Name = "wan0"; # "wlp15s0";
|
||||
};
|
||||
};
|
||||
|
||||
# systemd.services.systemd-networkd.environment.SYSTEMD_LOG_LEVEL = "debug";
|
||||
}
|
|
@ -1,6 +1,13 @@
|
|||
{ inputs, outputs, lib, pkgs, config, ... }:
|
||||
|
||||
{
|
||||
# age.secrets."nextcloud.adminpass" = {
|
||||
# rekeyFile = "${inputs.self}/secrets/home/jeeves/nextcloud/adminpass.age";
|
||||
# mode = "770";
|
||||
# owner = "nextcloud";
|
||||
# group = "nextcloud";
|
||||
# };
|
||||
|
||||
environment.systemPackages = [
|
||||
# config.services.nextcloud.package
|
||||
];
|
||||
|
@ -10,7 +17,7 @@
|
|||
services.nginx = {
|
||||
enable = true;
|
||||
package = pkgs.openresty;
|
||||
# virtualHosts."_.jeeves.local" = {
|
||||
# virtualHosts."_.${config.networking.hostName}.local" = {
|
||||
# # listen = [
|
||||
# # {
|
||||
# # addr = "127.0.0.1";
|
|
@ -8,9 +8,12 @@ let
|
|||
hasDirectories
|
||||
recurseDir
|
||||
configuration-type-to-outputs-modules
|
||||
configuration-type-to-outputs-machines;
|
||||
configuration-type-to-outputs-hosts;
|
||||
in
|
||||
let
|
||||
# Configuration helpers
|
||||
configurationTypes = ["nixos" "nix-on-droid" "nix-darwin" "home-manager"];
|
||||
|
||||
homeManagerModule = { root, system, hostname, users ? null }: {
|
||||
home-manager = {
|
||||
# Use same `pkgs` instance as system (i.e. carry over overlays)
|
||||
|
@ -30,15 +33,13 @@ let
|
|||
config = "${root}/home.nix";
|
||||
} else {
|
||||
# Not nixOnDroid
|
||||
users = lib.attrsets.genAttrs
|
||||
users
|
||||
users =
|
||||
lib.attrsets.genAttrs
|
||||
users
|
||||
(user: import "${root}/home/${user}.nix");
|
||||
});
|
||||
};
|
||||
|
||||
# Configuration helpers
|
||||
configurationTypes = ["nixos" "nix-on-droid" "nix-darwin" "home-manager"];
|
||||
|
||||
mkNixosHost = args @ { root, system, hostname, users }: lib.nixosSystem {
|
||||
inherit system;
|
||||
pkgs = withSystem system ({ pkgs, ... }: pkgs);
|
||||
|
@ -120,7 +121,7 @@ let
|
|||
};
|
||||
|
||||
createConfigurations =
|
||||
pred: mkHost: machines:
|
||||
pred: mkHost: hosts:
|
||||
lib.foldAttrs
|
||||
lib.const
|
||||
[ ]
|
||||
|
@ -138,7 +139,7 @@ let
|
|||
${host} = mkHost { inherit system host configurationFiles; };
|
||||
})
|
||||
hosts)
|
||||
machines));
|
||||
hosts));
|
||||
in
|
||||
{
|
||||
options = let
|
||||
|
@ -156,8 +157,8 @@ in
|
|||
Base directory of the contained configurations, used as a base for the rest of the options
|
||||
'';
|
||||
type = types.path;
|
||||
default = "${self}/machines";
|
||||
defaultText = ''''${self}/machines'';
|
||||
default = "${self}/hosts";
|
||||
defaultText = ''''${self}/hosts'';
|
||||
};
|
||||
} // (
|
||||
lib.pipe
|
||||
|
@ -194,29 +195,20 @@ in
|
|||
|
||||
config = {
|
||||
flake = let
|
||||
autoMachines =
|
||||
autoHosts =
|
||||
lib.pipe
|
||||
configurationTypes
|
||||
[
|
||||
(builtins.map
|
||||
(configurationType:
|
||||
lib.nameValuePair
|
||||
"${configuration-type-to-outputs-machines configurationType}"
|
||||
(if config.flake.autoConfigurations.${configurationType}.enable
|
||||
then recurseDir config.flake.autoConfigurations.${configurationType}.dir
|
||||
else { })))
|
||||
"${configuration-type-to-outputs-hosts configurationType}"
|
||||
(if config.flake.autoConfigurations.${configurationType}.enable
|
||||
then recurseDir config.flake.autoConfigurations.${configurationType}.dir
|
||||
else { })))
|
||||
builtins.listToAttrs
|
||||
];
|
||||
in {
|
||||
# Machines
|
||||
# NOTE: manually inheriting generated machines to avoid recursion
|
||||
# (`autoMachines` depends on `config.flake` itself)
|
||||
inherit (autoMachines)
|
||||
nixosMachines
|
||||
darwinMachines
|
||||
nixOnDroidMachines
|
||||
homeManagerMachines;
|
||||
|
||||
in autoHosts // {
|
||||
# Configurations
|
||||
nixosConfigurations =
|
||||
createConfigurations
|
||||
|
@ -239,7 +231,7 @@ in
|
|||
(lib.strings.removeSuffix ".nix")
|
||||
(builtins.attrNames (configurationFiles."home" or { })));
|
||||
})
|
||||
config.flake.${configuration-type-to-outputs-machines "nixos"};
|
||||
self.${configuration-type-to-outputs-hosts "nixos"};
|
||||
|
||||
nixOnDroidConfigurations =
|
||||
createConfigurations
|
||||
|
@ -256,7 +248,7 @@ in
|
|||
inherit system;
|
||||
hostname = host;
|
||||
})
|
||||
config.flake.${configuration-type-to-outputs-machines "nix-on-droid"};
|
||||
self.${configuration-type-to-outputs-hosts "nix-on-droid"};
|
||||
|
||||
darwinConfigurations =
|
||||
createConfigurations
|
||||
|
@ -279,7 +271,7 @@ in
|
|||
(lib.strings.removeSuffix ".nix")
|
||||
(builtins.attrNames (configurationFiles."home" or { })));
|
||||
})
|
||||
config.flake.${configuration-type-to-outputs-machines "nix-darwin"};
|
||||
self.${configuration-type-to-outputs-hosts "nix-darwin"};
|
||||
|
||||
homeConfigurations =
|
||||
createConfigurations
|
||||
|
@ -296,7 +288,7 @@ in
|
|||
inherit system;
|
||||
hostname = host;
|
||||
})
|
||||
config.flake.${configuration-type-to-outputs-machines "home-manager"};
|
||||
self.${configuration-type-to-outputs-hosts "home-manager"};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
let
|
||||
inherit (import ../../nix/utils.nix { inherit lib self; })
|
||||
accumulateMachines
|
||||
accumulateHosts
|
||||
configuration-type-to-deploy-type;
|
||||
in
|
||||
{
|
||||
flake = {
|
||||
deploy.nodes =
|
||||
accumulateMachines
|
||||
accumulateHosts
|
||||
# TODO: nix-on-droid
|
||||
["nixos" "nix-darwin"]
|
||||
({ host, system, configuration-type, configuration }:
|
||||
|
|
|
@ -55,19 +55,19 @@ rec {
|
|||
(builtins.throw
|
||||
(mkError configuration-type));
|
||||
|
||||
# TODO: abstract away `_Machines` and `_Modules`
|
||||
# TODO: abstract away `_Hosts` and `_Modules`
|
||||
|
||||
configuration-type-to-outputs-machines =
|
||||
configuration-type-to-outputs-hosts =
|
||||
gen-configuration-type-to
|
||||
{
|
||||
nixos = "nixosMachines";
|
||||
nix-on-droid = "nixOnDroidMachines";
|
||||
nix-darwin = "darwinMachines";
|
||||
home-manager = "homeManagerMachines";
|
||||
nixos = "nixosHosts";
|
||||
nix-on-droid = "nixOnDroidHosts";
|
||||
nix-darwin = "darwinHosts";
|
||||
home-manager = "homeManagerHosts";
|
||||
}
|
||||
(configuration-type:
|
||||
builtins.throw
|
||||
"Invaild configuration-type \"${configuration-type}\" for flake outputs' machines");
|
||||
"Invaild configuration-type \"${configuration-type}\" for flake outputs' hosts");
|
||||
|
||||
configuration-type-to-outputs-modules =
|
||||
gen-configuration-type-to
|
||||
|
@ -104,18 +104,18 @@ rec {
|
|||
builtins.throw
|
||||
"Invaild configuration-type \"${configuration-type}\" for deploy-rs deployment");
|
||||
|
||||
accumulateMachines = configuration-types: host-system-configuration-type-configuration-fn:
|
||||
accumulateHosts = configuration-types: host-system-configuration-type-configuration-fn:
|
||||
lib.flip lib.concatMapAttrs
|
||||
(lib.genAttrs
|
||||
configuration-types
|
||||
(configuration-type:
|
||||
let
|
||||
machines = configuration-type-to-outputs-machines configuration-type;
|
||||
hosts = configuration-type-to-outputs-hosts configuration-type;
|
||||
in
|
||||
self.${machines}))
|
||||
(configuration-type: machines:
|
||||
self.${hosts}))
|
||||
(configuration-type: hosts:
|
||||
lib.pipe
|
||||
machines
|
||||
hosts
|
||||
[
|
||||
# Filter out nondirectories
|
||||
(lib.filterAttrs
|
||||
|
|
Loading…
Reference in a new issue