racket2nix icon indicating copy to clipboard operation
racket2nix copied to clipboard

Problem: software feels very uncomfortable to use

Open sjmackenzie opened this issue 6 years ago • 4 comments

Is there a way I can do something like this:

{ pkgs ? import <nixpkgs> {}}:

# pull in racket2nix src

pkgs.stdenv.mkDerivation {
  name = "fractalide-paper";
  src = ./.;
  buildInputs = [ racket73Packages.base racket73Packages.scribble-lib ];

  buildPhase = ''
    scribble --pdf fractalide.scrbl
  '';
  installPhase = ''
    mkdir $out
    mv fractalide.pdf $out
  '';
}

sjmackenzie avatar May 25 '19 18:05 sjmackenzie

At the moment I have something like this:

{ pkgs ? import <nixpkgs> {}
, racket2nix ? pkgs.fetchFromGitHub {
  owner = "fractalide"; repo = "racket2nix";
  rev = "0cafac6fbebed544c6118a53fce3d0972c900769";
  sha256 = "142kh5ispik87fah5wgvnaih3yqg1ajqpb0ipaxbxv7wrdmn0ziw"; }
}:
with pkgs;
let
  inherit (racket2nix) buildRacketPackage;
  latex = texlive.combine { inherit (texlive) scheme-full;};
  pdf = (buildRacketPackage (builtins.path {
    name = "pdf";
    path = ./.;
  })).overrideAttrs (oldAttrs: {
    buildInputs = oldAttrs.buildInputs or [] ++ [ latex ];
    postInstall = oldAttrs.postInstall or "" + ''
      scribble --pdf pdf.scrbl
      mkdir $out
      mv pdf.pdf $out
    '';
  });
in
pdf

and I get this error:

$ nix-build
error: attribute 'buildRacketPackage' missing, at path/to/default.nix:8:4

sjmackenzie avatar May 25 '19 19:05 sjmackenzie

The first thing: Yeah, the big thing missing here is a nice racket.withPackages. That's not too far off in the future, I'm reworking the whole buildPhase (actually making a buildPhase at all rather than building everything in installPhase), and that's going to make this easy to add.

clacke avatar May 25 '19 21:05 clacke

The second thing: It needs to be inherit (import racket2nix {}) buildRacketPackage, but that still won't work, because your derivation won't have the scribble tool in its $PATH.

If you don't rely on any specific packages in your .scrbl you can get away with something like:

{ pkgs ? import <nixpkgs> {}
, racket2nix ? pkgs.fetchFromGitHub {
  owner = "fractalide"; repo = "racket2nix";
  rev = "0cafac6fbebed544c6118a53fce3d0972c900769";
  sha256 = "142kh5ispik87fah5wgvnaih3yqg1ajqpb0ipaxbxv7wrdmn0ziw"; }
}:

with pkgs;

runCommand "pdf.pdf" {
  buildInputs = [
    (import racket2nix { package = "scribble-lib"; })  # shortcut "documented" in test.nix but not in human-friendly docs
    (texlive.combine { inherit (texlive) scheme-full;})
  ];
} ''
  cp ${./pdf.scrbl} pdf.scrbl
  scribble --pdf pdf.scrbl
  mv pdf.pdf $out
''

But if you are documenting an API and you need a bunch of collections installed to interpret the .scrbl, I'm afraid you'll have to take the scribble-lib derivation, overrideRacketDerivation it and augment racketThinBuildInputs with everything you need (but at least using *Thin* takes care of the transitive dependencies!). There's a lot of potential for improvement here, but basically that's all captured by the glorious future racket.withPackages.

clacke avatar May 25 '19 21:05 clacke

#158

clacke avatar May 25 '19 21:05 clacke