From 0c38364b28e3443ac45b56c08787bb70a2b30b28 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Sun, 24 Aug 2025 15:10:22 +0200 Subject: modules/: Hard-code user and group ids This avoids relying on the state in /var/lib/nixos --- modules/by-name/co/constants/module.nix | 57 +++++++++++++++++++++++++++++++++ modules/by-name/co/coredump/module.nix | 17 ++++++++++ 2 files changed, 74 insertions(+) create mode 100644 modules/by-name/co/constants/module.nix create mode 100644 modules/by-name/co/coredump/module.nix (limited to 'modules/by-name/co') diff --git a/modules/by-name/co/constants/module.nix b/modules/by-name/co/constants/module.nix new file mode 100644 index 00000000..5711e9cf --- /dev/null +++ b/modules/by-name/co/constants/module.nix @@ -0,0 +1,57 @@ +# This file is inspired by the `nixos/modules/misc/ids.nix` +# file in nixpkgs. +{lib, ...}: { + options.soispha.constants = { + ids.uids = lib.mkOption { + internal = true; + description = '' + The user IDs used in this nixos config. + ''; + type = lib.types.attrsOf (lib.types.ints.between 0 1000); + }; + ids.gids = lib.mkOption { + internal = true; + description = '' + The group IDs used in this nixos config. + ''; + type = lib.types.attrsOf (lib.types.ints.between 0 1000); + }; + }; + + config.soispha.constants = { + ids.uids = { + # Keep this sorted with `!sort --numeric-sort --key=2 --field-separator="="` + + dhcpcd = 992; + systemd-oom = 993; + sshd = 994; + rtkit = 995; + nscd = 996; + nm-iodine = 997; + fwupd-refresh = 998; + avahi = 999; + + # As per the NixOS file, the uids should not be greater or equal to 400; + }; + ids.gids = { + # Please add your groups to the users and inherit them here. + # This avoids having an user/group id mismatch. + + dhcpcd = 987; + lpadmin = 988; + resolvconf = 989; + systemd-oom = 990; + systemd-coredump = 991; + sshd = 992; + rtkit = 993; + polkituser = 994; + nscd = 995; + msr = 996; + fwupd-refresh = 997; + avahi = 998; + adbusers = 999; + + # The gid should match the uid. Thus should not be >= 400; + }; + }; +} diff --git a/modules/by-name/co/coredump/module.nix b/modules/by-name/co/coredump/module.nix new file mode 100644 index 00000000..79e764eb --- /dev/null +++ b/modules/by-name/co/coredump/module.nix @@ -0,0 +1,17 @@ +{ + config, + lib, + ... +}: let + cfg = config.soispha.systemd.coredump; +in { + options.soispha.systemd.coredump = { + enable = (lib.mkEnableOption "oomd") // {default = config.systemd.coredump.enable;}; + }; + + config = lib.mkIf cfg.enable { + users = { + groups.systemd-coredump.gid = config.soispha.constants.ids.gids.systemd-coredump; + }; + }; +} -- cgit 1.4.1