mirror of
https://github.com/SebastianWendel/nixpkgs.git
synced 2024-09-20 04:19:00 +02:00
Merge pull request #167153 from helsinki-systems/feat/systemd-stage-1-jobscripts
nixos/stage-1-systemd: Implement job scripts
This commit is contained in:
commit
33a73886c4
|
@ -94,7 +94,8 @@ in rec {
|
|||
|
||||
};
|
||||
|
||||
commonUnitOptions = { options = (sharedOptions // {
|
||||
commonUnitOptions = {
|
||||
options = sharedOptions // {
|
||||
|
||||
description = mkOption {
|
||||
default = "";
|
||||
|
@ -218,7 +219,8 @@ in rec {
|
|||
'';
|
||||
};
|
||||
|
||||
}); };
|
||||
};
|
||||
};
|
||||
|
||||
stage2CommonUnitOptions = {
|
||||
imports = [
|
||||
|
@ -250,7 +252,8 @@ in rec {
|
|||
};
|
||||
stage1CommonUnitOptions = commonUnitOptions;
|
||||
|
||||
serviceOptions = { options = {
|
||||
serviceOptions = { name, config, ... }: {
|
||||
options = {
|
||||
|
||||
environment = mkOption {
|
||||
default = {};
|
||||
|
@ -284,15 +287,6 @@ in rec {
|
|||
'';
|
||||
};
|
||||
|
||||
}; };
|
||||
|
||||
stage2ServiceOptions = { name, config, ... }: {
|
||||
imports = [
|
||||
stage2CommonUnitOptions
|
||||
serviceOptions
|
||||
];
|
||||
|
||||
options = {
|
||||
script = mkOption {
|
||||
type = types.lines;
|
||||
default = "";
|
||||
|
@ -349,6 +343,51 @@ in rec {
|
|||
'';
|
||||
};
|
||||
|
||||
jobScripts = mkOption {
|
||||
type = with types; coercedTo path singleton (listOf path);
|
||||
internal = true;
|
||||
description = "A list of all job script derivations of this unit.";
|
||||
default = [];
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
config = mkMerge [
|
||||
(mkIf (config.preStart != "") rec {
|
||||
jobScripts = makeJobScript "${name}-pre-start" config.preStart;
|
||||
serviceConfig.ExecStartPre = [ jobScripts ];
|
||||
})
|
||||
(mkIf (config.script != "") rec {
|
||||
jobScripts = makeJobScript "${name}-start" config.script;
|
||||
serviceConfig.ExecStart = jobScripts + " " + config.scriptArgs;
|
||||
})
|
||||
(mkIf (config.postStart != "") rec {
|
||||
jobScripts = (makeJobScript "${name}-post-start" config.postStart);
|
||||
serviceConfig.ExecStartPost = [ jobScripts ];
|
||||
})
|
||||
(mkIf (config.reload != "") rec {
|
||||
jobScripts = makeJobScript "${name}-reload" config.reload;
|
||||
serviceConfig.ExecReload = jobScripts;
|
||||
})
|
||||
(mkIf (config.preStop != "") rec {
|
||||
jobScripts = makeJobScript "${name}-pre-stop" config.preStop;
|
||||
serviceConfig.ExecStop = jobScripts;
|
||||
})
|
||||
(mkIf (config.postStop != "") rec {
|
||||
jobScripts = makeJobScript "${name}-post-stop" config.postStop;
|
||||
serviceConfig.ExecStopPost = jobScripts;
|
||||
})
|
||||
];
|
||||
|
||||
};
|
||||
|
||||
stage2ServiceOptions = {
|
||||
imports = [
|
||||
stage2CommonUnitOptions
|
||||
serviceOptions
|
||||
];
|
||||
|
||||
options = {
|
||||
restartIfChanged = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
|
@ -404,33 +443,6 @@ in rec {
|
|||
apply = v: if isList v then v else [ v ];
|
||||
};
|
||||
};
|
||||
|
||||
config = mkMerge
|
||||
[ (mkIf (config.preStart != "")
|
||||
{ serviceConfig.ExecStartPre =
|
||||
[ (makeJobScript "${name}-pre-start" config.preStart) ];
|
||||
})
|
||||
(mkIf (config.script != "")
|
||||
{ serviceConfig.ExecStart =
|
||||
makeJobScript "${name}-start" config.script + " " + config.scriptArgs;
|
||||
})
|
||||
(mkIf (config.postStart != "")
|
||||
{ serviceConfig.ExecStartPost =
|
||||
[ (makeJobScript "${name}-post-start" config.postStart) ];
|
||||
})
|
||||
(mkIf (config.reload != "")
|
||||
{ serviceConfig.ExecReload =
|
||||
makeJobScript "${name}-reload" config.reload;
|
||||
})
|
||||
(mkIf (config.preStop != "")
|
||||
{ serviceConfig.ExecStop =
|
||||
makeJobScript "${name}-pre-stop" config.preStop;
|
||||
})
|
||||
(mkIf (config.postStop != "")
|
||||
{ serviceConfig.ExecStopPost =
|
||||
makeJobScript "${name}-post-stop" config.postStop;
|
||||
})
|
||||
];
|
||||
};
|
||||
|
||||
stage1ServiceOptions = {
|
||||
|
@ -441,7 +453,8 @@ in rec {
|
|||
};
|
||||
|
||||
|
||||
socketOptions = { options = {
|
||||
socketOptions = {
|
||||
options = {
|
||||
|
||||
listenStreams = mkOption {
|
||||
default = [];
|
||||
|
@ -474,8 +487,9 @@ in rec {
|
|||
<manvolnum>5</manvolnum></citerefentry> for details.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
}; };
|
||||
};
|
||||
|
||||
stage2SocketOptions = {
|
||||
imports = [
|
||||
|
@ -492,7 +506,8 @@ in rec {
|
|||
};
|
||||
|
||||
|
||||
timerOptions = { options = {
|
||||
timerOptions = {
|
||||
options = {
|
||||
|
||||
timerConfig = mkOption {
|
||||
default = {};
|
||||
|
@ -508,7 +523,8 @@ in rec {
|
|||
'';
|
||||
};
|
||||
|
||||
}; };
|
||||
};
|
||||
};
|
||||
|
||||
stage2TimerOptions = {
|
||||
imports = [
|
||||
|
@ -525,7 +541,8 @@ in rec {
|
|||
};
|
||||
|
||||
|
||||
pathOptions = { options = {
|
||||
pathOptions = {
|
||||
options = {
|
||||
|
||||
pathConfig = mkOption {
|
||||
default = {};
|
||||
|
@ -539,7 +556,8 @@ in rec {
|
|||
'';
|
||||
};
|
||||
|
||||
}; };
|
||||
};
|
||||
};
|
||||
|
||||
stage2PathOptions = {
|
||||
imports = [
|
||||
|
@ -556,7 +574,8 @@ in rec {
|
|||
};
|
||||
|
||||
|
||||
mountOptions = { options = {
|
||||
mountOptions = {
|
||||
options = {
|
||||
|
||||
what = mkOption {
|
||||
example = "/dev/sda1";
|
||||
|
@ -598,7 +617,9 @@ in rec {
|
|||
<manvolnum>5</manvolnum></citerefentry> for details.
|
||||
'';
|
||||
};
|
||||
}; };
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
stage2MountOptions = {
|
||||
imports = [
|
||||
|
@ -614,7 +635,8 @@ in rec {
|
|||
];
|
||||
};
|
||||
|
||||
automountOptions = { options = {
|
||||
automountOptions = {
|
||||
options = {
|
||||
|
||||
where = mkOption {
|
||||
example = "/mnt";
|
||||
|
@ -636,7 +658,9 @@ in rec {
|
|||
<manvolnum>5</manvolnum></citerefentry> for details.
|
||||
'';
|
||||
};
|
||||
}; };
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
stage2AutomountOptions = {
|
||||
imports = [
|
||||
|
@ -652,7 +676,8 @@ in rec {
|
|||
];
|
||||
};
|
||||
|
||||
sliceOptions = { options = {
|
||||
sliceOptions = {
|
||||
options = {
|
||||
|
||||
sliceConfig = mkOption {
|
||||
default = {};
|
||||
|
@ -666,7 +691,8 @@ in rec {
|
|||
'';
|
||||
};
|
||||
|
||||
}; };
|
||||
};
|
||||
};
|
||||
|
||||
stage2SliceOptions = {
|
||||
imports = [
|
||||
|
|
|
@ -96,6 +96,7 @@ let
|
|||
|
||||
enabledUpstreamUnits = filter (n: ! elem n cfg.suppressedUnits) upstreamUnits;
|
||||
enabledUnits = filterAttrs (n: v: ! elem n cfg.suppressedUnits) cfg.units;
|
||||
jobScripts = concatLists (mapAttrsToList (_: unit: unit.jobScripts or []) (filterAttrs (_: v: v.enable) cfg.services));
|
||||
|
||||
stage1Units = generateUnits {
|
||||
type = "initrd";
|
||||
|
@ -378,7 +379,7 @@ in {
|
|||
|
||||
# so NSS can look up usernames
|
||||
"${pkgs.glibc}/lib/libnss_files.so"
|
||||
];
|
||||
] ++ jobScripts;
|
||||
|
||||
targets.initrd.aliases = ["default.target"];
|
||||
units =
|
||||
|
|
Loading…
Reference in a new issue