finally resovled container options

This commit is contained in:
Tigor Hutasuhut 2024-06-13 00:50:38 +07:00
parent 544ea1236d
commit 46f4a0ee48
10 changed files with 98 additions and 10 deletions

View file

@ -6,5 +6,6 @@
type = lib.types.bool; type = lib.types.bool;
default = true; default = true;
}; };
kavita.enable = lib.mkEnableOption "kavita docker";
}; };
} }

View file

@ -6,5 +6,6 @@
type = lib.types.bool; type = lib.types.bool;
default = true; default = true;
}; };
kavita.enable = lib.mkEnableOption "kavita docker";
}; };
} }

View file

@ -17,17 +17,20 @@
audio.enable = false; audio.enable = false;
security.sudo.wheelNeedsPassword = false; security.sudo.wheelNeedsPassword = false;
podman = {
enable = false;
};
openssh.enable = true; openssh.enable = true;
go.enable = true; go.enable = true;
networking.firewall.enable = true; networking.firewall.enable = true;
networking.firewall.allowedTCPPorts = [ 80 443 ]; networking.firewall.allowedTCPPorts = [ 80 443 ];
cockpit.enable = false; cockpit.enable = true;
docker = { docker = {
enable = false;
caddy.enable = false;
kavita.enable = false;
};
podman = {
enable = true; enable = true;
caddy.enable = true; caddy.enable = false;
kavita.enable = true;
}; };
}; };
} }

View file

@ -4,7 +4,7 @@
profile-path profile-path
hardware-configuration hardware-configuration
./modules ./modules
# ./podman ./podman
./docker ./docker
./programs.nix ./programs.nix
./user.nix ./user.nix

View file

@ -11,5 +11,6 @@ in
imports = [ imports = [
./caddy.nix ./caddy.nix
./kavita.nix
]; ];
} }

32
system/docker/kavita.nix Normal file
View file

@ -0,0 +1,32 @@
{ config, lib, ... }:
let
user = config.profile.user;
docker = config.profile.docker;
volume = "/nas/kavita";
image = "lscr.io/linuxserver/kavita:latest";
gid = toString user.gid;
uid = toString user.uid;
in
{
config = lib.mkIf (docker.enable && docker.kavita.enable) {
system.activationScripts.docker-kavita = ''
mkdir -p ${volume}
chown -R ${user.name}:${gid} ${volume}
'';
virtualisation.oci-containers.containers.kavita = {
inherit image;
environment = {
PUID = uid;
PGID = gid;
TZ = "Asia/Jakarta";
};
ports = [ "5000:5000" ];
autoStart = true;
volumes = [
"${volume}/config:/config"
"${volume}/library:/library"
];
};
};
}

View file

@ -7,6 +7,9 @@ in
environment.systemPackages = lib.mkIf config.profile.podman.enable [ environment.systemPackages = lib.mkIf config.profile.podman.enable [
(pkgs.callPackage ../packages/cockpit-podman.nix { }) (pkgs.callPackage ../packages/cockpit-podman.nix { })
]; ];
services.caddy.virtualHosts."cockpit.tigor.web.id".extraConfig = ''
reverse_proxy 0.0.0.0:9090
'';
services.udisks2.enable = true; services.udisks2.enable = true;
services.cockpit = { services.cockpit = {
enable = true; enable = true;

View file

@ -31,10 +31,6 @@ in
extraOptions = [ extraOptions = [
"--network=caddy" "--network=caddy"
]; ];
labels = {
"caddy" = "cockpit.tigor.web.id";
"caddy.reverse_proxy" = "hosts.container.internal:9090";
};
}; };
}; };
}; };

View file

@ -4,6 +4,7 @@ let
in in
{ {
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
services.caddy.enable = true;
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [
dive # look into docker image layers dive # look into docker image layers
podman-tui # status of containers in the terminal podman-tui # status of containers in the terminal
@ -28,5 +29,6 @@ in
imports = [ imports = [
./caddy.nix ./caddy.nix
./kavita.nix
]; ];
} }

49
system/podman/kavita.nix Normal file
View file

@ -0,0 +1,49 @@
{ config, lib, pkgs, ... }:
let
user = config.profile.user;
podman = config.profile.podman;
volume = "/nas/kavita";
image = "lscr.io/linuxserver/kavita:latest";
gid = toString user.gid;
uid = toString user.uid;
gateway = "10.1.1.1";
subnet = "10.1.1.0/24";
ip = "10.1.1.3";
ip-range = "10.1.1.3/25";
in
{
config = lib.mkIf (podman.enable && podman.kavita.enable) {
services.caddy.virtualHosts."kavita.tigor.web.id".extraConfig = ''
reverse_proxy ${ip}:5000
'';
systemd.services.create-kavita-network = with config.virtualisation.oci-containers; {
serviceConfig.Type = "oneshot";
wantedBy = [ "${backend}-kavita.service" ];
script = ''${pkgs.podman}/bin/podman network exists kavita || ${pkgs.podman}/bin/podman network create --gateway=${gateway} --subnet=${subnet} --ip-range=${ip-range} kavita'';
};
system.activationScripts.docker-kavita = ''
mkdir -p ${volume}
chown -R ${user.name}:${gid} ${volume}
'';
virtualisation.oci-containers.containers.kavita = {
inherit image;
environment = {
PUID = uid;
PGID = gid;
TZ = "Asia/Jakarta";
};
extraOptions = [
"--network=kavita"
"--ip=${ip}"
];
autoStart = true;
volumes = [
"${volume}/config:/config"
"${volume}/library:/library"
];
};
};
}