Browse Source

Clean up makeSystem, move more stuff into module system

Signed-off-by: Magic_RB <magic_rb@redalder.org>
master
Magic_RB 1 month ago
parent
commit
349bad1de3
Signed by: Magic_RB GPG Key ID: 08D5287CC5DDCA0E
5 changed files with 5 additions and 140 deletions
  1. +0
    -3
      flake.nix
  2. +0
    -25
      lib/make-bundle.nix
  3. +0
    -22
      lib/make-initramfs.nix
  4. +0
    -40
      lib/make-iso-image.nix
  5. +5
    -50
      lib/make-system.nix

+ 0
- 3
flake.nix View File

@ -23,10 +23,7 @@
inherit (systemed system) callPackage;
in
{
makeInitramfs = callPackage ./lib/make-initramfs.nix {};
makeBundle = callPackage ./lib/make-bundle.nix;
makeSystem = callPackage ./lib/make-system.nix;
makeBootloader = callPackage ./lib/make-bootloader;
runInVm = callPackage ./lib/vm/run-in-vm.nix;
writeSubstitutedShellScript = callPackage ./lib/write-substituted-shell-script.nix {};
writeSubstitutedFile = callPackage ./lib/write-substituted-file.nix {};


+ 0
- 25
lib/make-bundle.nix View File

@ -1,25 +0,0 @@
{ system
, runCommandNoCC, writeReferencesToFile
, path, name
}:
let
references = writeReferencesToFile path;
in
runCommandNoCC name
{}
''
set -x
shopt -s dotglob
mkdir $out
cp -r ${path}/* $out
for path in $(cat ${references}); do
if [[ -f $path ]]; then
mkdir -p $out/$(dirname $path) ; cp -r $path $out/$path
elif [[ -d $path ]]; then
mkdir -p $out/$path ; cp -r $path/* $out/$path
fi
done
''

+ 0
- 22
lib/make-initramfs.nix View File

@ -1,22 +0,0 @@
{ system
, runCommandNoCC
, findutils, cpio, gzip
}:
{ path, name
, compress ? true
}:
runCommandNoCC name
{ nativeBuildInputs = [
findutils
cpio
gzip
];
}
(if compress then
''
( cd ${path} ; find . | cpio -o -H newc --quiet | gzip -9 ) > $out
''
else
''
( cd ${path} ; find . | cpio -o -H newc --quiet ) > $out
'')

+ 0
- 40
lib/make-iso-image.nix View File

@ -1,40 +0,0 @@
{ nglib, writeShellScript
, busybox, utillinux, dosfstools, e2fsprogs, parted, grub2
, system
}:
assert system.config.bootloader.enable;
nglib.runInVm {
preProcess = writeShellScript "script"
''
export PATH=${busybox}/bin:${parted}/bin
set -e
dd if=/dev/zero of=$xchg/out/image.img bs=1024 count=524288
parted --script $xchg/out/image.img \
mklabel msdos \
mkpart primary 1MiB 100%
'';
script = writeShellScript "script"
''
export PATH=${dosfstools}/bin:${e2fsprogs}/bin:${utillinux}/bin:${busybox}/bin:${parted}/bin:${grub2}/bin
set -e
_root=$(mktemp -d)
_loopdev=$(losetup -f)
losetup -P $_loopdev $out/image.img
mkfs.ext4 ''${_loopdev}p1
mount ''${_loopdev}p1 $_root
cp -r ${system.bundle}/* $_root
mkdir -p $_root/boot $_root/etc
ln -sfn /proc/mounts $_root/etc/mtab
grub-install --root-directory=$_root --boot-directory=$_root/boot --target=i386-pc /dev/loop0
'';
}

+ 5
- 50
lib/make-system.nix View File

@ -1,12 +1,12 @@
{ pkgs, callPackage, system, dockerTools
, runCommandNoCC, lib, nglib
, busybox, bootloaderLinux
, config, name
, busybox, config, name
}:
let
defaultModules = [
../modules/runit
../modules/dumb-init
../modules/initrd
../modules/initramfs
../modules/init.nix
@ -20,6 +20,8 @@ let
../modules/services/apache2-nixos.nix
../modules/services/gitea.nix
../modules/services/getty.nix
../modules/services/socklog.nix
../modules/services/crond.nix
];
evaledModules = lib.evalModules
@ -39,52 +41,5 @@ let
throw "\nFailed assertions:\n${lib.concatStringsSep "\n" (map (x: "- ${x}") failedAssertions)}"
else
evaledModules.config;
systemPath =
runCommandNoCC name
{ nativeBuildInputs = [
busybox
];
}
(with configValid;
''
mkdir $out
ln -s ${init.script} $out/init
ln -s ${configValid.system.activationScript} $out/activation
'');
systemBundle = nglib.makeBundle
{ name = "${name}-bundle";
path = systemPath;
};
initramfsImage = nglib.makeInitramfs
{ name = "${name}-initrd.img";
path = systemBundle;
};
qemu = {
run = pkgs.writeShellScript "qemu-run.sh" ''
${pkgs.qemu}/bin/qemu-system-x86_64 -kernel ${systemPath}/bootloader -initrd ${systemPath}/initrd.img -nographic -append "console=ttyS0" -m 512
''; # /run/current-system/kernel
};
self = {
system = systemPath;
bundle = systemBundle;
initramfs = initramfsImage;
config = evaledModules.config;
iso = callPackage ./make-iso-image.nix { system = self; };
inherit qemu;
ociImage = dockerTools.buildLayeredImage {
inherit name;
tag = "latest";
contents = [ systemBundle ];
config = {
StopSignal = "SIGCONT";
Entrypoint =
[ "/init"
];
};
};
};
in
self
evaledModules // { config = configValid; }

Loading…
Cancel
Save