From 428baed6cf2edcc9b8786e71bf708ed026b79d32 Mon Sep 17 00:00:00 2001 From: Christopher Bacher Date: Fri, 28 Oct 2022 18:51:18 +0200 Subject: [PATCH] flake(linger): add linger-flaker to allow the pihole-flake to manage user lingering Systemd's user lingering feature seems to be necessary to run rootless podman if the executing user is not logged in. See https://github.com/NixOS/nixpkgs/issues/138423 --- flake.nix | 10 ++++++++-- modules/pihole-container.factory.nix | 7 ++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 2b3fbcc..c425d5e 100644 --- a/flake.nix +++ b/flake.nix @@ -5,9 +5,11 @@ nixpkgs.url = "nixpkgs/nixpkgs-unstable"; flake-utils.url = "github:numtide/flake-utils"; + + linger.url = "github:mindsbackyard/linger-flake"; }; - outputs = { self, nixpkgs, flake-utils }: with flake-utils.lib; eachSystem (with system; [ x86_64-linux aarch64-linux ]) (curSystem: + outputs = { self, nixpkgs, flake-utils, linger }: with flake-utils.lib; eachSystem (with system; [ x86_64-linux aarch64-linux ]) (curSystem: let util = import ./lib/util.nix; pkgs = nixpkgs.legacyPackages.${curSystem}; @@ -34,7 +36,11 @@ default = piholeImage; }; - nixosModules.default = (import ./modules/pihole-container.factory.nix) { piholeFlake = self; inherit util; }; + nixosModules.default = (import ./modules/pihole-container.factory.nix) { + piholeFlake = self; + lingerFlake = linger; + inherit util; + }; devShells.default = let updatePiholeImageInfoScript = pkgs.writeShellScriptBin "update-pihole-image-info" '' diff --git a/modules/pihole-container.factory.nix b/modules/pihole-container.factory.nix index 1de525c..dbac385 100644 --- a/modules/pihole-container.factory.nix +++ b/modules/pihole-container.factory.nix @@ -1,4 +1,4 @@ -{ piholeFlake, util }: { config, pkgs, lib, ... }: with lib; with builtins; let +{ piholeFlake, lingerFlake, util }: { config, pkgs, lib, ... }: with lib; with builtins; let inherit (util) collectAttrFragments accessValueOfFragment toEnvValue; cfg = config.services.pihole; @@ -320,6 +320,11 @@ in rec { Set it to "suppressWarning" if you manage lingering in a different way. ''); + services.linger = mkIf (cfg.hostConfig.enableLingeringForUser == true) { + enable = true; + users = [ cfg.hostConfig.user ]; + }; + systemd.services."pihole-rootless-container" = { wantedBy = [ "multi-user.target" ]; after = [ "network-online.target" ];