Using an installation script in a package

I am currently working on packaging a theme that comes with an installation script, which unfortunately does not lend itself at all to a declarative installation. To solve this, I made a modified version of the script that just replacement all the interactive parts of the script with variables for users to override. However, I’m not sure how to include the script in the package.

I originally tried setting builder = ./, but then realized that this overrides other phases I want, like the unpack phase. I think the script is too long and complex to just paste into the installPhase, so if anybody can explain how to include it in the built, I would appreciate it.

If I understand correctly, you have a script that need to be executed after the packaged is installed ?
Like, for example to setup things in the user folders (or in /etc).

If so, you could put your script in the $out/bin/ folder or somewhere in $out/usr/share.

Would that works for you ?

The script needs to execute during the install phase, it’s in place of the packages original script. My problem is that I’m unsure how to include the script in the buildroot.

I’m currently solving this by using a patch that adds the script to the repo, but I’m not sure if this is a good way to do it. Sorry if I explained my question poorly.

AFAIK, Nix/Nixpkgs has no easy way to do automated postinstall script since that creates unaccounted state.

To include the script in the buildroot, you can use srcs instead of src (see this link) but that will not execute the script at installation.

If you want to do that there is a few options:

  • Wrapping your theme and the software using your theme in a single installable package (like for example obs).
    The advantage is that nothing has to be outside of nix
  • Using a nixos/home-manager module that can start systemd scripts.
    The advantage is that you have the full power of the script but the user has to opt-in to enable your theme.

There may be other possibilities but I do not see them right now.

1 Like

That first link should help, I just need to put the script in the build root to run it during install, not after. Thank you!