nixos_config/hosts/tesla-nixos/configuration.nix

177 lines
5.7 KiB
Nix
Raw Normal View History

2025-08-12 21:00:01 +02:00
{ config, pkgs, ... }:
{
2025-09-29 15:56:43 +02:00
security.sudo.wheelNeedsPassword = false;
2025-08-12 21:00:01 +02:00
imports =
[ ./hardware-configuration.nix ];
networking.hostName = "tesla-nixos";
boot.initrd.enable = true;
boot.loader = {
systemd-boot = {
enable = true;
}; # end loader.systemd-boot
}; # end boot
2025-09-24 18:23:45 +02:00
virtualisation.oci-containers.containers = {
isponsorblocktv = {
image = "ghcr.io/dmunozv04/isponsorblocktv:latest";
autoStart = true;
volumes = [
2025-09-24 18:33:20 +02:00
"/home/alisceon/isponsorblocktv:/app/data"
2025-09-24 18:31:24 +02:00
];
2025-09-24 18:23:45 +02:00
}; # end isponsorblocktv
};
2025-09-29 11:23:45 +02:00
boot.kernel.sysctl = {
"kernel.unprivileged_userns_clone" = 1;
};
# Persist GitLab Runner state on the host (tokens, cache, builds)
# so the container can be rebuilt without losing registration.
systemd.tmpfiles.rules = [
"d /var/lib/gitlab-runner 0755 root root -"
];
2025-09-29 16:06:47 +02:00
containers.gitlab-runner = {
2025-09-29 11:23:45 +02:00
autoStart = true;
ephemeral = false;
# Keep networking simple. If you want isolation, set privateNetwork = true
# and configure veth/bridge. With false it shares the host network namespace.
privateNetwork = false;
# Podman rootless uses fuse-overlayfs → /dev/fuse must be available
allowedDevices = [
{ node = "/dev/fuse"; modifiers = [ "rwm" ]; }
];
# Persist runners home/state and optionally cache
bindMounts = {
"/var/lib/gitlab-runner" = {
hostPath = "/var/lib/gitlab-runner";
isReadOnly = false;
};
# Optional: a big builds/cache dir for job artifacts
"/var/lib/gitlab-runner/builds" = {
hostPath = "/var/lib/gitlab-runner/builds";
isReadOnly = false;
create = true;
};
"/var/lib/gitlab-runner/cache" = {
hostPath = "/var/lib/gitlab-runner/cache";
isReadOnly = false;
create = true;
};
};
# The container runs its own NixOS config below:
config = { config, pkgs, lib, ... }: {
imports = [ ];
networking.hostName = "ci-nspawn";
time.timeZone = "UTC";
# GitLab Runner user (will run jobs and the user-scoped Podman API)
users.users.gitlab-runner = {
isSystemUser = true;
# keep home on the persistent mount
home = "/var/lib/gitlab-runner";
createHome = true;
shell = pkgs.bashInteractive;
extraGroups = [ "podman" "wheel" ];
2025-09-29 16:27:22 +02:00
group = "gitlab-runner";
2025-09-29 11:23:45 +02:00
};
2025-09-29 16:28:59 +02:00
users.groups.gitlab-runner = { };
2025-09-29 11:23:45 +02:00
users.groups.podman = { };
2025-09-24 18:23:45 +02:00
2025-09-29 11:23:45 +02:00
# Rootless Podman
virtualisation.podman = {
enable = true;
defaultNetwork.settings.dns_enabled = true;
};
environment.systemPackages = with pkgs; [
podman
fuse-overlayfs
slirp4netns
crun
skopeo
git
];
# Ensure /etc/subuid /etc/subgid exist for rootless user namespace
environment.etc."subuid".text = ''
gitlab-runner:100000:65536
'';
environment.etc."subgid".text = ''
gitlab-runner:100000:65536
'';
# Run a *user*-scoped Podman API service so GitLab Runner can talk to it.
# The socket ends up at: /run/user/<UID>/podman/podman.sock
# We keep it always-on via linger below.
systemd.user.services."podman-api" = {
description = "Podman API (rootless)";
serviceConfig = {
ExecStart = "${pkgs.podman}/bin/podman system service --time=0";
Restart = "always";
};
2025-09-29 16:37:42 +02:00
wantedBy = [ "default.target" ];
2025-09-29 11:23:45 +02:00
};
# Make the user session available at boot (so the user service can run)
# This is the NixOS way to call `loginctl enable-linger gitlab-runner`.
systemd.services."enable-linger-gitlab-runner" = {
description = "Enable linger for gitlab-runner";
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "oneshot";
ExecStart = "${pkgs.systemd}/bin/loginctl enable-linger gitlab-runner";
# Harmless if already enabled
RemainAfterExit = true;
};
};
# GitLab Runner
services.gitlab-runner = {
enable = true;
2025-09-29 16:12:43 +02:00
services = {
ci-nspawn-rootless-podman = {
# Prefer auth tokens (GitLab 18 deprecates registration tokens)
# Put CI_SERVER_URL and CI_SERVER_TOKEN into this file (ENV format).
authenticationTokenConfigFile = "/var/lib/gitlab-runner/token-env";
# …or, if you still use a registration token:
# registrationConfigFile = "/var/lib/gitlab-runner/registration.env";
executor = "docker"; # use Docker executor against Podman
2025-09-29 11:23:45 +02:00
dockerImage = "alpine:3";
2025-09-29 16:12:43 +02:00
dockerPrivileged = true; # tighten later if you can
2025-09-29 11:23:45 +02:00
dockerVolumes = [
"/var/lib/gitlab-runner/cache:/cache"
];
2025-09-29 16:40:30 +02:00
environmentVariables = {
DOCKER_HOST = "unix:///run/user/2100/podman/podman.sock";
};
2025-09-29 16:12:43 +02:00
}; # end services.ci-nspawn-rootless-podman
}; # end services.gitlab-runner
}; # end containers.ci.config
2025-09-29 11:23:45 +02:00
# Make sure systemd + cgroups are fully available inside the container
systemd.oomd.enable = false; # avoids noise in small containers
services.dbus.enable = true;
# Storage tuning for rootless overlay
environment.etc."containers/storage.conf".text = ''
[storage]
driver = "overlay"
runroot = "/run/user/1000/containers" # will be per-user anyway
graphroot = "/var/lib/gitlab-runner/.local/share/containers/storage"
[storage.options]
mount_program = "${pkgs.fuse-overlayfs}/bin/fuse-overlayfs"
additionalimagestores = []
'';
2025-09-29 16:22:54 +02:00
}; # end containers.gitlab-runner.config
}; # end containers.gitlab-runner
2025-08-12 21:00:01 +02:00
} # end file
2025-09-29 11:23:45 +02:00