1
1
mirror of https://github.com/NixOS/mobile-nixos.git synced 2024-12-11 09:04:01 +03:00

image-builder: handle size and begin work on populate commands

This commit is contained in:
Samuel Dionne-Riel 2019-08-28 20:50:28 -04:00
parent 183c64b638
commit eb8ca1f685
3 changed files with 28 additions and 7 deletions

View File

@ -5,7 +5,7 @@ lib.makeScope newScope (self:
inherit (self) callPackage;
in
{
makePartition = callPackage ./makePartition.nix {};
makeFilesystem = callPackage ./makeFilesystem.nix {};
# All known supported filesystems for image generation.
# Use stand-alone (outside of a disk image) is supported.

View File

@ -1,9 +1,9 @@
{ makePartition, dosfstools, mtools, libfaketime }:
{ makeFilesystem, dosfstools, mtools, libfaketime }:
/* */ let scope = { "fileSystem.makeFAT32" =
{ partitionID, ... } @ args:
makePartition (args // {
makeFilesystem (args // {
# FAT32 can be used for ESP. Let's make this obvious.
filesystemType = if args ? filesystemType then args.filesystemType else "FAT32";

View File

@ -1,16 +1,26 @@
{ stdenvNoCC, lib, writeText }:
/* */ let scope = { "fileSystem.makePartition" =
/* */ let scope = { "fileSystem.makeFilesystem" =
let
inherit (lib) optionals;
inherit (lib) optionals optionalString assertMsg;
in
{
name
# The populate commands are executed in a subshell. The CWD at the star is the
# public API to know where to add files that will be added to the image.
, populateCommands ? null
# When size is not given, it is assumed that `populateCommands` will populate
# the filesystem.
, size ? null
, ...
} @ args:
assert lib.asserts.assertMsg
(size !=null || populateCommands != null)
"Either a size or populateCommands needs to be given to build a filesystem.";
let
partName = name;
partSize = toString size;
@ -34,6 +44,17 @@ stdenvNoCC.mkDerivation (args // rec {
mkdir -p $out
${optionalString (populateCommands != null) ''
echo
echo "Populating disk image"
echo
(
mkdir -p files
cd files
${populateCommands}
)
''}
echo
echo "Building partition ${partName}"
echo "With ${if size == null then "automatic size" else "${toString size} bytes"}"
@ -53,7 +74,7 @@ stdenvNoCC.mkDerivation (args // rec {
runHook checkPhase
''
+ lib.optionalString ((builtins.getEnv "TEST_MODE") == "yes")
+ optionalString ((builtins.getEnv "TEST_MODE") == "yes")
"# test impure builds ${toString builtins.currentTime}"
;
@ -63,4 +84,4 @@ stdenvNoCC.mkDerivation (args // rec {
# inherit size;
# })} > $out/nix-support/partition-metadata.json
/* */ ;}; in scope."fileSystem.makePartition"
/* */ ;}; in scope."fileSystem.makeFilesystem"