nixos/lib: systemd definition files function
Add a re-usable function that converts an attrset to a directory containing systemd definition files.
This commit is contained in:
parent
906f999a2f
commit
a662dc8b73
|
@ -443,4 +443,21 @@ in rec {
|
||||||
${attrsToSection def.sliceConfig}
|
${attrsToSection def.sliceConfig}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Create a directory that contains systemd definition files from an attrset
|
||||||
|
# that contains the file names as keys and the content as values. The values
|
||||||
|
# in that attrset are determined by the supplied format.
|
||||||
|
definitions = directoryName: format: definitionAttrs:
|
||||||
|
let
|
||||||
|
listOfDefinitions = lib.mapAttrsToList
|
||||||
|
(name: format.generate "${name}.conf")
|
||||||
|
definitionAttrs;
|
||||||
|
in
|
||||||
|
pkgs.runCommand directoryName { } ''
|
||||||
|
mkdir -p $out
|
||||||
|
${(lib.concatStringsSep "\n"
|
||||||
|
(map (pkg: "cp ${pkg} $out/${pkg.name}") listOfDefinitions)
|
||||||
|
)}
|
||||||
|
'';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +1,15 @@
|
||||||
{ config, pkgs, lib, utils, ... }:
|
{ config, lib, pkgs, utils, ... }:
|
||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.systemd.repart;
|
cfg = config.systemd.repart;
|
||||||
initrdCfg = config.boot.initrd.systemd.repart;
|
initrdCfg = config.boot.initrd.systemd.repart;
|
||||||
|
|
||||||
writeDefinition = name: partitionConfig: pkgs.writeText
|
format = pkgs.formats.ini { };
|
||||||
"${name}.conf"
|
|
||||||
(lib.generators.toINI { } { Partition = partitionConfig; });
|
|
||||||
|
|
||||||
listOfDefinitions = lib.mapAttrsToList
|
definitionsDirectory = utils.systemdUtils.lib.definitions
|
||||||
writeDefinition
|
"repart.d"
|
||||||
(lib.filterAttrs (k: _: !(lib.hasPrefix "_" k)) cfg.partitions);
|
format
|
||||||
|
(lib.mapAttrs (_n: v: { Partition = v; }) cfg.partitions);
|
||||||
# Create a directory in the store that contains a copy of all definition
|
|
||||||
# files. This is then passed to systemd-repart in the initrd so it can access
|
|
||||||
# the definition files after the sysroot has been mounted but before
|
|
||||||
# activation. This needs a hard copy of the files and not just symlinks
|
|
||||||
# because otherwise the files do not show up in the sysroot.
|
|
||||||
definitionsDirectory = pkgs.runCommand "systemd-repart-definitions" { } ''
|
|
||||||
mkdir -p $out
|
|
||||||
${(lib.concatStringsSep "\n"
|
|
||||||
(map (pkg: "cp ${pkg} $out/${pkg.name}") listOfDefinitions)
|
|
||||||
)}
|
|
||||||
'';
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
|
|
|
@ -5,16 +5,10 @@ let
|
||||||
|
|
||||||
format = pkgs.formats.ini { };
|
format = pkgs.formats.ini { };
|
||||||
|
|
||||||
listOfDefinitions = lib.mapAttrsToList
|
definitionsDirectory = utils.systemdUtils.lib.definitions
|
||||||
(name: format.generate "${name}.conf")
|
"sysupdate.d"
|
||||||
(lib.filterAttrs (k: _: !(lib.hasPrefix "_" k)) cfg.transfers);
|
format
|
||||||
|
cfg.transfers;
|
||||||
definitionsDirectory = pkgs.runCommand "sysupdate.d" { } ''
|
|
||||||
mkdir -p $out
|
|
||||||
${(lib.concatStringsSep "\n"
|
|
||||||
(map (pkg: "cp ${pkg} $out/${pkg.name}") listOfDefinitions)
|
|
||||||
)}
|
|
||||||
'';
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.systemd.sysupdate = {
|
options.systemd.sysupdate = {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user