Chicken-install fails for anything

I don’t know much about scheme or chicken, but on other operating systems I’ve been able to use chicken-install 7off to download and compile 7off along with all of its dependencies. This is my goal, but it doesn’t seem to work for me on NixOS. I haven’t been able to find any examples of others using NixOS to do anything with chicken or scheme, either.

Here’s what I get when I try:

[nix-shell:~]$ chicken-install 7off
building anaphora
installing anaphora
install: cannot create regular file '/nix/store/vmvki72pmpgm975xdkr369qispiq85qj-chicken-5.3.0/lib/chicken/11/anaphora.o': Read-only file system

Error: shell command terminated with nonzero exit code
256
"sh /home/stephen/.cache/chicken-install/anaphora/anaphora.install.sh"

Any help would be appreciated.

It’s trying to install files to its installation directory. This means it was either deliberately not packaged in a way that permits chicken-install, it doesn’t support installing to a different prefix, or someone forgot to add a setting to change the prefix.

You’ll have to dig into this tool, figure out how you’re supposed to change the module directory, and maybe upstream a fix to nixpkgs.

Oh, there’s a reply via email option? This is cool, let’s see how this
goes…

It’s trying to install files to its installation directory. This means it was

I assumed this was the case.

either deliberately not packaged in a way that permits chicken-install, it
doesn’t support installing to a different prefix, or someone forgot to add a
setting to change the prefix.

I don’t know enough about chicken to even know what to set.

You’ll have to dig into this tool, figure out how you’re supposed to change the
module directory, and maybe upstream a fix to nixpkgs.

After re-reading the chicken manuals a few times and then inspecting the
environment variables that were set, and then a hell of a lot of trial
and error, I came up with the following to be able to fetch and build,
but I don’t know enough about NixOS to even know how to reconcile what
I’ve managed to scrape together with whatever configuration NixOS is
using.

Despite having separate variables, it seems chicken needs to have the
same value set for the install-repository and the repository paths.
Otherwise the build fails when built dependencies are not found in the
repository path.

Anywhere, here’s a pretty terrible script I used to build:

set -e

PKG=${@}

CRP=${CHICKEN_REPOSITORY_PATH}

BASE="$(pwd)"

cat > env-for-binaries.sh << EOF
export CHICKEN_INSTALL_PREFIX="${BASE}/install"
export CHICKEN_EGG_CACHE="${BASE}/cache"
export CHICKEN_REPOSITORY_PATH="${BASE}/repository"
export CHICKEN_INSTALL_REPOSITORY="${BASE}/repository"
export CHICKEN_INCLUDE_PATH="${BASE}/include"
EOF

. env-for-binaries.sh

TARGETS=("${CHICKEN_INSTALL_PREFIX}" "${CHICKEN_EGG_CACHE}" "${CHICKEN_REPOSITORY_PATH}" "${CHICKEN_INCLUDE_PATH}")

for TARGET in "${TARGETS[@]}" ; do
    mkdir -p "${TARGET}"
done

