1
0
Fork 0

Compare commits

...

3 Commits

3 changed files with 205 additions and 15 deletions

View File

@ -9,19 +9,13 @@
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
patched-not-os = let
remote-patches = [
{
# Zynq image various fixes and cleanup
url = "https://patch-diff.githubusercontent.com/raw/cleverca22/not-os/pull/28.patch";
sha256 = "sha256-EnYb95QfwHmUHfbCT9tL291mC8Tze0Koadb11arvTDY=";
}
];
local-patches = [ ./not-os.patch ];
in pkgs.applyPatches {
patched-not-os = pkgs.applyPatches {
name = "not-os-patched";
src = not-os;
patches = map pkgs.fetchpatch remote-patches ++ local-patches;
patches = [
./pr-28.patch
./pr-29.patch
];
};
gnu-platform = "arm-none-eabi";

183
pr-28.patch Normal file
View File

@ -0,0 +1,183 @@
diff --git a/base.nix b/base.nix
index 7eaee32..f767d5e 100644
--- a/base.nix
+++ b/base.nix
@@ -27,6 +27,11 @@ with lib;
description = "enable rngd";
default = false;
};
+ not-os.sd = mkOption {
+ type = types.bool;
+ default = false;
+ description = "enable sd image support";
+ };
not-os.simpleStaticIp = mkOption {
type = types.bool;
default = false;
diff --git a/stage-1.nix b/stage-1.nix
index 331fecd..85fda30 100644
--- a/stage-1.nix
+++ b/stage-1.nix
@@ -164,7 +164,9 @@ let
mkdir -p /mnt/nix/store/
- ${if config.not-os.nix then ''
+ ${if config.not-os.sd && config.not-os.nix then ''
+ mount $root /mnt
+ '' else if config.not-os.nix then ''
# make the store writeable
mkdir -p /mnt/nix/.ro-store /mnt/nix/.overlay-store /mnt/nix/store
mount $root /mnt/nix/.ro-store -t squashfs
@@ -190,6 +192,11 @@ let
initialRamdisk = pkgs.makeInitrd {
contents = [ { object = bootStage1; symlink = "/init"; } ];
};
+ # Use for zynq_image
+ uRamdisk = pkgs.makeInitrd {
+ makeUInitrd = true;
+ contents = [ { object = bootStage1; symlink = "/init"; } ];
+ };
in
{
options = {
@@ -205,6 +212,7 @@ in
config = {
system.build.bootStage1 = bootStage1;
system.build.initialRamdisk = initialRamdisk;
+ system.build.uRamdisk = uRamdisk;
system.build.extraUtils = extraUtils;
boot.initrd.availableKernelModules = [ ];
boot.initrd.kernelModules = [ "tun" "loop" "squashfs" ] ++ (lib.optional config.not-os.nix "overlay");
diff --git a/stage-2.nix b/stage-2.nix
index c61f9d6..4e30d4b 100644
--- a/stage-2.nix
+++ b/stage-2.nix
@@ -21,6 +21,11 @@ with lib;
type = types.str;
};
};
+ networking.hostName = mkOption {
+ default = "";
+ type = types.strMatching
+ "^$|^[[:alnum:]]([[:alnum:]_-]{0,61}[[:alnum:]])?$";
+ };
};
config = {
system.build.bootStage2 = pkgs.substituteAll {
diff --git a/zynq_image.nix b/zynq_image.nix
index 3fa23ab..484a063 100644
--- a/zynq_image.nix
+++ b/zynq_image.nix
@@ -1,66 +1,62 @@
{ config, pkgs, ... }:
let
- # dont use overlays for the qemu, it causes a lot of wasted time on recompiles
- x86pkgs = import pkgs.path { system = "x86_64-linux"; };
- customKernel = pkgs.linux.override {
+ crosspkgs = import pkgs.path {
+ system = "x86_64-linux";
+ crossSystem = {
+ system = "armv7l-linux";
+ linux-kernel = {
+ name = "zynq";
+ baseConfig = "multi_v7_defconfig";
+ target = "uImage";
+ installTarget = "uImage";
+ autoModules = false;
+ DTB = true;
+ makeFlags = [ "LOADADDR=0x8000" ];
+ };
+ };
+ };
+ customKernel = (crosspkgs.linux.override {
extraConfig = ''
OVERLAY_FS y
'';
- };
- customKernelPackages = pkgs.linuxPackagesFor customKernel;
+ }).overrideAttrs (oa: {
+ postInstall = ''
+ cp arch/arm/boot/uImage $out
+ ${oa.postInstall}
+ '';
+ });
+ customKernelPackages = crosspkgs.linuxPackagesFor customKernel;
in {
imports = [ ./arm32-cross-fixes.nix ];
boot.kernelPackages = customKernelPackages;
nixpkgs.system = "armv7l-linux";
- system.build.zynq_image = let
- cmdline = "root=/dev/mmcblk0 console=ttyPS0,115200n8 systemConfig=${builtins.unsafeDiscardStringContext config.system.build.toplevel}";
- qemuScript = ''
- #!/bin/bash -v
- export PATH=${x86pkgs.qemu}/bin:$PATH
- set -x
- base=$(dirname $0)
-
- cp $base/root.squashfs /tmp/
- chmod +w /tmp/root.squashfs
- truncate -s 64m /tmp/root.squashfs
-
- qemu-system-arm \
- -M xilinx-zynq-a9 \
- -serial /dev/null \
- -serial stdio \
- -display none \
- -dtb $base/zynq-zc702.dtb \
- -kernel $base/zImage \
- -initrd $base/initrd \
- -drive file=/tmp/root.squashfs,if=sd,format=raw \
- -append "${cmdline}"
- '';
- in pkgs.runCommand "zynq_image" {
- inherit qemuScript;
- passAsFile = [ "qemuScript" ];
+ networking.hostName = "zynq";
+ not-os.sd = true;
+ system.build.zynq_image = pkgs.runCommand "zynq_image" {
preferLocalBuild = true;
} ''
mkdir $out
cd $out
- cp -s ${config.system.build.squashfs} root.squashfs
- cp -s ${config.system.build.kernel}/*zImage .
- cp -s ${config.system.build.initialRamdisk}/initrd initrd
- cp -s ${config.system.build.kernel}/dtbs/zynq-zc702.dtb .
+ cp -s ${config.system.build.kernel}/uImage .
+ cp -s ${config.system.build.uRamdisk}/initrd uRamdisk.image.gz
+ cp -s ${config.system.build.kernel}/dtbs/zynq-zc706.dtb devicetree.dtb
ln -sv ${config.system.build.toplevel} toplevel
- cp $qemuScriptPath qemu-script
- chmod +x qemu-script
- patchShebangs qemu-script
- ls -ltrh
- '';
- system.build.rpi_image_tar = pkgs.runCommand "dist.tar" {} ''
- mkdir -p $out/nix-support
- tar -cvf $out/dist.tar ${config.system.build.rpi_image}
- echo "file binary-dist $out/dist.tar" >> $out/nix-support/hydra-build-products
'';
- environment.systemPackages = [ pkgs.strace ];
- environment.etc."service/getty/run".source = pkgs.writeShellScript "getty" ''
- agetty ttyPS0 115200
- '';
- environment.etc."pam.d/other".text = "";
+ environment = {
+ systemPackages = with pkgs; [ strace inetutils ];
+ etc = {
+ "service/getty/run".source = pkgs.writeShellScript "getty" ''
+ hostname ${config.networking.hostName}
+ agetty ttyPS0 115200
+ '';
+ "pam.d/other".text = ''
+ auth sufficient pam_permit.so
+ account required pam_permit.so
+ password required pam_permit.so
+ session optional pam_env.so
+ '';
+ "security/pam_env.conf".text = "";
+ };
+ };
}

View File

@ -1,8 +1,8 @@
diff --git a/base.nix b/base.nix
index 7eaee32..b5a61ee 100644
index 7eaee32..c1881cb 100644
--- a/base.nix
+++ b/base.nix
@@ -155,7 +155,23 @@ with lib;
@@ -155,6 +155,23 @@ with lib;
# dummy to make setup-etc happy
'';
system.activationScripts.etc = stringAfter [ "users" "groups" ] config.system.build.etcActivationCommands;
@ -10,7 +10,7 @@ index 7eaee32..b5a61ee 100644
+ # See https://github.com/NixOS/nixpkgs/commit/59e37267556eb917146ca3110ab7c96905b9ffbd
+ system.activationScripts.var = lib.mkForce ''
+ # Various log/runtime directories.
+
+ mkdir -p /var/tmp
+ chmod 1777 /var/tmp
+
@ -23,6 +23,19 @@ index 7eaee32..b5a61ee 100644
+ chown root:root /var/empty
+ ${pkgs.e2fsprogs}/bin/chattr -f +i /var/empty || true
+ '';
# nix-build -A system.build.toplevel && du -h $(nix-store -qR result) --max=0 -BM|sort -n
system.build.toplevel = pkgs.runCommand "not-os" {
activationScript = config.system.activationScripts.script;
diff --git a/systemd-compat.nix b/systemd-compat.nix
index 11464c6..cb223b8 100644
--- a/systemd-compat.nix
+++ b/systemd-compat.nix
@@ -9,6 +9,8 @@ with lib;
};
systemd.user = mkOption {
};
+ systemd.tmpfiles = mkOption {
+ };
};
config = {
};