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
This commit is contained in:
Christopher Bacher 2022-10-28 18:51:18 +02:00
parent 5fb27f33b3
commit 428baed6cf
2 changed files with 14 additions and 3 deletions

View file

@ -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" ''

View file

@ -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" ];