From 7174f824d6c99b27e43af04129f0d7661e18c5d8 Mon Sep 17 00:00:00 2001 From: Christopher Bacher Date: Sun, 9 Oct 2022 19:05:10 +0200 Subject: [PATCH] module(pihole-container): make it a module factory; WIP: start adding systemd service The factory function returns the pihole module and allows to pass the flake itself to refer to its outputs. --- flake.nix | 2 +- ...ntainer.nix => pihole-container.factory.nix} | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) rename modules/{pihole-container.nix => pihole-container.factory.nix} (95%) diff --git a/flake.nix b/flake.nix index 95fbbae..4878c22 100644 --- a/flake.nix +++ b/flake.nix @@ -34,7 +34,7 @@ default = piholeImage; }; - nixosModule = import ./modules/pihole-container.nix; + nixosModules.default = import ./modules/pihole-container.factory.nix { piholeFlake = self; }; devShells.default = let updatePiholeImageInfoScript = pkgs.writeShellScriptBin "update-pihole-image-info" '' diff --git a/modules/pihole-container.nix b/modules/pihole-container.factory.nix similarity index 95% rename from modules/pihole-container.nix rename to modules/pihole-container.factory.nix index 536ed91..2d9fc26 100644 --- a/modules/pihole-container.nix +++ b/modules/pihole-container.factory.nix @@ -1,4 +1,6 @@ -{ config, pkgs, lib, ... }: with lib; let +{ piholeFlake }: { config, pkgs, lib, ... }: with lib; let + cfg = config.services.piholeRootlessContainer; + mkHostPortsOption = { service, publicDefaultPort }: { host-internal-port = mkOption { type = types.port; @@ -235,6 +237,17 @@ in { }; }; - config = { + config = mkIf cfg.enable { + systemd.services."pihole-rootless-container" = { + serviceConfig = { + ExecStart = '' + ${pkgs.podman}/bin/podman run \ + --rm \ + --rmi \ + docker-archive:${self.packages.piholeImage} + ''; + User = null; + }; + }; }; }