This nix file nixifies a script after which I can call it in the cli. How can I use/call this script, “my-custom-script”, inside another nix file.
{ config
, lib
, pkgs
, ...
}:
with lib; let
bashScript = name: scriptDependencies: (
pkgs.resholve.writeScriptBin
"${name}"
{
interpreter = "${pkgs.bash}/bin/bash";
inputs = scriptDependencies;
fake.external = [ "sudo" "ping" "mount" "umount" ];
execer = [
"cannot:${pkgs.git}/bin/git"
"cannot:${pkgs.gzip}/bin/uncompress"
"cannot:${pkgs.networkmanager}/bin/nmcli"
"cannot:${pkgs.nixos-install-tools}/bin/nixos-generate-config"
"cannot:${pkgs.nixos-install-tools}/bin/nixos-install"
"cannot:${pkgs.nixos-rebuild}/bin/nixos-rebuild"
"cannot:${pkgs.nix}/bin/nix"
"cannot:${pkgs.nix}/bin/nix-collect-garbage"
"cannot:${pkgs.openssh}/bin/ssh"
"cannot:${pkgs.p7zip}/bin/7z"
"cannot:${pkgs.p7zip}/bin/7za"
"cannot:${pkgs.procps}/bin/pkill"
"cannot:${pkgs.rsync}/bin/rsync"
"cannot:${pkgs.sway}/bin/swaymsg"
"cannot:${pkgs.systemd}/bin/systemctl"
"cannot:${pkgs.util-linux}/bin/swapon"
"cannot:${pkgs.wl-clipboard}/bin/wl-copy"
"cannot:${pkgs.wpa_supplicant}/bin/wpa_passphrase"
];
}
(builtins.readFile ../../scripts/${
name}.sh)
);
my-custom-script = bashScript "my-custom-script" (with pkgs; [
coreutils
util-linux
gawk
gnugrep
gnused
parted
cryptsetup
exfat
e2fsprogs # ext4
]);
in
{
config = {
environment.systemPackages = with pkgs; [
my-custom-script
];
}
}
I’d like to call my-custom-script inside a udev run script.
{ config
, lib
, pkgs
, ...
}:
with lib;
{
config = lib.mkIf cfg.enable {
# udevadm info -a -p /sys/block/sdc | ag serial
services.udev.extraRules =
let
usbAddScript = pkgs.writeScript "usb-add-script" ''
#!${pkgs.stdenv.shell}
my-custom-script
'';
in
''
ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="0000", ATTRS{idProduct}=="0000", ATTRS{serial}=="xxxxxxxxxxxx", RUN+="${usbAddScript}"
'';
};
}