mirror of
https://github.com/nix-community/home-manager.git
synced 2026-06-05 21:02:51 +00:00
Adds `home.services`, an attribute set of nixpkgs [modular services](https://nixos.org/manual/nixos/unstable/#modular-services) sourced from `<nixpkgs/lib/services/lib.nix>`. Each service exposes `process.argv` and the upstream NixOS-style systemd schema (`systemd.lib`, `systemd.mainExecStart`, `systemd.service`, `systemd.services`, `systemd.sockets`) by re-exporting `nixos/modules/system/service/systemd/service.nix`. Service modules shipped with `_class = "service"` (e.g. `pkgs.<name>.passthru.services.default`) drop in unchanged -- service portability across module systems is the point of modular services. Lifted units are evaluated and translated from NixOS-style attrs (`wantedBy`, `serviceConfig`, `unitConfig`, `environment`, ...) into the section-based INI shape (`{ Unit; Service; Install; }`) that home-manager's `systemd.user.{services,sockets}` consumes; only the common keys are mapped, uncommon options remain reachable via `unitConfig` / `serviceConfig` / `socketConfig`. Sub-services and their units are dashed under the parent service name; `process.argv` becomes the default `ExecStart` for the service's primary unit, which defaults to `WantedBy=default.target`. Mirrors the surface of nixpkgs' portable systemd module (services + sockets only); other unit kinds home-manager supports natively (timers etc.) are intentionally not modeled until upstream grows them. Each service's `configData.<name>` entries are materialized at `$XDG_CONFIG_HOME/system-services/<service-prefix>/<name>` (mirroring how `nixos/modules/system/service/systemd/{config-data-path,system}.nix` lifts `configData` to `environment.etc`), with the absolute path injected back into `configData.<name>.path` so the service can refer to its files at a stable location. Includes nmt tests covering: a basic `process.argv`-only service, a service with a `configData` entry, and importing `pkgs.ghostunnel.passthru.services.default` to assert the lifted user unit contains the expected ExecStart flags and `LoadCredential` entries.
133 lines
3.4 KiB
Nix
133 lines
3.4 KiB
Nix
{
|
|
pkgs,
|
|
|
|
# Note, this should be "the standard library" + HM extensions.
|
|
lib,
|
|
|
|
# Whether to enable module type checking.
|
|
check ? true,
|
|
|
|
# If disabled, the pkgs attribute passed to this function is used instead.
|
|
useNixpkgsModule ? true,
|
|
|
|
# Whether to only import the required modules, and let the user add modules
|
|
# manually
|
|
minimal ? false,
|
|
}:
|
|
|
|
let
|
|
|
|
modules = builtins.concatLists [
|
|
[
|
|
# keep-sorted start case=no numeric=yes
|
|
./accounts/calendar.nix
|
|
./accounts/contacts.nix
|
|
./accounts/email.nix
|
|
./config/home-cursor.nix
|
|
./config/i18n.nix
|
|
./dbus.nix
|
|
./files.nix
|
|
./home-environment.nix
|
|
./i18n/input-method/default.nix
|
|
./launchd/default.nix
|
|
./manual.nix
|
|
./misc/dconf.nix
|
|
./misc/debug.nix
|
|
./misc/editorconfig.nix
|
|
./misc/fontconfig.nix
|
|
./misc/gtk.nix
|
|
./misc/lib.nix
|
|
./misc/mozilla-messaging-hosts.nix
|
|
./misc/news.nix
|
|
./misc/nix-remote-build.nix
|
|
./misc/nix.nix
|
|
./misc/numlock.nix
|
|
./misc/pam.nix
|
|
./misc/qt.nix
|
|
./misc/qt/kconfig.nix
|
|
./misc/qt/kvantum.nix
|
|
./misc/shell.nix
|
|
./misc/specialisation.nix
|
|
./misc/ssh-auth-sock.nix
|
|
./misc/submodule-support.nix
|
|
./misc/tmpfiles.nix
|
|
./misc/uninstall.nix
|
|
./misc/version.nix
|
|
./misc/vte.nix
|
|
./misc/xdg-autostart.nix
|
|
./misc/xdg-desktop-entries.nix
|
|
./misc/xdg-mime-apps.nix
|
|
./misc/xdg-mime.nix
|
|
./misc/xdg-portal.nix
|
|
./misc/xdg-system-dirs.nix
|
|
./misc/xdg-terminal-exec.nix
|
|
./misc/xdg-user-dirs.nix
|
|
./misc/xdg.nix
|
|
./misc/xfconf.nix
|
|
./services-modular
|
|
./systemd.nix
|
|
./targets/darwin
|
|
./targets/generic-linux.nix
|
|
./wayland.nix
|
|
./xresources.nix
|
|
./xsession.nix
|
|
# keep-sorted end
|
|
(pkgs.path + "/nixos/modules/misc/assertions.nix")
|
|
(pkgs.path + "/nixos/modules/misc/meta.nix")
|
|
# Module deprecations and removals
|
|
./deprecations.nix
|
|
]
|
|
|
|
(lib.optional useNixpkgsModule ./misc/nixpkgs.nix)
|
|
|
|
(lib.optional (!useNixpkgsModule) ./misc/nixpkgs-disabled.nix)
|
|
|
|
(
|
|
if minimal then
|
|
[
|
|
./programs/bash.nix
|
|
./programs/autojump.nix # Dependency of bash module
|
|
./programs/zsh
|
|
./programs/ion.nix
|
|
./programs/nushell.nix
|
|
./services/window-managers/i3-sway/default.nix # Dependency of home-cursor module
|
|
]
|
|
else
|
|
lib.concatMap
|
|
(
|
|
dir:
|
|
lib.pipe (builtins.readDir dir) [
|
|
(lib.filterAttrs (path: _kind: !lib.hasPrefix "_" path))
|
|
(lib.filterAttrs (
|
|
_path: kind: kind == "directory" || (kind == "regular" && lib.hasSuffix ".nix" _path)
|
|
))
|
|
(lib.mapAttrsToList (path: _kind: lib.path.append dir path))
|
|
]
|
|
)
|
|
[
|
|
./services
|
|
./programs
|
|
]
|
|
)
|
|
];
|
|
|
|
pkgsModule =
|
|
{ config, ... }:
|
|
{
|
|
config = {
|
|
_module.args.baseModules = modules;
|
|
_module.args.pkgsPath = lib.mkDefault (
|
|
if lib.versionAtLeast config.home.stateVersion "20.09" then pkgs.path else <nixpkgs>
|
|
);
|
|
_module.args.pkgs = lib.mkDefault pkgs;
|
|
_module.check = check;
|
|
lib = lib.hm;
|
|
}
|
|
// lib.optionalAttrs useNixpkgsModule {
|
|
nixpkgs.system = lib.mkDefault pkgs.stdenv.hostPlatform.system;
|
|
};
|
|
};
|
|
|
|
in
|
|
modules ++ [ pkgsModule ]
|