makeCpioRecursive: init
This commit is contained in:
parent
ecf42daa66
commit
6ecf5bfa0f
27
pkgs/cpio-recursive/default.nix
Normal file
27
pkgs/cpio-recursive/default.nix
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
{ runCommand, nix, jq, path }:
|
||||||
|
let
|
||||||
|
map-cpio = ./map-cpio.nix;
|
||||||
|
|
||||||
|
makeCpioRecursive = { name, root, prepend ? [], compressor }:
|
||||||
|
runCommand "${name}-initrd" {
|
||||||
|
buildInputs = [ nix jq ];
|
||||||
|
requiredSystemFeatures = [ "recursive-nix" ];
|
||||||
|
exportReferencesGraph = [ "root" root ];
|
||||||
|
NIX_PATH = "nixpkgs=${path}";
|
||||||
|
inherit prepend compressor;
|
||||||
|
} ''
|
||||||
|
|
||||||
|
cat root | grep /nix/store | sort | uniq | jq -R . | jq -s . > paths.json
|
||||||
|
nix-build ${map-cpio} --arg pathsJson ./paths.json --argstr compressor "$compressor"
|
||||||
|
|
||||||
|
touch initrd
|
||||||
|
for pre in $prepend; do
|
||||||
|
cat "$pre" >> initrd
|
||||||
|
done
|
||||||
|
|
||||||
|
cat result | xargs cat >> initrd
|
||||||
|
mkdir $out
|
||||||
|
mv initrd $out/initrd
|
||||||
|
'';
|
||||||
|
in
|
||||||
|
makeCpioRecursive
|
||||||
25
pkgs/cpio-recursive/map-cpio.nix
Normal file
25
pkgs/cpio-recursive/map-cpio.nix
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
{ pathsJson, compressor, pkgs ? import <nixpkgs> {} }:
|
||||||
|
let
|
||||||
|
namePart = strPath:
|
||||||
|
let
|
||||||
|
last = list: builtins.elemAt list ((builtins.length list) - 1);
|
||||||
|
stripPathPrefix = path: last (builtins.split "[/]" path);
|
||||||
|
in
|
||||||
|
stripPathPrefix "${strPath}";
|
||||||
|
|
||||||
|
paths = builtins.fromJSON (builtins.readFile pathsJson);
|
||||||
|
mkcpio = strPath: pkgs.runCommand "${namePart strPath}-cpio" {
|
||||||
|
buildInputs = [ pkgs.cpio ];
|
||||||
|
} ''
|
||||||
|
mkdir root
|
||||||
|
cd root
|
||||||
|
cp -prd --parents ${builtins.storePath strPath} .
|
||||||
|
find . -print0 | xargs -0r touch -h -d '@1'
|
||||||
|
find . -print0 \
|
||||||
|
| sort -z \
|
||||||
|
| cpio -o -H newc -R +0:+1 --reproducible --null \
|
||||||
|
| ${compressor} \
|
||||||
|
> $out
|
||||||
|
'';
|
||||||
|
in
|
||||||
|
pkgs.writeText "cpios" (pkgs.lib.concatMapStringsSep "\n" mkcpio paths)
|
||||||
4
pkgs/default.nix
Normal file
4
pkgs/default.nix
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{ callPackage }:
|
||||||
|
{
|
||||||
|
makeCpioRecursive = callPackage ./cpio-recursive {};
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user