diff --git a/config.nix b/config.nix new file mode 100644 index 0000000..2748b17 --- /dev/null +++ b/config.nix @@ -0,0 +1,4 @@ +{ + domain = "staging.kallestruik.nl"; + shortDomain = "khs.li"; +} diff --git a/flake.nix b/flake.nix index 3fcaed7..8cd8b2b 100644 --- a/flake.nix +++ b/flake.nix @@ -11,11 +11,14 @@ let outputs = self.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 { - nixosConfigurations = { - "base" = utils.mkSystem [ ]; - "nix-test" = utils.mkSystem [ ./systems/nix-test.nix ]; - }; + nixosConfigurations = nixpkgs.lib.mapAttrs ( + hostname: value: (utils.mkSystem value // { inherit hostname; }) + ) hosts; }; } diff --git a/hosts.nix b/hosts.nix new file mode 100644 index 0000000..b670336 --- /dev/null +++ b/hosts.nix @@ -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"; + }; +} diff --git a/roles/default.nix b/roles/default.nix new file mode 100644 index 0000000..5f6a13a --- /dev/null +++ b/roles/default.nix @@ -0,0 +1,6 @@ +{ + utils, +}: +{ + sonarr = utils.mkRole (import ./sonarr.nix); +} diff --git a/roles/sonarr.nix b/roles/sonarr.nix new file mode 100644 index 0000000..1353892 --- /dev/null +++ b/roles/sonarr.nix @@ -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 = { }; + }; + }; +} diff --git a/utils.nix b/utils.nix index 1d821d5..fcf98e1 100644 --- a/utils.nix +++ b/utils.nix @@ -6,15 +6,30 @@ }: { mkSystem = - configs: + hostConfig: nixpkgs.lib.nixosSystem { system = "x86_64-linux"; specialArgs = { - inherit inputs outputs; + inherit inputs outputs hostConfig; }; - modules = [ + modules = [ inputs.impermanence.nixosModules.impermanence - ./systems/base/configuration.nix - ] ++ configs; + # inputs.sops-nix.nixosModules.sops + + ./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 ({ ... }: [ ]); + }; }