I’m trying to install a shell script (with 1 line) on NixOS for the last 4 hours.
I always get obscure error messages like:
error: syntax error, unexpected ELLIPSIS, expecting '}', at /root/nixos-config/machines/targets-host-lxc/configuration.nix:5:25
error: cannot coerce a set to a string, at /root/nixos-config/machines/targets-host-lxc/configuration.nix:11:5 (where line 11 is: name = "target-ips";)
error: The option value `environment.systemPackages.[definition 4-entry 1]' in `/etc/nixos/configuration.nix' is not of type `package'.
Here is an example from nixpkgs where it works: nixpkgs/default.nix at 63f93407b9fba499dc0cfcfb56b665ba063b67bb · NixOS/nixpkgs · GitHub
But it don’t work on my system with this effort:
configuration.nix
{ config, pkgs, ... }:
let
target_ips = pkgs.callPackage ./target-ips.nix;
in
{
...
environment.systemPackages = with pkgs; [ target_ips ];
}
target-ips.nix
{ substituteAll, lib, lxd, jq }:
substituteAll {
name = "target-ips";
src = ./target-ips.sh;
dir = "bin";
isExecutable = true;
inherit lxd jq;
meta = with lib; {
description = "Output IPs of running LXC containers";
license = [ licenses.mit ];
maintainers = with maintainers; [ davidak ];
platforms = platforms.linux;
};
}
target-ips.sh
#! @shell@
for i in $(@lxd@/bin/lxc list -c 4 --format json | @jq@/bin/jq --raw-output 'map(select(.state.network.eth0.addresses[0].address != null)) | .[] | .state.network.eth0.addresses[0].address'); do echo -n "$i,"; done
I had it working without substituting lxc and jq, but that is considered bad practice. (but i noticed it is also done in nixos core tools like nixos-install, but that is only used on NixOS where the programs SHOULD be present )
What is the simplest way to get this shell script installed on my system?
I have seen this in nixpkgs, but it don’t work in configuration.nix
:
substituteAll ${./common-lisp.sh} "$out"/bin/common-lisp.sh