add nixos module
This commit is contained in:
parent
79b4f7454d
commit
c436983153
3 changed files with 166 additions and 2 deletions
43
base.nix
43
base.nix
|
@ -1,4 +1,4 @@
|
|||
{ config, pkgs, modulesPath, ... }: {
|
||||
{ config, pkgs, lib, modulesPath, ... }: {
|
||||
fileSystems = {
|
||||
"/boot" = {
|
||||
device = "/dev/disk/by-label/nixos-boot";
|
||||
|
@ -16,11 +16,50 @@
|
|||
system.build.rootFileSystem = pkgs.callPackage (modulesPath + "/../lib/make-ext4-fs.nix") {
|
||||
storePaths = with pkgs; [
|
||||
config.system.build.toplevel
|
||||
busybox
|
||||
];
|
||||
volumeLabel = "nixos-root";
|
||||
populateImageCommands = ''
|
||||
cp ${config.system.build.toplevel}/init ./files/init
|
||||
touch ./files/firstboot
|
||||
'';
|
||||
};
|
||||
|
||||
# from https://github.com/NixOS/nixpkgs/blob/e405f30513169feedb64b5c25e7b00242010af58/nixos/modules/installer/sd-card/sd-image.nix#L267
|
||||
boot.postBootCommands = let
|
||||
expandOnBoot = ''
|
||||
# Figure out device names for the boot device and root filesystem.
|
||||
rootPart=$(${pkgs.util-linux}/bin/findmnt -n -o SOURCE /)
|
||||
bootDevice=$(lsblk -npo PKNAME $rootPart)
|
||||
partNum=$(lsblk -npo MAJ:MIN $rootPart | ${pkgs.gawk}/bin/awk -F: '{print $2}')
|
||||
|
||||
# Resize the root partition and the filesystem to fit the disk
|
||||
echo ",+," | sfdisk -N$partNum --no-reread $bootDevice
|
||||
${pkgs.parted}/bin/partprobe
|
||||
${pkgs.e2fsprogs}/bin/resize2fs $rootPart
|
||||
'';
|
||||
firstbootFile = "/firstboot";
|
||||
in ''
|
||||
# On the first boot do some maintenance tasks
|
||||
if [ -f ${firstbootFile} ]; then
|
||||
set -euo pipefail
|
||||
set -x
|
||||
|
||||
${expandOnBoot}
|
||||
|
||||
# TODO what does all this do?
|
||||
|
||||
# Register the contents of the initial Nix store
|
||||
# ${config.nix.package.out}/bin/nix-store --load-db < ${firstbootFile}
|
||||
|
||||
# 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 ${firstbootFile}
|
||||
fi
|
||||
'';
|
||||
|
||||
# system.build.usbImage = pkgs.callPackage ({ stdenvNoCC }: stdenvNoCC.mkDerivation {
|
||||
# name = "nixos-ps4-usbimage";
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue