diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2023-10-04 01:35:06 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2023-10-04 02:11:48 +0200 |
commit | 1a64deeb894dc95e2645a75771732c6cc53a79ad (patch) | |
tree | 1b9df4838f894577a09b9b260151756272efeb53 /flakes/loginctl-linger | |
parent | fa25ffd4583cc362075cd5e1b4130f33306103f0 (diff) | |
download | Nix-1a64deeb894dc95e2645a75771732c6cc53a79ad.tar.gz Nix-1a64deeb894dc95e2645a75771732c6cc53a79ad.tar.zst Nix-1a64deeb894dc95e2645a75771732c6cc53a79ad.zip |
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
Diffstat (limited to 'flakes/loginctl-linger')
-rw-r--r-- | flakes/loginctl-linger/flake.nix | 56 |
1 files changed, 56 insertions, 0 deletions
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 @@ | |||
1 | { | ||
2 | outputs = { self }: { | ||
3 | nixosModule = { config, lib, pkgs, ... }: | ||
4 | # https://github.com/michalrus/dotfiles/commit/ebd5fa9583f82589f23531647aa677feb3f8d344#diff-4d353005ef5b3e37f33c07332b8523edR1 | ||
5 | # A temporary hack to `loginctl enable-linger $somebody` (for | ||
6 | # multiplexer sessions to last), until this one is unresolved: | ||
7 | # https://github.com/NixOS/nixpkgs/issues/3702 | ||
8 | # | ||
9 | # Usage: `users.extraUsers.somebody.linger = true` or slt. | ||
10 | |||
11 | with lib; | ||
12 | |||
13 | let | ||
14 | |||
15 | dataDir = "/var/lib/systemd/linger"; | ||
16 | |||
17 | lingeringUsers = map (u: u.name) (attrValues (flip filterAttrs config.users.users (n: u: u.linger))); | ||
18 | |||
19 | lingeringUsersFile = builtins.toFile "lingering-users" | ||
20 | (concatStrings (map (s: "${s}\n") | ||
21 | (sort (a: b: a < b) lingeringUsers))); # this sorting is important for `comm` to work correctly | ||
22 | |||
23 | updateLingering = pkgs.writeScript "update-lingering" '' | ||
24 | if [ ! -e ${dataDir} ]; then | ||
25 | install -m 0755 -o root -g root -d ${dataDir} | ||
26 | fi | ||
27 | if [ -e ${dataDir} ] ; then | ||
28 | ls ${dataDir} | sort | comm -3 -1 ${lingeringUsersFile} - | xargs -r ${pkgs.systemd}/bin/loginctl disable-linger | ||
29 | ls ${dataDir} | sort | comm -3 -2 ${lingeringUsersFile} - | xargs -r ${pkgs.systemd}/bin/loginctl enable-linger | ||
30 | fi | ||
31 | ''; | ||
32 | |||
33 | in | ||
34 | |||
35 | { | ||
36 | # Necessary for situations where flake gets included multiple times | ||
37 | key = builtins.hashString "sha256" (builtins.path { path = self.sourceInfo.outPath; name = "source"; }); | ||
38 | options = { | ||
39 | users.users = mkOption { | ||
40 | type = lib.types.attrsOf (lib.types.submodule { | ||
41 | options = { | ||
42 | linger = mkEnableOption "lingering for the user"; | ||
43 | }; | ||
44 | }); | ||
45 | }; | ||
46 | }; | ||
47 | |||
48 | config = { | ||
49 | system.activationScripts.update-lingering = { | ||
50 | deps = ["users"]; | ||
51 | text = "${updateLingering}"; | ||
52 | }; | ||
53 | }; | ||
54 | }; | ||
55 | }; | ||
56 | } | ||