Declarative configuration for GNU Rush?

I’m trying to make my configuration.nix file create a user who’s shell is GNU Rush. In order for GNU Rush to be useful, you have to create a configuration file for it. According to Rush’s manual, “[t]he configuration file rush.rc is located in /usr/local/etc by default.” I took a look at the rush package’s Nix expression. As far as I can tell, there’s nothing in that Nix expression that would change that default configuration file location.

I know that I can use environment.etc to declaratively add files to /etc. How would I declaratively add files to /usr/local/etc? Is there a way to configure GNU Rush without adding files to /usr/local/etc?

1 Like

But to actually answer your question (sorry about that):

{
  systemd.tmpfiles.rules =
    let
      rushCfg = pkgs.writeText "rush.rc" ''
        what_ever_the contents are ....
      '';
    in
    [
      "L+ /usr/local/etc/rush.rc - - - - ${rushCfg}"
    ];
}

1 Like

That answer was helpful, but unfortunately it didn’t work:

$ cat /usr/local/etc/rush.rc
rush 2.0

rule test-rule
        match $command == "echo hi"

$ # These two commands work as expected:
$ rush --test /usr/local/etc/rush.rc -c 'echo hi'; echo "$?"
0
$ rush --test /usr/local/etc/rush.rc -c 'echo bye'; echo "$?"
rush: Error: no matching rule for "echo bye", user jayman
1

$ # These don’t:
$ rush -c 'echo hi'; echo "$?"
You are not permitted to execute this command.
Contact the systems administrator for further assistance.
1
$ rush -c 'echo bye'; echo "$?"
You are not permitted to execute this command.
Contact the systems administrator for further assistance.
1

I noticed that man rush.rc says “[t]he file /etc/rush.rc contains a set of rules that[…]” I tried putting an identical config file in /etc/rush.rc, but I got the same results.

Here’s what I ended up doing:

environment.etc."rush.rc".text = "whatever";
environment.systemPackages = let
  customRushPkg = pkgs.rush.overrideAttrs (previousAttrs: {
  configureFlags = [ "--sysconfdir=/etc" ];
    # Prevent “make install” from trying to copy something to /etc/rush.rc:
    installFlags = [ "sysconfdir=$(out)" ];
  });
in [
  customRushPkg
];

I still feel like I’m missing something, though. GNU Rush has been in nixpkgs since 2010. I would think that there would be a better way to configure it at this point.

1 Like

Consider upstreaming that change to the package, and/or writing a module for it. I can see this being a packaging bug that simply nobody has cared to fix for the last 12 years.

1 Like

OK, done.

2 Likes