fix: create derivation for initrd creation
This commit is contained in:
parent
9ff916d0a3
commit
e7470498e5
4 changed files with 137 additions and 129 deletions
|
@ -26,9 +26,9 @@
|
|||
echo "make UKI..."
|
||||
|
||||
mkdir -p patos/efi/boot
|
||||
${self.packages.${system}.systemd.out}/usr/bin/ukify build \
|
||||
--linux ${self.packages.${system}.kernel.kernel}/bzImage \
|
||||
--initrd ./initrd.xz \
|
||||
${patosPkgs.systemd.out}/usr/bin/ukify build \
|
||||
--linux ${patosPkgs.kernel.kernel}/bzImage \
|
||||
--initrd ${patosPkgs.initrd.out}/initrd.xz \
|
||||
--cmdline "console=ttyS0" \
|
||||
-o patos/efi/boot/bootx64.efi
|
||||
'';
|
||||
|
@ -38,8 +38,8 @@
|
|||
systemd = pkgs.callPackage ./systemd { };
|
||||
dbus-broker = pkgs.callPackage ./dbus-broker { };
|
||||
rootfs = pkgs.callPackage ./rootfs { inherit patosPkgs; };
|
||||
initrd = pkgs.callPackage ./rootfs/mkinitrd.nix { inherit patosPkgs; };
|
||||
|
||||
mkinitrd = pkgs.callPackage ./utils/mkinitrd.nix { inherit patosPkgs; };
|
||||
qemu-uefi-tpm = pkgs.callPackage ./utils/qemu-uefi-tpm.nix { };
|
||||
};
|
||||
|
||||
|
|
23
rootfs/mkinitrd.nix
Normal file
23
rootfs/mkinitrd.nix
Normal file
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
pkgs,
|
||||
stdenvNoCC,
|
||||
patosPkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
version = "0.0.1";
|
||||
pname = "patos-ramdisk";
|
||||
in
|
||||
stdenvNoCC.mkDerivation (finalAttrs: {
|
||||
inherit version;
|
||||
inherit pname;
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
cpio
|
||||
xz
|
||||
];
|
||||
|
||||
rootfs = patosPkgs.rootfs.out;
|
||||
|
||||
builder = ./mkinitrd.sh;
|
||||
})
|
110
rootfs/mkinitrd.sh
Normal file
110
rootfs/mkinitrd.sh
Normal file
|
@ -0,0 +1,110 @@
|
|||
set -ex -p pipefail
|
||||
echo "Building initram disk"
|
||||
mkdir -p $out/root
|
||||
pushd $out/root
|
||||
|
||||
### copy rootfs
|
||||
cp -prP $rootfs/* .
|
||||
find . -type d -exec chmod 755 {} \;
|
||||
|
||||
### create directories
|
||||
ln -sf ../usr/lib/systemd/systemd init
|
||||
|
||||
# set default target to basic
|
||||
mkdir usr/lib/systemd/system/basic.target.wants
|
||||
ln -sf basic.target usr/lib/systemd/system/default.target
|
||||
|
||||
# enable dbus broker
|
||||
ln -sf ../dbus-broker.service usr/lib/systemd/system/basic.target.wants/dbus-broker.service
|
||||
ln -sf ../dbus.socket usr/lib/systemd/system/sockets.target.wants/dbus.socket
|
||||
|
||||
### Create needed files
|
||||
echo patos > ./etc/hostname
|
||||
cat <<EOF > ./etc/os-release
|
||||
NAME="PatOS"
|
||||
PRETTY_NAME="PatOS Platform"
|
||||
ID=patos
|
||||
EOF
|
||||
|
||||
cat <<EOF > ./etc/passwd
|
||||
root::0:0:root:/root:/bin/sh
|
||||
bin:x:1:1:bin:/bin:/usr/bin/nologin
|
||||
daemon:x:2:2:daemon:/:/usr/bin/nologin
|
||||
mail:x:8:12:mail:/var/spool/mail:/usr/bin/nologin
|
||||
ftp:x:14:11:ftp:/srv/ftp:/usr/bin/nologin
|
||||
http:x:33:33:http:/srv/http:/usr/bin/nologin
|
||||
uuidd:x:68:68:uuidd:/:/usr/bin/nologin
|
||||
messagebus:x:81:81:messagebus:/:/usr/bin/nologin
|
||||
nobody:x:99:99:nobody:/:/usr/bin/nologin
|
||||
EOF
|
||||
chmod 644 ./etc/passwd
|
||||
|
||||
cat <<EOF > ./etc/group
|
||||
root:x:0:root
|
||||
bin:x:1:root,bin,daemon
|
||||
daemon:x:2:root,bin,daemon
|
||||
sys:x:3:root,bin
|
||||
adm:x:4:root,daemon
|
||||
tty:x:5:
|
||||
disk:x:6:root
|
||||
lp:x:7:daemon
|
||||
mem:x:8:
|
||||
kmem:x:9:
|
||||
wheel:x:10:root
|
||||
ftp:x:11:
|
||||
mail:x:12:
|
||||
uucp:x:14:
|
||||
log:x:19:root
|
||||
utmp:x:20:
|
||||
locate:x:21:
|
||||
rfkill:x:24:
|
||||
smmsp:x:25:
|
||||
proc:x:26:
|
||||
http:x:33:
|
||||
games:x:50:
|
||||
lock:x:54:
|
||||
uuidd:x:68:
|
||||
messagebus:x:81:
|
||||
network:x:90:
|
||||
video:x:91:
|
||||
audio:x:92:
|
||||
optical:x:93:
|
||||
floppy:x:94:
|
||||
storage:x:95:
|
||||
scanner:x:96:
|
||||
input:x:97:
|
||||
power:x:98:
|
||||
nobody:x:99:
|
||||
EOF
|
||||
chmod 644 ./etc/group
|
||||
|
||||
# FIXME: remove this later (just to get a shell in the initramfs)
|
||||
cat <<EOF > usr/lib/systemd/system/demo.service
|
||||
[Unit]
|
||||
Description=Debug Shell (/bin/sulogin)
|
||||
Conflicts=shutdown.target
|
||||
Before=shutdown.target
|
||||
|
||||
[Service]
|
||||
Environment=HOME=/root
|
||||
WorkingDirectory=/root
|
||||
ExecStart=/bin/sulogin
|
||||
Type=idle
|
||||
StandardInput=tty-force
|
||||
StandardOutput=inherit
|
||||
StandardError=inherit
|
||||
KillMode=process
|
||||
IgnoreSIGPIPE=no
|
||||
SendSIGHUP=yes
|
||||
Restart=always
|
||||
|
||||
[Install]
|
||||
WantedBy=basic.target
|
||||
EOF
|
||||
ln -sf ../demo.service usr/lib/systemd/system/basic.target.wants/demo.service
|
||||
|
||||
# gen initrd
|
||||
find . -print0 | cpio --null --owner=root:root -o --format=newc | xz -9 --check=crc32 > ../initrd.xz
|
||||
|
||||
popd
|
||||
rm -rf $out/root
|
|
@ -1,125 +0,0 @@
|
|||
{
|
||||
pkgs,
|
||||
patosPkgs,
|
||||
...
|
||||
}:
|
||||
pkgs.writeShellApplication {
|
||||
name = "mkinitrd";
|
||||
|
||||
runtimeInputs = with pkgs; [
|
||||
cpio
|
||||
xz
|
||||
];
|
||||
|
||||
text = ''
|
||||
echo "Building initram disk"
|
||||
mkdir -p root
|
||||
pushd root
|
||||
|
||||
### copy rootfs
|
||||
cp -prP ${patosPkgs.rootfs}/* .
|
||||
find . -type d -exec chmod 755 {} \;
|
||||
|
||||
### create directories
|
||||
ln -sf ../usr/lib/systemd/systemd init
|
||||
|
||||
# set default target to basic
|
||||
mkdir usr/lib/systemd/system/basic.target.wants
|
||||
ln -sf basic.target usr/lib/systemd/system/default.target
|
||||
|
||||
# enable dbus broker
|
||||
ln -sf ../dbus-broker.service usr/lib/systemd/system/basic.target.wants/dbus.service
|
||||
ln -sf ../dbus.socket usr/lib/systemd/system/sockets.target.wants/dbus.socket
|
||||
|
||||
### Create needed files
|
||||
echo patos > ./etc/hostname
|
||||
cat <<EOF > ./etc/os-release
|
||||
NAME="PatOS"
|
||||
PRETTY_NAME="PatOS Platform"
|
||||
ID=patos
|
||||
EOF
|
||||
|
||||
cat <<EOF > ./etc/passwd
|
||||
root::0:0:root:/root:/bin/sh
|
||||
bin:x:1:1:bin:/bin:/usr/bin/nologin
|
||||
daemon:x:2:2:daemon:/:/usr/bin/nologin
|
||||
mail:x:8:12:mail:/var/spool/mail:/usr/bin/nologin
|
||||
ftp:x:14:11:ftp:/srv/ftp:/usr/bin/nologin
|
||||
http:x:33:33:http:/srv/http:/usr/bin/nologin
|
||||
uuidd:x:68:68:uuidd:/:/usr/bin/nologin
|
||||
messagebus:x:81:81:messagebus:/:/usr/bin/nologin
|
||||
nobody:x:99:99:nobody:/:/usr/bin/nologin
|
||||
EOF
|
||||
chmod 644 ./etc/passwd
|
||||
|
||||
cat <<EOF > ./etc/group
|
||||
root:x:0:root
|
||||
bin:x:1:root,bin,daemon
|
||||
daemon:x:2:root,bin,daemon
|
||||
sys:x:3:root,bin
|
||||
adm:x:4:root,daemon
|
||||
tty:x:5:
|
||||
disk:x:6:root
|
||||
lp:x:7:daemon
|
||||
mem:x:8:
|
||||
kmem:x:9:
|
||||
wheel:x:10:root
|
||||
ftp:x:11:
|
||||
mail:x:12:
|
||||
uucp:x:14:
|
||||
log:x:19:root
|
||||
utmp:x:20:
|
||||
locate:x:21:
|
||||
rfkill:x:24:
|
||||
smmsp:x:25:
|
||||
proc:x:26:
|
||||
http:x:33:
|
||||
games:x:50:
|
||||
lock:x:54:
|
||||
uuidd:x:68:
|
||||
messagebus:x:81:
|
||||
network:x:90:
|
||||
video:x:91:
|
||||
audio:x:92:
|
||||
optical:x:93:
|
||||
floppy:x:94:
|
||||
storage:x:95:
|
||||
scanner:x:96:
|
||||
input:x:97:
|
||||
power:x:98:
|
||||
nobody:x:99:
|
||||
EOF
|
||||
chmod 644 ./etc/group
|
||||
|
||||
# FIXME: remove this later (just to get a shell in the initramfs)
|
||||
cat <<EOF > usr/lib/systemd/system/demo.service
|
||||
[Unit]
|
||||
Description=Debug Shell (/bin/sulogin)
|
||||
Conflicts=shutdown.target
|
||||
Before=shutdown.target
|
||||
|
||||
[Service]
|
||||
Environment=HOME=/root
|
||||
WorkingDirectory=/root
|
||||
ExecStart=/bin/sulogin
|
||||
Type=idle
|
||||
StandardInput=tty-force
|
||||
StandardOutput=inherit
|
||||
StandardError=inherit
|
||||
KillMode=process
|
||||
IgnoreSIGPIPE=no
|
||||
SendSIGHUP=yes
|
||||
Restart=always
|
||||
|
||||
[Install]
|
||||
WantedBy=basic.target
|
||||
EOF
|
||||
ln -sf ../demo.service usr/lib/systemd/system/basic.target.wants/demo.service
|
||||
|
||||
# gen initrd
|
||||
find . -print0 | cpio --null --owner=root:root -o --format=newc | xz -9 --check=crc32 > ../initrd.xz
|
||||
|
||||
popd
|
||||
rm -rf root
|
||||
'';
|
||||
}
|
Loading…
Add table
Reference in a new issue