mirror of
https://github.com/NixOS/mobile-nixos.git
synced 2024-11-24 12:42:47 +03:00
rootfs: Build using the image-builder
This commit is contained in:
parent
70a967a904
commit
c4d16fd341
@ -34,14 +34,18 @@ let
|
||||
}
|
||||
{
|
||||
name = "system";
|
||||
# Equivalent to:
|
||||
# → nix-build nixos -I nixos-config=system-image.nix -A config.system.build.sdImage
|
||||
path = ((import (pkgs.path + "/nixos")) { configuration = ../system-image.nix; }).config.system.build.sdImage;
|
||||
path = config.system.build.rootfs;
|
||||
}
|
||||
];
|
||||
};
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
../systems/rootfs.nix
|
||||
# FIXME: factor out installation device profile.
|
||||
<nixpkgs/nixos/modules/profiles/installation-device.nix>
|
||||
];
|
||||
|
||||
options.mobile = {
|
||||
system.type = mkOption {
|
||||
type = types.enum (lib.attrNames build_types);
|
||||
|
83
systems/rootfs.nix
Normal file
83
systems/rootfs.nix
Normal file
@ -0,0 +1,83 @@
|
||||
# This builds a rootfs image (ext4) from the current configuration.
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
{
|
||||
boot.loader.grub.enable = false;
|
||||
boot.loader.generic-extlinux-compatible.enable = false;
|
||||
|
||||
system.build.rootfs =
|
||||
pkgs.imageBuilder.fileSystem.makeExt4 {
|
||||
name = "NIXOS_SYSTEM";
|
||||
partitionID = "44444444-4444-4444-8888-888888888888";
|
||||
populateCommands =
|
||||
let
|
||||
closureInfo = pkgs.buildPackages.closureInfo { rootPaths = config.system.build.toplevel; };
|
||||
in
|
||||
''
|
||||
mkdir -p ./nix/store
|
||||
echo "Copying system closure..."
|
||||
while IFS= read -r path; do
|
||||
echo " Copying $path"
|
||||
cp -prf "$path" ./nix/store
|
||||
done < "${closureInfo}/store-paths"
|
||||
echo "Done copying system closure..."
|
||||
cp -v ${closureInfo}/registration ./nix-path-registration
|
||||
'';
|
||||
# FIXME : fixup the partition autoexpand.
|
||||
extraPadding = pkgs.imageBuilder.size.MiB 500;
|
||||
}
|
||||
;
|
||||
|
||||
# FIXME: this is not a rootfs!
|
||||
system.build.diskImage =
|
||||
pkgs.imageBuilder.diskImage.makeMBR {
|
||||
name = "mobile-nixos";
|
||||
diskID = "01234567";
|
||||
partitions = [
|
||||
# FIXME : initrd how?
|
||||
config.system.build.rootfs
|
||||
];
|
||||
}
|
||||
;
|
||||
|
||||
#pkgs.runCommandNoCC "mobile-nixos-rootfs" {} ''
|
||||
# echo "${config.system.build.toplevel}" > $out
|
||||
#'';
|
||||
|
||||
boot.postBootCommands = ''
|
||||
# On the first boot do some maintenance tasks
|
||||
if [ -f /nix-path-registration ]; then
|
||||
${""
|
||||
# TODO : optionally resize NIXOS_SYSTEM, depending on the target.
|
||||
# # Figure out device names for the boot device and root filesystem.
|
||||
# rootPart=$(readlink -f /dev/disk/by-label/NIXOS_SYSTEM)
|
||||
# bootDevice=$(lsblk -npo PKNAME $rootPart)
|
||||
|
||||
# # Resize the root partition and the filesystem to fit the disk
|
||||
# echo ",+," | sfdisk -N2 --no-reread $bootDevice
|
||||
# ${pkgs.parted}/bin/partprobe
|
||||
# ${pkgs.e2fsprogs}/bin/resize2fs $rootPart
|
||||
}
|
||||
|
||||
# Register the contents of the initial Nix store
|
||||
${config.nix.package.out}/bin/nix-store --load-db < /nix-path-registration
|
||||
|
||||
# nixos-rebuild also requires a "system" profile and an /etc/NIXOS tag.
|
||||
touch /etc/NIXOS
|
||||
${config.nix.package.out}/bin/nix-env -p /nix/var/nix/profiles/system --set /run/current-system
|
||||
|
||||
# Prevents this from running on later boots.
|
||||
rm -f /nix-path-registration
|
||||
fi
|
||||
'';
|
||||
|
||||
fileSystems = {
|
||||
"/" = {
|
||||
# Expected to be installed as `system` partition on android-like.
|
||||
# Thus the name.
|
||||
# TODO: move into the android system type.
|
||||
device = "/dev/disk/by-label/NIXOS_SYSTEM";
|
||||
fsType = "ext4";
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user