Move to different structure

main
kalle 2024-12-26 17:22:00 +01:00
parent 05c996db50
commit bcec9a18c3
6 changed files with 105 additions and 9 deletions

4
config.nix Normal file
View File

@ -0,0 +1,4 @@
{
domain = "staging.kallestruik.nl";
shortDomain = "khs.li";
}

View File

@ -11,11 +11,14 @@
let let
outputs = self.outputs; outputs = self.outputs;
utils = import ./utils.nix { inherit nixpkgs inputs outputs; }; utils = import ./utils.nix { inherit nixpkgs inputs outputs; };
homelabConfig = import ./config.nix;
roles = import ./roles { inherit utils; };
hosts = import ./hosts.nix { inherit homelabConfig roles; };
in in
{ {
nixosConfigurations = { nixosConfigurations = nixpkgs.lib.mapAttrs (
"base" = utils.mkSystem [ ]; hostname: value: (utils.mkSystem value // { inherit hostname; })
"nix-test" = utils.mkSystem [ ./systems/nix-test.nix ]; ) hosts;
};
}; };
} }

25
hosts.nix Normal file
View File

@ -0,0 +1,25 @@
{
roles,
homelabConfig,
...
}:
let
hlConfig = homelabConfig;
in
{
base = {
roles = [ ];
config = { };
stateVersion = "24.05";
};
nix-test = {
roles = with roles; [
sonarr
];
config = {
sonarr.domain = "sonarr.${hlConfig.domain}";
};
stateVersion = "24.05";
};
}

6
roles/default.nix Normal file
View File

@ -0,0 +1,6 @@
{
utils,
}:
{
sonarr = utils.mkRole (import ./sonarr.nix);
}

43
roles/sonarr.nix Normal file
View File

@ -0,0 +1,43 @@
{
name = "Sonarr";
description = ''
Sonarr PVR
'';
traefikRoutes =
{
hostname,
config,
...
}:
[
{
name = "${hostname}-sonarr";
rule = "Host(`${config.sonarr.domain}`)";
target = "http://${hostname}.lan:8989";
}
];
nixosModules =
{ lib, ... }:
{
options.sonarr = {
domain = lib.mkOption {
type = lib.types.listOf lib.types.str;
};
};
config = {
# Enable the sonarr service
services.sonarr = {
enable = true;
openFirewall = true;
group = "media";
};
# Ensure that the media group exists
users.groups.media = { };
};
};
}

View File

@ -6,15 +6,30 @@
}: }:
{ {
mkSystem = mkSystem =
configs: hostConfig:
nixpkgs.lib.nixosSystem { nixpkgs.lib.nixosSystem {
system = "x86_64-linux"; system = "x86_64-linux";
specialArgs = { specialArgs = {
inherit inputs outputs; inherit inputs outputs hostConfig;
}; };
modules = [ modules = [
inputs.impermanence.nixosModules.impermanence inputs.impermanence.nixosModules.impermanence
./systems/base/configuration.nix # inputs.sops-nix.nixosModules.sops
] ++ configs;
./systems/base/configuration.nix
(
{ ... }:
{
networking.hostName = hostConfig.hostname;
system.stateVersion = hostConfig.stateVersion;
}
)
({ ... }: hostConfig.config)
] ++ builtins.map (role: role.nixosModule) hostConfig.roles;
}; };
mkRole = cfg: {
inherit (cfg) name description nixosModule;
traefikRoutes = cfg.traefikRoutes or ({ ... }: [ ]);
};
} }