From 1a9dfe22ba21da12a2e069d1c085c5a4d6194060 Mon Sep 17 00:00:00 2001 From: colin Date: Mon, 1 Aug 2022 14:37:19 -0700 Subject: [PATCH] image builder: integrate impermanence so that we create such things as /var/log untested --- modules/image.nix | 20 +++++++++----------- modules/impermanence.nix | 1 + 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/modules/image.nix b/modules/image.nix index 1125ee59..64190b97 100644 --- a/modules/image.nix +++ b/modules/image.nix @@ -12,6 +12,12 @@ in default = []; type = types.listOf types.package; }; + # extra (empty) directories to create in the rootfs. + # for example, /var/log might be required by the boot process, so ensure it exists. + sane.image.extraDirectories = mkOption { + default = []; + type = types.listOf types.str; + }; # the GPT header is fixed to Logical Block Address 1, # but we can actually put the partition entries anywhere. @@ -46,6 +52,7 @@ in (builtins.substring 0 (builtins.stringLength sub) super) == sub ); # return the (string) path to get from `stem` to `path` + # XXX: not sure how this behaves if the path doesn't contain the stem. relPath = stem: path: ( builtins.head (builtins.match "^${stem}(.+)" path) ); @@ -56,14 +63,6 @@ in # resolves to e.g. "nix/store", "/store" or "" storeRelPath = relPath nixFs.mountPoint "/nix/store"; - # return a list of all the `device` values -- one for each fileSystems."$x" - devices = builtins.attrValues (builtins.mapAttrs (mount: entry: entry.device) fileSystems); - # filter the devices to just those which sit under nixFs - subNixMounts = builtins.filter (a: startsWith (builtins.toString a) nixFs.mountPoint) devices; - # e.g. ["/nix/persist/var"] -> ["/persist/var"] if nixFs sits at /nix - subNixRelMounts = builtins.map (m: relPath nixFs.mountPoint m) subNixMounts; - makeSubNixMounts = builtins.toString (builtins.map (m: "mkdir -p ./${m};") subNixRelMounts); - uuidFromFs = fs: builtins.head (builtins.match "/dev/disk/by-uuid/(.+)" fs.device); vfatUuidFromFs = fs: builtins.replaceStrings ["-"] [""] (uuidFromFs fs); @@ -113,11 +112,10 @@ in populateCommands = let closureInfo = buildPackages.closureInfo { rootPaths = config.system.build.toplevel; }; + extraRelPaths = builtins.map (p: relPath nixFs.mountPoint m) cfg.extraDirectories; in '' - mkdir -p ./${storeRelPath} - # TODO: we should create the dirs required for boot (/var/log?). the rest are populated automatically. - # $(makeSubNixMounts) + mkdir -p ./${storeRelPath} ${extraRelPaths} echo "Copying system closure..." while IFS= read -r path; do echo " Copying $path" diff --git a/modules/impermanence.nix b/modules/impermanence.nix index 6836b981..95967569 100644 --- a/modules/impermanence.nix +++ b/modules/impermanence.nix @@ -36,6 +36,7 @@ in map-sys-dirs = map-dirs { user = "root"; group = "root"; mode = "0755"; directory = ""; }; map-service-dirs = map-dirs { user = "root"; group = "root"; mode = "0755"; directory = ""; }; in mkIf cfg.enable { + sane.image.extraDirectories = [ "/nix/persist/var/log" ]; environment.persistence."/nix/persist" = { directories = (map-home-dirs ([ # cache is probably too big to fit on the tmpfs