forked from M-Labs/nix-servo
zynq: add first boot commands
This commit is contained in:
parent
bd4885c597
commit
c74391e94e
81
pr-28.patch
81
pr-28.patch
@ -49,29 +49,61 @@ index 331fecd..85fda30 100644
|
|||||||
system.build.extraUtils = extraUtils;
|
system.build.extraUtils = extraUtils;
|
||||||
boot.initrd.availableKernelModules = [ ];
|
boot.initrd.availableKernelModules = [ ];
|
||||||
boot.initrd.kernelModules = [ "tun" "loop" "squashfs" ] ++ (lib.optional config.not-os.nix "overlay");
|
boot.initrd.kernelModules = [ "tun" "loop" "squashfs" ] ++ (lib.optional config.not-os.nix "overlay");
|
||||||
|
diff --git a/stage-2-init.sh b/stage-2-init.sh
|
||||||
|
index 6cc08e2..0c854c4 100644
|
||||||
|
--- a/stage-2-init.sh
|
||||||
|
+++ b/stage-2-init.sh
|
||||||
|
@@ -19,4 +19,7 @@ mount -t tmpfs tmpfs /dev/shm
|
||||||
|
|
||||||
|
$systemConfig/activate
|
||||||
|
|
||||||
|
+# Run any user-specified commands.
|
||||||
|
+@runtimeShell@ @postBootCommands@
|
||||||
|
+
|
||||||
|
exec runit
|
||||||
diff --git a/stage-2.nix b/stage-2.nix
|
diff --git a/stage-2.nix b/stage-2.nix
|
||||||
index c61f9d6..4e30d4b 100644
|
index c61f9d6..46cf260 100644
|
||||||
--- a/stage-2.nix
|
--- a/stage-2.nix
|
||||||
+++ b/stage-2.nix
|
+++ b/stage-2.nix
|
||||||
@@ -21,6 +21,11 @@ with lib;
|
@@ -20,6 +20,19 @@ with lib;
|
||||||
|
example = "256m";
|
||||||
type = types.str;
|
type = types.str;
|
||||||
};
|
};
|
||||||
};
|
+ postBootCommands = mkOption {
|
||||||
|
+ default = "";
|
||||||
|
+ example = "rm -f /var/log/messages";
|
||||||
|
+ type = types.lines;
|
||||||
|
+ description = lib.mdDoc ''
|
||||||
|
+ Shell commands to be executed just before runnit is started.
|
||||||
|
+ '';
|
||||||
|
+ };
|
||||||
|
+ };
|
||||||
+ networking.hostName = mkOption {
|
+ networking.hostName = mkOption {
|
||||||
+ default = "";
|
+ default = "";
|
||||||
+ type = types.strMatching
|
+ type = types.strMatching
|
||||||
+ "^$|^[[:alnum:]]([[:alnum:]_-]{0,61}[[:alnum:]])?$";
|
+ "^$|^[[:alnum:]]([[:alnum:]_-]{0,61}[[:alnum:]])?$";
|
||||||
+ };
|
};
|
||||||
};
|
};
|
||||||
config = {
|
config = {
|
||||||
system.build.bootStage2 = pkgs.substituteAll {
|
@@ -28,6 +41,9 @@ with lib;
|
||||||
|
isExecutable = true;
|
||||||
|
path = config.system.path;
|
||||||
|
inherit (pkgs) runtimeShell;
|
||||||
|
+ postBootCommands = pkgs.writeText "local-cmds" ''
|
||||||
|
+ ${config.boot.postBootCommands}
|
||||||
|
+ '';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
diff --git a/zynq_image.nix b/zynq_image.nix
|
diff --git a/zynq_image.nix b/zynq_image.nix
|
||||||
index 3fa23ab..695d876 100644
|
index 3fa23ab..06dd1a5 100644
|
||||||
--- a/zynq_image.nix
|
--- a/zynq_image.nix
|
||||||
+++ b/zynq_image.nix
|
+++ b/zynq_image.nix
|
||||||
@@ -1,66 +1,63 @@
|
@@ -1,66 +1,90 @@
|
||||||
{ config, pkgs, ... }:
|
-{ config, pkgs, ... }:
|
||||||
|
+{ lib, config, pkgs, ... }:
|
||||||
|
|
||||||
|
+with lib;
|
||||||
let
|
let
|
||||||
- # dont use overlays for the qemu, it causes a lot of wasted time on recompiles
|
- # dont use overlays for the qemu, it causes a lot of wasted time on recompiles
|
||||||
- x86pkgs = import pkgs.path { system = "x86_64-linux"; };
|
- x86pkgs = import pkgs.path { system = "x86_64-linux"; };
|
||||||
@ -154,17 +186,15 @@ index 3fa23ab..695d876 100644
|
|||||||
- chmod +x qemu-script
|
- chmod +x qemu-script
|
||||||
- patchShebangs qemu-script
|
- patchShebangs qemu-script
|
||||||
- ls -ltrh
|
- ls -ltrh
|
||||||
- '';
|
'';
|
||||||
- system.build.rpi_image_tar = pkgs.runCommand "dist.tar" {} ''
|
- system.build.rpi_image_tar = pkgs.runCommand "dist.tar" {} ''
|
||||||
- mkdir -p $out/nix-support
|
- mkdir -p $out/nix-support
|
||||||
- tar -cvf $out/dist.tar ${config.system.build.rpi_image}
|
- tar -cvf $out/dist.tar ${config.system.build.rpi_image}
|
||||||
- echo "file binary-dist $out/dist.tar" >> $out/nix-support/hydra-build-products
|
- echo "file binary-dist $out/dist.tar" >> $out/nix-support/hydra-build-products
|
||||||
'';
|
- '';
|
||||||
- environment.systemPackages = [ pkgs.strace ];
|
- environment.systemPackages = [ pkgs.strace ];
|
||||||
- environment.etc."service/getty/run".source = pkgs.writeShellScript "getty" ''
|
- environment.etc."service/getty/run".source = pkgs.writeShellScript "getty" ''
|
||||||
- agetty ttyPS0 115200
|
- agetty ttyPS0 115200
|
||||||
- '';
|
|
||||||
- environment.etc."pam.d/other".text = "";
|
|
||||||
+ environment = {
|
+ environment = {
|
||||||
+ systemPackages = with pkgs; [ strace inetutils ];
|
+ systemPackages = with pkgs; [ strace inetutils ];
|
||||||
+ etc = {
|
+ etc = {
|
||||||
@ -181,4 +211,31 @@ index 3fa23ab..695d876 100644
|
|||||||
+ "security/pam_env.conf".text = "";
|
+ "security/pam_env.conf".text = "";
|
||||||
+ };
|
+ };
|
||||||
+ };
|
+ };
|
||||||
|
+ boot.postBootCommands = lib.mkIf config.not-os.sd ''
|
||||||
|
+ # On the first boot do some maintenance tasks
|
||||||
|
+ if [ -f /nix-path-registration ]; then
|
||||||
|
+ set -euo pipefail
|
||||||
|
+ set -x
|
||||||
|
+ # Figure out device names for the boot device and root filesystem.
|
||||||
|
+ rootPart=$(${pkgs.utillinux}/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
|
||||||
|
+
|
||||||
|
+ # Register the contents of the initial Nix store
|
||||||
|
+ nix-store --load-db < /nix-path-registration
|
||||||
|
+
|
||||||
|
+ # nixos-rebuild also requires a "system" profile and an /etc/NIXOS tag.
|
||||||
|
+ touch /etc/NIXOS
|
||||||
|
+ 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
|
||||||
|
'';
|
||||||
|
- environment.etc."pam.d/other".text = "";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user