1{
2 options,
3 config,
4 lib,
5 pkgs,
6 ...
7}:
8
9let
10 inherit (lib)
11 mkOption
12 types
13 ;
14
15 systemBuilderArgs = {
16 activationScript = config.system.activationScripts.script;
17 dryActivationScript = config.system.dryActivationScript;
18 };
19
20in
21{
22 options = {
23 system.activatable = mkOption {
24 type = types.bool;
25 default = true;
26 description = ''
27 Whether to add the activation script to the system profile.
28
29 The default, to have the script available all the time, is what we normally
30 do, but for image based systems, this may not be needed or not be desirable.
31 '';
32 };
33 system.activatableSystemBuilderCommands = options.system.systemBuilderCommands // {
34 description = ''
35 Like `system.systemBuilderCommands`, but only for the commands that are
36 needed *both* when the system is activatable and when it isn't.
37
38 Disclaimer: This option might go away in the future. It might be
39 superseded by separating switch-to-configuration into a separate script
40 which will make this option superfluous. See
41 https://github.com/NixOS/nixpkgs/pull/263462#discussion_r1373104845 for
42 a discussion.
43 '';
44 };
45 system.build.separateActivationScript = mkOption {
46 type = types.package;
47 description = ''
48 A separate activation script package that's not part of the system profile.
49
50 This is useful for configurations where `system.activatable` is `false`.
51 Otherwise, you can just use `system.build.toplevel`.
52 '';
53 };
54 };
55 config = {
56 system.activatableSystemBuilderCommands = ''
57 echo "$activationScript" > $out/activate
58 echo "$dryActivationScript" > $out/dry-activate
59 substituteInPlace $out/activate --subst-var-by out ''${!toplevelVar}
60 substituteInPlace $out/dry-activate --subst-var-by out ''${!toplevelVar}
61 chmod u+x $out/activate $out/dry-activate
62 unset activationScript dryActivationScript
63 '';
64
65 system.systemBuilderCommands = lib.mkIf config.system.activatable config.system.activatableSystemBuilderCommands;
66 system.systemBuilderArgs = lib.mkIf config.system.activatable (
67 systemBuilderArgs
68 // {
69 toplevelVar = "out";
70 }
71 );
72
73 system.build.separateActivationScript =
74 pkgs.runCommand "separate-activation-script"
75 (
76 systemBuilderArgs
77 // {
78 toplevelVar = "toplevel";
79 toplevel = config.system.build.toplevel;
80 }
81 )
82 ''
83 mkdir $out
84 ${config.system.activatableSystemBuilderCommands}
85 '';
86 };
87}