X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FConfig%2FNix.git;a=blobdiff_plain;f=modules%2Fprivate%2Floginctl-linger.nix;fp=modules%2Fprivate%2Floginctl-linger.nix;h=0000000000000000000000000000000000000000;hp=e6b9f23774238a4c7831f0e1a2a2b9ab5c4466c2;hb=1a64deeb894dc95e2645a75771732c6cc53a79ad;hpb=fa25ffd4583cc362075cd5e1b4130f33306103f0 diff --git a/modules/private/loginctl-linger.nix b/modules/private/loginctl-linger.nix deleted file mode 100644 index e6b9f23..0000000 --- a/modules/private/loginctl-linger.nix +++ /dev/null @@ -1,47 +0,0 @@ -{ config, lib, pkgs, ... }: - -# https://github.com/michalrus/dotfiles/commit/ebd5fa9583f82589f23531647aa677feb3f8d344#diff-4d353005ef5b3e37f33c07332b8523edR1 -# A temporary hack to `loginctl enable-linger $somebody` (for -# multiplexer sessions to last), until this one is unresolved: -# https://github.com/NixOS/nixpkgs/issues/3702 -# -# Usage: `users.extraUsers.somebody.linger = true` or slt. - -with lib; - -let - - dataDir = "/var/lib/systemd/linger"; - - lingeringUsers = map (u: u.name) (attrValues (flip filterAttrs config.users.users (n: u: u.linger))); - - lingeringUsersFile = builtins.toFile "lingering-users" - (concatStrings (map (s: "${s}\n") - (sort (a: b: a < b) lingeringUsers))); # this sorting is important for `comm` to work correctly - - updateLingering = pkgs.writeScript "update-lingering" '' - if [ ! -e ${dataDir} ]; then - install -m 0755 -o root -g root -d ${dataDir} - fi - if [ -e ${dataDir} ] ; then - ls ${dataDir} | sort | comm -3 -1 ${lingeringUsersFile} - | xargs -r ${pkgs.systemd}/bin/loginctl disable-linger - ls ${dataDir} | sort | comm -3 -2 ${lingeringUsersFile} - | xargs -r ${pkgs.systemd}/bin/loginctl enable-linger - fi - ''; - -in - -{ - options = { - users.users = mkOption { - options = [{ - linger = mkEnableOption "lingering for the user"; - }]; - }; - }; - - config = { - system.activationScripts.update-lingering = - stringAfter [ "users" ] updateLingering; - }; -}