pkgs.uvms: init
...with some basic optional persistence and without having to rebuild images for every app nix run -f . pkgs.uvms -- --persist-home librewolf alacritty --run librewolf --run alacritty
This commit is contained in:
parent
22b613d157
commit
384b45bdef
15 changed files with 1155 additions and 452 deletions
72
profiles/on-failure.nix
Normal file
72
profiles/on-failure.nix
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
{
|
||||
lib,
|
||||
config,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
cfg = config.some.failure-handler;
|
||||
jobScript = pkgs.writeShellScriptBin "show-status" ''
|
||||
set -euo pipefail
|
||||
|
||||
export PATH=${lib.getBin config.boot.initrd.systemd.package}/bin''${PATH:+:}$PATH
|
||||
export PATH=${lib.getBin pkgs.util-linux}/bin''${PATH:+:}$PATH
|
||||
export PATH=${lib.getBin pkgs.gnugrep}/bin''${PATH:+:}$PATH
|
||||
|
||||
unit="$1"
|
||||
shift
|
||||
|
||||
systemctl status "$unit" >&2 || true
|
||||
patterns=$unit$'\n'error
|
||||
dmesg | grep -Fi "$patterns" || true
|
||||
'';
|
||||
mkSystemdDropin = pkgs.callPackage ../pkgs/mkSystemdDropin.nix { };
|
||||
in
|
||||
{
|
||||
options.some.failure-handler = {
|
||||
enable = lib.mkEnableOption "Set up show-status@.service as a default OnFailure dependency";
|
||||
stage-1.enable =
|
||||
lib.mkEnableOption "Set up show-status@.service as a default OnFailure dependency in initramfs/initrd"
|
||||
// {
|
||||
default = cfg.enable;
|
||||
};
|
||||
package = lib.mkOption {
|
||||
type = lib.types.package;
|
||||
readOnly = true;
|
||||
description = "The internal package with the drop-ins";
|
||||
};
|
||||
};
|
||||
config = {
|
||||
some.failure-handler.package = mkSystemdDropin {
|
||||
name = "status-on-failure";
|
||||
inherit jobScript;
|
||||
dropinText = ''
|
||||
[Unit]
|
||||
OnFailure=status@%n.service
|
||||
'';
|
||||
serviceText = ''
|
||||
[Unit]
|
||||
DefaultDependencies=no
|
||||
Description=Show status for %i
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
StandardOutput=journal+console
|
||||
StandardError=journal+console
|
||||
ExecStart=${lib.getExe jobScript} "%i"
|
||||
JoinsNamespaceOf=
|
||||
DelegateNamespaces=
|
||||
'';
|
||||
extraCommands = ''
|
||||
printf "%s" "$serviceText" > "$root/status@.service"
|
||||
'';
|
||||
};
|
||||
boot.initrd.systemd.packages = lib.optionals cfg.stage-1.enable [ cfg.package ];
|
||||
boot.initrd.systemd.storePaths = lib.optionals cfg.stage-1.enable [
|
||||
jobScript
|
||||
pkgs.util-linux
|
||||
pkgs.gnugrep
|
||||
];
|
||||
systemd.packages = lib.optionals cfg.enable [ cfg.package ];
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue