dotfiles/hosts/default.nix

92 lines
2.9 KiB
Nix
Raw Normal View History

2023-06-18 00:46:31 +00:00
{
nixpkgs,
agenix,
home-manager,
flake-utils,
nixgl,
rust-overlay,
flake-compat,
pkgs,
lib,
proj_root,
nixosDefaultVersion ? "22.05",
defaultSystem ? "x86_64-linux",
...
} @ finalInputs: let
2023-01-13 06:42:21 +00:00
config = {
bao.metadata = {
# req
hostName = "bao";
# opts
ssh_pubkey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIBuAaAE7TiQmMH300VRj/pYCri1qPmHjd+y9aX2J0Fs";
nixosVersion = "22.11";
system = "x86_64-linux";
preset = "base";
};
# TODO: add override so that we can add wsl config on top
bao.nixosConfig = {
modules = [
(import ../modules/nvgpu.sys.nix)
(import ../modules/kde.sys.nix)
(import ../modules/pulseaudio.sys.nix)
(import ../modules/storage.perso.sys.nix)
];
};
2022-12-27 04:22:07 +00:00
};
2023-06-18 00:46:31 +00:00
propagate = hostConfig @ {
metadata,
nixosConfig,
}: let
# req
inherit (metadata) hostName;
# opts
ssh_pubkey = lib.attrByPath ["ssh_pubkey"] null metadata; # metadata.ssh_pubkey??undefined
users = lib.attrByPath ["users"] {} metadata;
nixosVersion = lib.attrByPath ["nixosVersion"] nixosDefaultVersion metadata;
system = lib.attrByPath ["system"] defaultSystem metadata;
preset = lib.attrByPath ["preset"] "base" metadata;
# infer
hardwareConfig = import "${proj_root.hosts.path}/${hostName}/hardware-configuration.nix";
# alias to prevent infinite recursion
_nixosConfig = nixosConfig;
in {
inherit hostName ssh_pubkey users nixosVersion system preset hardwareConfig;
nixosConfig =
_nixosConfig
// {
2023-01-13 06:42:21 +00:00
inherit system;
2023-06-18 00:46:31 +00:00
modules =
[
{
config._module.args = {
inherit proj_root;
my-lib = finalInputs.lib;
};
}
hardwareConfig
{
system.stateVersion = nixosVersion;
networking.hostName = hostName;
users.users = users;
}
{
imports = [agenix.nixosModule];
environment.systemPackages = [agenix.defaultPackage.x86_64-linux];
}
(import "${proj_root.modules.path}/secrets.nix")
(import "${proj_root.modules.path}/${preset}.sys.nix")
]
++ _nixosConfig.modules;
2023-01-13 06:42:21 +00:00
};
2023-06-18 00:46:31 +00:00
};
2023-01-13 06:42:21 +00:00
# we are blessed by the fact that we engulfed nixpkgs.lib.* at top level
2023-06-18 00:46:31 +00:00
mkHostFromPropagated = propagatedHostConfig @ {nixosConfig, ...}: nixpkgs.lib.nixosSystem nixosConfig;
mkHost = hostConfig: (lib.pipe [propagate mkHostFromPropagated] hostConfig);
2023-01-13 06:42:21 +00:00
trimNull = lib.filterAttrsRecursive (name: value: value != null);
flattenPubkey = lib.mapAttrs (hostName: meta_config: meta_config.metadata.ssh_pubkey);
2023-06-18 00:46:31 +00:00
in {
2023-01-12 17:50:46 +00:00
nixosConfigurations = lib.mapAttrs (name: hostConfig: mkHost hostConfig) config;
# {bao = "ssh-ed25519 ..."; another_host = "ssh-rsa ...";}
2022-12-27 10:47:58 +00:00
pubKeys = lib.getPubkey config;
2023-01-14 13:04:43 +00:00
}