How do I create a package around myscript
with dependencies resolved?
I think part of my problem is vocabulary. Do I want to create a “package”, a “derivation”, a “flake”, a “module” or what should I really be wanting to do?
It sounds to me like I should build a “package” but Nixpkgs/Create and debug packages - NixOS Wiki is mostly about building from source or binaries. I want to create a package from a working bash script using other nix packages as dependencies.
Similarly, I’d like to create a opensubtitles-download
wrapper around OpenSubtitlesDownload.py
, which has a handful of runtime dependencies, so that I can:
nix-shell -p opensubtitles-download \
--run OpenSubtitlesDownload.py some parameters
And now with 2 instances of a similar problem, I though I’d ask.
Details
Systemd/Timers - NixOS Wiki has this example:
systemd.services."hello-world" = {
script = ''
set -eu
${pkgs.coreutils}/bin/echo "Hello World"
'';
serviceConfig = {
Type = "oneshot";
User = "root";
};
};
I really want to run my bash-based myscript
that for the sake of argument has mailutils
and btrfs-progs
as dependencies. And bash
and unix-utils
for getopt
too, apparently.
How do I package myscript
so that I can run:
${pkgs.myscript}/bin/myscript "Hello World"
Which then implicitly loads the dependencies?
I have succeeded with:
systemd.services."myscript" = {
path = with pkgs; [ mailutils util-linux bash btrfs-progs ];
script = ''
set -eu
/path/to/bin/myscript "Hello World"
'';
serviceConfig = {
Type = "oneshot";
User = "root";
};
};
Which smells to me like a hack because I’d prefer my configuration.nix
didn’t know about the path to or dependencies for myscript
.
I think it should be possible to build a package from this alone:
- The name
myscript
/path/to/myscript
- Dependencies
with pkgs; [ mailutils util-linux bash btrfs-progs ];
- Perhaps an input specifying where to get
pkgs
from
And then my configuration.nix
should now where to get mypkgs
from so I can use mypkgs.myscript
?
I don’t really know where to start.