diff --git a/host.nix b/host.nix index 5365f46..d0fe5a6 100644 --- a/host.nix +++ b/host.nix @@ -1,30 +1,39 @@ { pkgs, ... }: -let gitea = { - host = "10.10.0.1"; - local = "10.10.0.2"; - }; - secrets = import ./secrets/secrets.nix; +let secrets = import ./secrets/secrets.nix; + services = import ./services.nix; + lib = import ./lib.nix; in + +lib.foldMap ({ name, ip, config, ... }: { - # [CONTAINERS] - containers.gitea = { + containers.${name} = { autoStart = true; ephemeral = true; privateNetwork = true; - hostAddress = gitea.host; - localAddress = gitea.local; - config = ./guests/gitea.nix; + hostAddress = ip.host; + localAddress = ip.local; + config = config; }; +} +) services +// + +{ # [NGINX] services.nginx = { enable = true; recommendedProxySettings = true; - virtualHosts = { - "localhost" = { - locations."/".proxyPass = "http://${gitea.local}:3001"; - }; - }; + virtualHosts = + lib.foldMap ({ ip, port, hosts, ... }: + lib.foldMap (host: + { + "${host}" = { + locations."/".proxyPass = "http://${ip.local}:${builtins.toString port}"; + }; + } + ) hosts + ) services; }; # [NETWORK] @@ -32,12 +41,12 @@ in networking.firewall.allowedUDPPorts = [ ]; # VM test user - users.users.admin.isSystemUser = true ; - users.users.admin.hashedPassword = builtins.readFile ./secrets/admin_password; + users.users.admin.isNormalUser = true; + users.users.admin.hashedPassword = pkgs.lib.removeSuffix "\n" + (builtins.readFile ./secrets/admin_password); users.users.admin.group = "admin"; users.groups.admin = {}; - system.stateVersion = "23.11"; } diff --git a/lib.nix b/lib.nix new file mode 100644 index 0000000..f0185b0 --- /dev/null +++ b/lib.nix @@ -0,0 +1,3 @@ +{ + foldMap = (f: list: builtins.foldl' (acc: elem: acc // elem) {} (builtins.map f list)); +} diff --git a/services.nix b/services.nix new file mode 100644 index 0000000..1e41e3b --- /dev/null +++ b/services.nix @@ -0,0 +1,14 @@ +# List of attrsets defining +# name, ip.host, ip.local, config, hosts +[ + { + name = "gitea"; + ip = { + host = "10.10.0.1"; + local = "10.10.0.2"; + }; + config = ./guests/gitea.nix; + port = 3001; + hosts = [ "localhost" ]; + } +]