Tool to derive a Nix expression from a psc-package.json configuration.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib/PscPackage2Nix update derivation to put get deps in site packages Dec 21, 2018
nix put nix functions in a bucket Dec 21, 2018
test-bower-style put nix functions in a bucket Dec 21, 2018
test update test with callPackage Dec 31, 2018
.gitattributes
.travis.yml
LICENSE
README.md put nix functions in a bucket Dec 21, 2018
default.nix Fixed reference to missing attribute pkgs.perl.version Jan 8, 2019
psc-package2nix update derivation to put get deps in site packages Dec 21, 2018
utils.nix put nix functions in a bucket Dec 21, 2018

README.md

Psc-Package2Nix

Build Status

Tool to derive a Nix expression from a psc-package.json configuration.

Prefetches Git SHA of the total dependencies you depend on.

Read the blog post about this project here: https://qiita.com/kimagure/items/85a64437f9af78398638

There's also a post about this whole setup (going from Bower): https://qiita.com/kimagure/items/aec640d0047d08d2ce90

I (Justin) gave a talk about Psc-Package2Nix: https://speakerdeck.com/justinwoo/nix-ify-your-psc-package-dependencies

Usage example

default.nix

In the test setup, we have the packages.nix that is generated by psc-package2nix checked in, so you can see what kind of file we are generating here.

Then when you look at default.nix, you will find that we have a normal derivation, where...

First, we use easy-purescript-nix to easily install the PureScript compiler and Psc-Package. This expression takes an argument should you wish to override pkgs, but this will default to using <nixpkgs>.

# easy-purs.nix

# this line means that this expression can take a "pkgs" argument, but will default to `import <nixpkgs> {}`
# You can check the nixpkgs content from the repl yourself with `nixpkgs = ./import <nixpkgs> {}`
# Remember that <nixpkgs> corresponds to channels you have declared in ~/.nix-channels, e.g.
# https://nixos.org/channels/nixpkgs-unstable nixpkgs
{ pkgs ? import <nixpkgs> {} }:

# import the nix expression provided by a source, in this case being a derivation with its `src` contents being the repo contents
import (pkgs.fetchFromGitHub {
  owner = "justinwoo";
  repo = "easy-purescript-nix";

  # some commit SHA or tag name
  rev = "5b71ea53e25a1f99229ee0b657b37c46f6fc0a45";

  # some SHA of the contents, obtained by nix-prefetch-git/prefetch-github/etc
  sha256 = "1qza198b93abr4klzvz55ccai99ji893j4kgv0dali827ryk7ph2";
})

Then, we bring in psc-package2nix from this repository remotely.

{ pkgs ? import <nixpkgs> {} }:

let
  # here we use the derivation defined above to import easy-ps:
  easy-ps = import ./easy-ps.nix { inherit pkgs; };

  psc-package2nix = import ./psc-package2nix.nix { inherit pkgs; };

in pkgs.stdenv.mkDerivation {
  name = "test";
  buildInputs = [
    easy-ps.inputs.purs
    easy-ps.inputs.psc-package-simple
    psc-package2nix
  ];
}

With this, we can start up a nix-shell that runs psc-package2nix to generate packages.nix of our Psc-Package dependencies.

install-deps.nix

Then we have a separate install-deps.nix file which uses the generated packages.nix file. We bring in the packages that have been generated here and create a list using the attribute values of the set (reminder: records are called "attribute sets" in Nixlang).

The list we prepare wil be a series of copy commands for the Psc-Package dependencies to be copied from the Nix Store, which will give us local mutable copies in .psc-package/. We can accomplish this with an executable install-deps.nix file:

#! /usr/bin/env nix-shell
#! nix-shell ./install-deps.nix --run 'exit'
# ^ this second line determines how install-deps.nix is called by nix-shell

{ pkgs ? import <nixpkgs> {} }:

let
  # import our packages
  packages = import ./packages.nix { inherit pkgs; };

  # you will want to fetch this likely by direct url or copy this into your project
  # _pp2n-utils = import pkgs.fetchurl {
  #   url = "https://raw.githubusercontent.com/justinwoo/psc-package2nix/SOMEREV/utils.nix";
  #   sha = "SOMESHA";
  # };

  # import pp2n-utils from the psc-package2nix derivation in easy-ps
  # easy-ps = import ./easy-ps.nix { inherit pkgs; };
  # pp2n-utils = import (easy-ps.inputs.psc-package2nix.src + "/utils.nix");

  # get the utilities defined in utils.nix in this repo for getting a default shell hook to copy dependencies
  pp2n-utils = import ../utils.nix;

# use the mkInstallPackages function to generate a shell derivation to install derivation
in pp2n-utils.mkInstallPackages pkgs packages

Of course, you might use the full power of the Nix language to tweak this to fit your uses, but this should work for many uses.

More Information

If you need more information on how Psc-Package works, you might see the Spacchetti guide page here: https://spacchetti.readthedocs.io/en/latest/intro.html

Complaints

PRs welcome