How to add user-callable scripts to the environment?

瀏覽次數:115 次
跳到第一則未讀訊息

Pavel Goran

未讀,
2018年6月16日 中午12:48:492018/6/16
收件者:nix-devel
There is probably a well-known answer to this question, but I don't know where to look for it.

I want to have a certain script available for invocation on a NixOS system. The script is a completely custom piece that does things specific to the machine (say, downloads some data I need there), thus it's not suitable to be a software package with a VSC repository, metadata and stuff. I just want to include it in configuration.nix (it's short enough for it) without much overhead, and call it from the shell. How do I do this?

Some additional details. The script needs to accept parameters, and it needs to be invoked by a user (well, an administrator) at arbitrary times (not during system startup or activation). This prevents me from putting it into the "script' attribute of a systemd service.

Graham Christensen

未讀,
2018年6月16日 中午12:57:312018/6/16
收件者:Pavel Goran、nix-devel
Hi Pavel,

You can add the following to your system packages:

environment.systemPackages = [
  (pkgs.writeShellScriptBin "my-cool-script" ''
    echo "hello, here are my args!" "$@"
  '')
];

# nixos-rebuild switch
$ my-cool-script foo bar
hello, here are my args! foo bar

--
You received this message because you are subscribed to the Google Groups "nix-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nix-devel+...@googlegroups.com.
To post to this group, send email to nix-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nix-devel/332886b5-8d7a-4f9f-8a56-1c8c8b18471a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Pavel Goran

未讀,
2018年6月16日 下午1:00:102018/6/16
收件者:nix-devel
Thanks. Exactly what I was looking for!

суббота, 16 июня 2018 г., 23:57:31 UTC+7 пользователь Graham Christensen написал:
回覆所有人
回覆作者
轉寄
0 則新訊息