Skip to content

Instantly share code, notes, and snippets.

@Quelklef
Last active May 29, 2023 19:18
Show Gist options
  • Save Quelklef/48291d934d2c2a3606a7b20207ed428b to your computer and use it in GitHub Desktop.
Save Quelklef/48291d934d2c2a3606a7b20207ed428b to your computer and use it in GitHub Desktop.
{
environment.etc = {
# Utility scripts. Must be manually symlinked into /root
"my-scripts".source = let
scripts = [
{
"script-name.sh" = ''
echo 'script content';
'';
}
(
let condition = false; in
if condition
then { "other-script.sh" = "echo 'other content'"; }
else null # gets excluded
)
];
in pkgs.stdenv.mkDerivation {
name = "etc-util-scripts";
dontUnpack = true;
installPhase = ''
mkdir -p $out
${ let inherit (pkgs.lib) trivial attrsets strings lists; in
trivial.pipe scripts [
(lists.filter (x: x != null))
(lists.foldl trivial.mergeAttrs {})
(attrsets.mapAttrsToList
(name: text: "cp ${pkgs.writeScript name text} $out/${name}\n"))
strings.concatStrings
] }
'';
};
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment