1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 inherit (pkgs) plymouth;
8
9 cfg = config.boot.plymouth;
10
11 themesEnv = pkgs.buildEnv {
12 name = "plymouth-themes";
13 paths = [ plymouth ] ++ cfg.themePackages;
14 };
15
16 configFile = pkgs.writeText "plymouthd.conf" ''
17 [Daemon]
18 ShowDelay=0
19 Theme=${cfg.theme}
20 '';
21
22in
23
24{
25
26 options = {
27
28 boot.plymouth = {
29
30 enable = mkEnableOption "Plymouth boot splash screen";
31
32 themePackages = mkOption {
33 default = [];
34 type = types.listOf types.package;
35 description = ''
36 Extra theme packages for plymouth.
37 '';
38 };
39
40 theme = mkOption {
41 default = "fade-in";
42 type = types.str;
43 description = ''
44 Splash screen theme.
45 '';
46 };
47
48 logo = mkOption {
49 type = types.path;
50 default = pkgs.fetchurl {
51 url = "https://nixos.org/logo/nixos-hires.png";
52 sha256 = "1ivzgd7iz0i06y36p8m5w48fd8pjqwxhdaavc0pxs7w1g7mcy5si";
53 };
54 defaultText = ''pkgs.fetchurl {
55 url = "https://nixos.org/logo/nixos-hires.png";
56 sha256 = "1ivzgd7iz0i06y36p8m5w48fd8pjqwxhdaavc0pxs7w1g7mcy5si";
57 }'';
58 description = ''
59 Logo which is displayed on the splash screen.
60 '';
61 };
62
63 };
64
65 };
66
67 config = mkIf cfg.enable {
68
69 boot.kernelParams = [ "splash" ];
70
71 # To be discoverable by systemd.
72 environment.systemPackages = [ plymouth ];
73
74 environment.etc."plymouth/plymouthd.conf".source = configFile;
75 environment.etc."plymouth/plymouthd.defaults".source = "${plymouth}/share/plymouth/plymouth.defaults";
76 environment.etc."plymouth/logo.png".source = cfg.logo;
77 environment.etc."plymouth/themes".source = "${themesEnv}/share/plymouth/themes";
78 # XXX: Needed because we supply a different set of plugins in initrd.
79 environment.etc."plymouth/plugins".source = "${plymouth}/lib/plymouth";
80
81 systemd.packages = [ plymouth ];
82
83 systemd.services.plymouth-kexec.wantedBy = [ "kexec.target" ];
84 systemd.services.plymouth-halt.wantedBy = [ "halt.target" ];
85 systemd.services.plymouth-quit = {
86 wantedBy = [ "multi-user.target" ];
87 after = [ "display-manager.service" "multi-user.target" ];
88 };
89 systemd.services.plymouth-poweroff.wantedBy = [ "poweroff.target" ];
90 systemd.services.plymouth-reboot.wantedBy = [ "reboot.target" ];
91 systemd.services.plymouth-read-write.wantedBy = [ "sysinit.target" ];
92
93 boot.initrd.extraUtilsCommands = ''
94 copy_bin_and_libs ${pkgs.plymouth}/bin/plymouthd
95 copy_bin_and_libs ${pkgs.plymouth}/bin/plymouth
96
97 moduleName="$(sed -n 's,ModuleName *= *,,p' ${themesEnv}/share/plymouth/themes/${cfg.theme}/${cfg.theme}.plymouth)"
98
99 mkdir -p $out/lib/plymouth/renderers
100 cp ${plymouth}/lib/plymouth/{text,details,$moduleName}.so $out/lib/plymouth
101 cp ${plymouth}/lib/plymouth/renderers/{drm,frame-buffer}.so $out/lib/plymouth/renderers
102
103 mkdir -p $out/share/plymouth/themes
104 cp ${plymouth}/share/plymouth/plymouthd.defaults $out/share/plymouth
105 cp -r ${themesEnv}/share/plymouth/themes/{text,details,${cfg.theme}} $out/share/plymouth/themes
106 cp ${cfg.logo} $out/share/plymouth/logo.png
107 '';
108
109 boot.initrd.extraUtilsCommandsTest = ''
110 $out/bin/plymouthd --help >/dev/null
111 $out/bin/plymouth --help >/dev/null
112 '';
113
114 boot.initrd.extraUdevRulesCommands = ''
115 cp ${config.systemd.package}/lib/udev/rules.d/{70-uaccess,71-seat}.rules $out
116 sed -i '/loginctl/d' $out/71-seat.rules
117 '';
118
119 # We use `mkAfter` to ensure that LUKS password prompt would be shown earlier than the splash screen.
120 boot.initrd.preLVMCommands = mkAfter ''
121 mkdir -p /etc/plymouth
122 ln -s ${configFile} /etc/plymouth/plymouthd.conf
123 ln -s $extraUtils/share/plymouth/plymouthd.defaults /etc/plymouth/plymouthd.defaults
124 ln -s $extraUtils/share/plymouth/logo.png /etc/plymouth/logo.png
125 ln -s $extraUtils/share/plymouth/themes /etc/plymouth/themes
126 ln -s $extraUtils/lib/plymouth /etc/plymouth/plugins
127
128 plymouthd --mode=boot --pid-file=/run/plymouth/pid --attach-to-session
129 plymouth show-splash
130 '';
131
132 boot.initrd.postMountCommands = ''
133 plymouth update-root-fs --new-root-dir="$targetRoot"
134 '';
135
136 # `mkBefore` to ensure that any custom prompts would be visible.
137 boot.initrd.preFailCommands = mkBefore ''
138 plymouth quit --wait
139 '';
140
141 };
142
143}