cp -rn "${CRP}"/* "${CHICKEN_REPOSITORY_PATH}" 2>/dev/null || true

chicken-install "${PKG[@]}"

I named it chicken-scratch.sh and invoked it thusly:

bash chicken-scratch.sh 7off
. env-for-binaries.sh
./install/bin/7off --help

Resulting binaries are dropped relative to the current directory. For
now, I’ll put them in a path that works for the stuff I need, but this
doesn’t really help anyone else. Oh, and I have to remember to source
the env-for-binaries.sh that my script drops so deps can be found.

I think it’d be relatively easy to set those variables with makeWrapper, and dedicate /usr/share/chicken to those paths. Something like:

pkgs.chicken.overrideAttrs (old: {
  nativeBuildInputs = old ++ [ pkgs.makeWrapper ];
  postBuild = ''
    wrapProgram $out/bin/chicken-install \
      --set-default CHICKEN_INSTALL_PREFIX : "/var/lib/chicken/install" \
      --set-default CHICKEN_EGG_CACHE : "/var/cache/chicken" \
      --set-default CHICKEN_REPOSITORY_PATH : "/var/lib/chicken/repository" \
      --set-default CHICKEN_INCLUDE_PATH : "/var/lib/chicken/include"
  '';
})

Doing that upstream would be no more difficult. But I have no idea how this chicken stuff works, so I’ll leave it to someone actually using the language.

I think it’d be relatively easy to set those variables with makeWrapper, and
dedicate /usr/share/chicken to those paths. Something like:

pkgs.chicken.overrideAttrs (old: {
nativeBuildInputs = old ++ [ pkgs.makeWrapper ];
postBuild = ‘’
wrapProgram $out/bin/chicken-install
–set-default CHICKEN_INSTALL_PREFIX : “/var/lib/chicken/install”
–set-default CHICKEN_EGG_CACHE : “/var/cache/chicken”
–set-default CHICKEN_REPOSITORY_PATH : “/var/lib/chicken/repository”
–set-default CHICKEN_INCLUDE_PATH : “/var/lib/chicken/include”
‘’;
})

Can you point me to some reading material? I suspect I can somehow use
the above to make some sort of build, but it’s beyond me at the moment.
Could I put something like this in my configuration.nix or would this
only be applicable to the input package files… sorry, I’ve only been
using NixOS for a few months and it’s a lot of new ground.

Doing that upstream would be no more difficult. But I have no idea how this
chicken stuff works, so I’ll leave it to someone actually using the language.

Yeah, 7off is literally the only program I have ever used that’s written
in scheme, so it’s all new to me, too. It’s a bit obscure, but it’s
also the best one I’ve used for what it does, so it was important enough
for me to find a workaround.

This kind of seems like a problem with the current chicken package if
it can’t be used to get other packages nor can it be used (without
modifications?) to build stuff that has dependencies.

Maybe I’ll reach out to the package maintainers.

Thank you for your replies, it encouraged me to revisit the manuals and
at least come up with the workaround I have now.

https://nix.dev/ is where documentation for this kind of thing is slowly being created. The tutorial on overrideAttrs hasn’t been written yet, though, and lower-level NixOS concepts aren’t really covered at all yet, so it won’t really help make sense of what I wrote (the basic language tutorial and such may help get there though). I should earmark this as a thing to write a guide for.

The nix pills are still one of the better resources out there IMO for understanding what’s going on in-depth, but they are quite hard to grok if you’re just starting out…

Yep, you could for example install the overridden package like so:

# configuration.nix
{pkgs, ...}: {
  environment.systemPackages = let
    chicken = pkgs.chicken.overrideAttrs (old: {
      nativeBuildInputs = old ++ [ pkgs.makeWrapper ];
      postBuild = ‘’
      wrapProgram $out/bin/chicken-install
        –set-default CHICKEN_INSTALL_PREFIX : “/var/lib/chicken/install”
        –set-default CHICKEN_EGG_CACHE : “/var/cache/chicken”
        –set-default CHICKEN_REPOSITORY_PATH : “/var/lib/chicken/repository”
        –set-default CHICKEN_INCLUDE_PATH : “/var/lib/chicken/include”
      ‘’;
    });
  in [
    chicken
  ];
}

wrapProgram basically does what you did with your hand-written script. It replaces a binary in a package with a script that sets some environment variables before executing the real binary. This is often necessary in nix land because of the fhs-noncompliance causing issues exactly like the one we’re looking at here.

The code could be cleaned up with some imports and such of course.

You could also use an overlay to change what pkgs.chicken refers to. That’s probably equivalent to the above in practice, but useful if e.g. you want to patch your libc or something else lower-level.

Yep, that’s my point. Reaching out to the maintainer or at least opening an issue is definitely a good start, but nixpkgs maintainers are usually stretched for time, so don’t expect this to be resolved anytime soon.