diff options
author | nikstur <nikstur@outlook.com> | 2023-07-26 23:30:08 +0200 |
---|---|---|
committer | nikstur <nikstur@outlook.com> | 2023-07-26 23:30:08 +0200 |
commit | a662dc8b7369605e4b8e977d76797be982897b0c (patch) | |
tree | f02ae05e809f174fd4f6652367e3d4ee11ba5a6c /nixos/modules/system/boot | |
parent | 906f999a2fc8ff1617bd6ca5866157e8aab78260 (diff) |
nixos/lib: systemd definition files function
Add a re-usable function that converts an attrset to a directory containing systemd definition files.
Diffstat (limited to 'nixos/modules/system/boot')
-rw-r--r-- | nixos/modules/system/boot/systemd/repart.nix | 27 | ||||
-rw-r--r-- | nixos/modules/system/boot/systemd/sysupdate.nix | 14 |
2 files changed, 11 insertions, 30 deletions
diff --git a/nixos/modules/system/boot/systemd/repart.nix b/nixos/modules/system/boot/systemd/repart.nix index e81b3e4ff2a1b..2431c68ea17b8 100644 --- a/nixos/modules/system/boot/systemd/repart.nix +++ b/nixos/modules/system/boot/systemd/repart.nix @@ -1,28 +1,15 @@ -{ config, pkgs, lib, utils, ... }: +{ config, lib, pkgs, utils, ... }: let cfg = config.systemd.repart; initrdCfg = config.boot.initrd.systemd.repart; - writeDefinition = name: partitionConfig: pkgs.writeText - "${name}.conf" - (lib.generators.toINI { } { Partition = partitionConfig; }); - - listOfDefinitions = lib.mapAttrsToList - writeDefinition - (lib.filterAttrs (k: _: !(lib.hasPrefix "_" k)) 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) - )} - ''; + format = pkgs.formats.ini { }; + + definitionsDirectory = utils.systemdUtils.lib.definitions + "repart.d" + format + (lib.mapAttrs (_n: v: { Partition = v; }) cfg.partitions); in { options = { diff --git a/nixos/modules/system/boot/systemd/sysupdate.nix b/nixos/modules/system/boot/systemd/sysupdate.nix index 2921e97f7560a..b1914a9c4e767 100644 --- a/nixos/modules/system/boot/systemd/sysupdate.nix +++ b/nixos/modules/system/boot/systemd/sysupdate.nix @@ -5,16 +5,10 @@ let format = pkgs.formats.ini { }; - listOfDefinitions = lib.mapAttrsToList - (name: format.generate "${name}.conf") - (lib.filterAttrs (k: _: !(lib.hasPrefix "_" k)) cfg.transfers); - - definitionsDirectory = pkgs.runCommand "sysupdate.d" { } '' - mkdir -p $out - ${(lib.concatStringsSep "\n" - (map (pkg: "cp ${pkg} $out/${pkg.name}") listOfDefinitions) - )} - ''; + definitionsDirectory = utils.systemdUtils.lib.definitions + "sysupdate.d" + format + cfg.transfers; in { options.systemd.sysupdate = { |