Files
nixpkgs/pkgs/os-specific/linux/minimal-bootstrap/utils.nix
Dark Steveneq 646b892680
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s
push sheeet
2025-10-09 14:15:47 +02:00

80 lines
1.8 KiB
Nix

{
lib,
buildPlatform,
callPackage,
kaem,
mescc-tools-extra,
checkMeta,
}:
rec {
derivationWithMeta =
attrs:
let
passthru = attrs.passthru or { };
validity = checkMeta.assertValidity { inherit meta attrs; };
meta = checkMeta.commonMeta { inherit validity attrs; };
baseDrv = derivation (
{
inherit (buildPlatform) system;
inherit (meta) name;
}
// (removeAttrs attrs [
"meta"
"passthru"
])
);
passthru' =
passthru
// lib.optionalAttrs (passthru ? tests) {
tests = lib.mapAttrs (_: f: f baseDrv) passthru.tests;
};
in
lib.extendDerivation validity.handled (
{
inherit meta;
passthru = passthru';
}
// passthru'
) baseDrv;
writeTextFile =
{
name, # the name of the derivation
text,
executable ? false, # run chmod +x ?
destination ? "", # relative path appended to $out eg "/bin/foo"
}:
derivationWithMeta {
inherit name text;
passAsFile = [ "text" ];
builder = "${kaem}/bin/kaem";
args = [
"--verbose"
"--strict"
"--file"
(builtins.toFile "write-text-file.kaem" (
''
target=''${out}''${destination}
''
+ lib.optionalString (dirOf destination == ".") ''
mkdir -p ''${out}''${destinationDir}
''
+ ''
cp ''${textPath} ''${target}
''
+ lib.optionalString executable ''
chmod 555 ''${target}
''
))
];
PATH = lib.makeBinPath [ mescc-tools-extra ];
destinationDir = dirOf destination;
inherit destination;
};
writeText = name: text: writeTextFile { inherit name text; };
}