nixos: systemd-lib: Make generateUnits general with default args
This commit is contained in:
parent
d193ef8a57
commit
25113740a5
|
@ -120,10 +120,15 @@ in rec {
|
||||||
(if isList value then value else [value]))
|
(if isList value then value else [value]))
|
||||||
as));
|
as));
|
||||||
|
|
||||||
generateUnits = generateUnits' true;
|
generateUnits = { allowCollisions ? true, type, units, upstreamUnits, upstreamWants, packages ? cfg.packages, package ? cfg.package }:
|
||||||
|
let
|
||||||
generateUnits' = allowCollisions: type: units: upstreamUnits: upstreamWants:
|
typeDir = ({
|
||||||
pkgs.runCommand "${type}-units"
|
system = "system";
|
||||||
|
initrd = "system";
|
||||||
|
user = "user";
|
||||||
|
nspawn = "nspawn";
|
||||||
|
}).${type};
|
||||||
|
in pkgs.runCommand "${type}-units"
|
||||||
{ preferLocalBuild = true;
|
{ preferLocalBuild = true;
|
||||||
allowSubstitutes = false;
|
allowSubstitutes = false;
|
||||||
} ''
|
} ''
|
||||||
|
@ -131,7 +136,7 @@ in rec {
|
||||||
|
|
||||||
# Copy the upstream systemd units we're interested in.
|
# Copy the upstream systemd units we're interested in.
|
||||||
for i in ${toString upstreamUnits}; do
|
for i in ${toString upstreamUnits}; do
|
||||||
fn=${cfg.package}/example/systemd/${type}/$i
|
fn=${package}/example/systemd/${typeDir}/$i
|
||||||
if ! [ -e $fn ]; then echo "missing $fn"; false; fi
|
if ! [ -e $fn ]; then echo "missing $fn"; false; fi
|
||||||
if [ -L $fn ]; then
|
if [ -L $fn ]; then
|
||||||
target="$(readlink "$fn")"
|
target="$(readlink "$fn")"
|
||||||
|
@ -148,7 +153,7 @@ in rec {
|
||||||
# Copy .wants links, but only those that point to units that
|
# Copy .wants links, but only those that point to units that
|
||||||
# we're interested in.
|
# we're interested in.
|
||||||
for i in ${toString upstreamWants}; do
|
for i in ${toString upstreamWants}; do
|
||||||
fn=${cfg.package}/example/systemd/${type}/$i
|
fn=${package}/example/systemd/${typeDir}/$i
|
||||||
if ! [ -e $fn ]; then echo "missing $fn"; false; fi
|
if ! [ -e $fn ]; then echo "missing $fn"; false; fi
|
||||||
x=$out/$(basename $fn)
|
x=$out/$(basename $fn)
|
||||||
mkdir $x
|
mkdir $x
|
||||||
|
@ -160,14 +165,14 @@ in rec {
|
||||||
done
|
done
|
||||||
|
|
||||||
# Symlink all units provided listed in systemd.packages.
|
# Symlink all units provided listed in systemd.packages.
|
||||||
packages="${toString cfg.packages}"
|
packages="${toString packages}"
|
||||||
|
|
||||||
# Filter duplicate directories
|
# Filter duplicate directories
|
||||||
declare -A unique_packages
|
declare -A unique_packages
|
||||||
for k in $packages ; do unique_packages[$k]=1 ; done
|
for k in $packages ; do unique_packages[$k]=1 ; done
|
||||||
|
|
||||||
for i in ''${!unique_packages[@]}; do
|
for i in ''${!unique_packages[@]}; do
|
||||||
for fn in $i/etc/systemd/${type}/* $i/lib/systemd/${type}/*; do
|
for fn in $i/etc/systemd/${typeDir}/* $i/lib/systemd/${typeDir}/*; do
|
||||||
if ! [[ "$fn" =~ .wants$ ]]; then
|
if ! [[ "$fn" =~ .wants$ ]]; then
|
||||||
if [[ -d "$fn" ]]; then
|
if [[ -d "$fn" ]]; then
|
||||||
targetDir="$out/$(basename "$fn")"
|
targetDir="$out/$(basename "$fn")"
|
||||||
|
|
|
@ -461,7 +461,12 @@ in
|
||||||
enabledUpstreamSystemUnits = filter (n: ! elem n cfg.suppressedSystemUnits) upstreamSystemUnits;
|
enabledUpstreamSystemUnits = filter (n: ! elem n cfg.suppressedSystemUnits) upstreamSystemUnits;
|
||||||
enabledUnits = filterAttrs (n: v: ! elem n cfg.suppressedSystemUnits) cfg.units;
|
enabledUnits = filterAttrs (n: v: ! elem n cfg.suppressedSystemUnits) cfg.units;
|
||||||
in ({
|
in ({
|
||||||
"systemd/system".source = generateUnits "system" enabledUnits enabledUpstreamSystemUnits upstreamSystemWants;
|
"systemd/system".source = generateUnits {
|
||||||
|
type = "system";
|
||||||
|
units = enabledUnits;
|
||||||
|
upstreamUnits = enabledUpstreamSystemUnits;
|
||||||
|
upstreamWants = upstreamSystemWants;
|
||||||
|
};
|
||||||
|
|
||||||
"systemd/system.conf".text = ''
|
"systemd/system.conf".text = ''
|
||||||
[Manager]
|
[Manager]
|
||||||
|
|
|
@ -116,7 +116,13 @@ in {
|
||||||
in
|
in
|
||||||
mkMerge [
|
mkMerge [
|
||||||
(mkIf (cfg != {}) {
|
(mkIf (cfg != {}) {
|
||||||
environment.etc."systemd/nspawn".source = mkIf (cfg != {}) (generateUnits' false "nspawn" units [] []);
|
environment.etc."systemd/nspawn".source = mkIf (cfg != {}) (generateUnits {
|
||||||
|
allowCollisions = false;
|
||||||
|
type = "nspawn";
|
||||||
|
inherit units;
|
||||||
|
upstreamUnits = [];
|
||||||
|
upstreamWants = [];
|
||||||
|
});
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
systemd.targets.multi-user.wants = [ "machines.target" ];
|
systemd.targets.multi-user.wants = [ "machines.target" ];
|
||||||
|
|
|
@ -109,7 +109,12 @@ in {
|
||||||
];
|
];
|
||||||
|
|
||||||
environment.etc = {
|
environment.etc = {
|
||||||
"systemd/user".source = generateUnits "user" cfg.units upstreamUserUnits [];
|
"systemd/user".source = generateUnits {
|
||||||
|
type = "user";
|
||||||
|
inherit (cfg) units;
|
||||||
|
upstreamUnits = upstreamUserUnits;
|
||||||
|
upstreamWants = [];
|
||||||
|
};
|
||||||
|
|
||||||
"systemd/user.conf".text = ''
|
"systemd/user.conf".text = ''
|
||||||
[Manager]
|
[Manager]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user