users/services: actually remove the systemd backend

This commit is contained in:
Colin 2024-03-21 15:07:18 +00:00
parent d2f6648bce
commit c5c37e79ac
2 changed files with 1 additions and 75 deletions

View File

@ -6,7 +6,6 @@ let
path-lib = sane-lib.path;
serviceType = with lib; types.submodule {
options = {
# these aoptions are mostly copied from systemd. could be improved.
description = mkOption {
type = types.str;
};
@ -113,15 +112,10 @@ let
};
services = mkOption {
# see: <repo:nixos/nixpkgs:nixos/lib/utils.nix>
# type = utils.systemdUtils.types.services;
# `utils.systemdUtils.types.services` is nearly what we want, but remove `stage2ServiceConfig`,
# as we don't want to force a PATH for every service.
type = types.attrsOf serviceType;
default = {};
description = ''
services to define for this user.
populates files in ~/.config/systemd.
'';
};
};
@ -129,9 +123,8 @@ let
defaultUserOptions = with lib; {
options = userOptions.options // {
services = mkOption {
# type = utils.systemdUtils.types.services;
# map to listOf attrs so that we can pass through
# w/o worrying about merging at this layer
# w/o worrying about merging at this layer (TODO: this is probably not necessary with s6)
type = types.attrsOf (types.coercedTo types.attrs (a: [ a ]) (types.listOf types.attrs));
default = {};
inherit (userOptions.options.services) description;
@ -219,7 +212,6 @@ in
{
imports = [
./s6-rc.nix
./systemd.nix
];
options = with lib; {

View File

@ -1,66 +0,0 @@
{ lib, utils, ... }:
let
# see: <repo:nixos/nixpkgs:nixos/lib/utils.nix>
# see: <repo:nix-community/home-manager:modules/systemd.nix>
mkUnit = serviceName: value: utils.systemdUtils.lib.serviceToUnit serviceName {
inherit (value)
script
wantedBy
;
serviceConfig = lib.filterAttrs (_: v: v != null) value.serviceConfig;
unitConfig = {
After = value.after;
Before = value.before;
BindsTo = value.bindsTo;
Description = value.description;
Documentation = value.documentation;
Wants = value.wants;
};
environment = {
# clear PATH to allow inheriting it from environment.
# otherwise, nixos would force it to `systemd.globalEnvironment.PATH`, which is mostly tools like sed/find/etc.
# clearing PATH here allows user services to inherit whatever PATH the graphical session sets
# (see `dbus-update-activation-environment` call in ~/.config/sway/config),
# which is critical to making it so user services can see user *programs*/packages.
#
# note that systemd provides no way to *append* to the PATH, only to override it (or not).
# nor do they intend to ever support that:
# - <https://github.com/systemd/systemd/issues/1082>
PATH = null;
};
};
in
{
# create fs entries for every service, in the systemd user dir.
options.sane.users = with lib; mkOption {
type = types.attrsOf (types.submodule ({ config, ...}: {
fs = lib.concatMapAttrs
(serviceName: value: let
cleanName = utils.systemdUtils.lib.mkPathSafeName serviceName;
generatedUnit = mkUnit serviceName value;
#^ generatedUnit contains keys:
# - text
# - aliases (IGNORED)
# - wantedBy
# - requiredBy
# - enabled (IGNORED)
# - overrideStrategy (IGNORED)
# TODO: error if one of the above ignored fields are set
symlinkData = {
text = generatedUnit.text;
targetName = "${cleanName}.service"; # systemd derives unit name from symlink target
};
serviceEntry = {
".config/systemd/user/${serviceName}.service".symlink = symlinkData;
};
wants = builtins.map (wantedBy: {
".config/systemd/user/${wantedBy}.wants/${serviceName}.service".symlink = symlinkData;
}) generatedUnit.wantedBy;
in
lib.mergeAttrsList ([ serviceEntry ] ++ wants)
)
config.services
;
}));
};
}