From 1a64deeb894dc95e2645a75771732c6cc53a79ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Wed, 4 Oct 2023 01:35:06 +0200 Subject: Squash changes containing private information There were a lot of changes since the previous commit, but a lot of them contained personnal information about users. All thos changes got stashed into a single commit (history is kept in a different place) and private information was moved in a separate private repository --- flakes/loginctl-linger/flake.nix | 56 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 flakes/loginctl-linger/flake.nix (limited to 'flakes/loginctl-linger') diff --git a/flakes/loginctl-linger/flake.nix b/flakes/loginctl-linger/flake.nix new file mode 100644 index 0000000..4828d37 --- /dev/null +++ b/flakes/loginctl-linger/flake.nix @@ -0,0 +1,56 @@ +{ + outputs = { self }: { + nixosModule = { 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 + + { + # Necessary for situations where flake gets included multiple times + key = builtins.hashString "sha256" (builtins.path { path = self.sourceInfo.outPath; name = "source"; }); + options = { + users.users = mkOption { + type = lib.types.attrsOf (lib.types.submodule { + options = { + linger = mkEnableOption "lingering for the user"; + }; + }); + }; + }; + + config = { + system.activationScripts.update-lingering = { + deps = ["users"]; + text = "${updateLingering}"; + }; + }; + }; + }; +} -- cgit v1.2.3