{"id":13682139,"url":"https://github.com/justinwoo/spago2nix","last_synced_at":"2025-08-20T12:11:16.909Z","repository":{"id":36577597,"uuid":"192080777","full_name":"justinwoo/spago2nix","owner":"justinwoo","description":"Generate a derivation of (old) Spago dependencies, and use them to install them into the directory structure used by Spago.","archived":false,"fork":false,"pushed_at":"2024-06-17T07:39:04.000Z","size":157,"stargazers_count":43,"open_issues_count":15,"forks_count":23,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-31T00:24:15.621Z","etag":null,"topics":["nix","purescript","spago"],"latest_commit_sha":null,"homepage":"","language":"Nix","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/justinwoo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-06-15T13:17:52.000Z","updated_at":"2024-10-28T18:03:13.000Z","dependencies_parsed_at":"2024-08-02T13:21:47.487Z","dependency_job_id":"d0f8ae4f-f442-4266-9ad7-09a6035e9943","html_url":"https://github.com/justinwoo/spago2nix","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justinwoo%2Fspago2nix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justinwoo%2Fspago2nix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justinwoo%2Fspago2nix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justinwoo%2Fspago2nix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/justinwoo","download_url":"https://codeload.github.com/justinwoo/spago2nix/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252588559,"owners_count":21772697,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nix","purescript","spago"],"created_at":"2024-08-02T13:01:41.216Z","updated_at":"2025-05-05T22:38:44.136Z","avatar_url":"https://github.com/justinwoo.png","language":"Nix","funding_links":[],"categories":["Nix"],"sub_categories":[],"readme":"# Spago2Nix\n\n![](./logo-256.png)\n\nGenerate a derivation of (old) Spago dependencies, and use them to install them into the directory structure used by Spago.\n\n## Warning\n\nThis is a project targeting the old versions of Spago and will not be updated to work with the newer versions. This repository remains here for you to read through and fork from, if needed.\n\n## Installation\n\nFor now, simply clone this repo and run `npm link`. Requires a Node runtime and nix-prefetch-git.\n\nRemember to set npm prefix to something like `~/.npm`.\n\n## Usage\n\nFirst, generate the spago-packages.nix:\n\n```bash\n$ spago2nix generate\ngetting packages..\ngot 65 packages from Spago list-packages.\n# ...\nwrote spago-packages.nix\n```\n\nThen install these, optionally with more jobs provided to Nix:\n\n```bash\n$ spago2nix install -j 100\n/nix/store/...-install-spago-style\ninstalling dependencies...\n# ...\ndone.\nWrote install script to .spago2nix/install\n```\n\nThen build the project:\n\n```bash\n$ spago2nix build\n/nix/store/...-build-spago-style\nbuilding project...\ndone.\nWrote build script to .spago2nix/build\n```\n\nWhen using in your own Nix derivation, the best practice is calling generated scripts from `spago-packages.nix`:\n\n```nix\n{ pkgs, stdenv }:\n\nlet\n  spagoPkgs = import ./spago-packages.nix { inherit pkgs; };\nin\npkgs.stdenv.mkDerivation rec {\n  # \u003c ... \u003e\n  buildPhase =\n  ''\n    ${spagoPkgs.installSpagoStyle} # == spago2nix install\n    ${spagoPkgs.buildSpagoStyle}   # == spago2nix build\n    ${spagoPkgs.buildFromNixStore} # == spago2nix build\n  '';\n  # \u003c ... \u003e\n}\n```\n\n\n## Workflow\n\nThe [workflow of `spago2nix`](https://github.com/purescript/spago/issues/547) is:\n\n1. Ensure you have Spago installed, a `packages.dhall` file, and a `spago.dhall`\n   file.\n\n2. Run `spago2nix generate` to generate a new `spago-packages.nix` file which\n   describes how to build the dependencies.\n\n   You can add `spago2nix` to the `nativeBuildInputs` of a `mkShell` just by\n   importing the `spago2nix` repository `default.nix`.\n\n   ```nix\n   spago2nix = import (builtins.fetchGit {\n     url = \"git@github.com:justinwoo/spago2nix.git\";\n     rev = \"...\";\n   }) { inherit pkgs; };\n\n\n   pkgs.mkShell {\n     nativeBuildInputs = with pkgs; [\n       spago2nix\n     ];\n   ```\n\n   Then you'll be able to run `spago2nix generate` in an impure shell. It will\n   call out to the network to look up hashes for the versions of packages\n   in your `spago.dhall`.\n\n   The output of `spago2nix generate` will be a `spago-packages.nix` file,\n   which contains pure derivations for each package dependency, and which you\n   should check into source control.\n\n3. In the Nix expression which describes how to build your project, import\n   the generated `spago-packages.nix` file to get the package dependencies.\n\n   ```nix\n   spagoPkgs = import ./spago-packages.nix { inherit pkgs; };\n   ```\n\n4. When describing the build steps, either use `spago2nix build` or\n   `spago build --no-install` or call to the compiler directly\n   with `purs compile \"src/**/*.purs\" ${spagoPackages.compilePaths}`.\n\n   Or do something like this:\n\n   ```nix\n   pkgs.stdenv.mkDerivation {\n     name = \"myderiv\";\n     buildInputs = [\n       spagoPkgs.installSpagoStyle\n       spagoPkgs.buildSpagoStyle\n       ];\n     nativeBuildInputs = with pkgs; [\n       easy-ps.purs-0_13_8\n       easy-ps.spago\n       ];\n     src = ./.;\n     unpackPhase = ''\n       cp $src/spago.dhall .\n       cp $src/packages.dhall .\n       cp -r $src/src .\n       install-spago-style\n       '';\n     buildPhase = ''\n       build-spago-style \"./src/**/*.purs\"\n       '';\n     installPhase = ''\n       mkdir $out\n       mv output $out/\n       '';\n     }\n   ```\n\nThis has a key drawback: steps 2 and 3 really ought to be a single step.\nBecause the `spago.dhall` file doesn't contain any cryptographic verification\nof the dependencies, we can't do this as a pure one-step derivation.\n\n## 1-Step Workflow with `flake.nix`\n\nThe 1-Step Workflow requires an impure Nix build.\n\nThere is a `flake.nix` which provides a package for building a PureScript\nproject in a Nix derivation. The package is a function\nnamed `spago2nix_nativeBuildInputs` which has a “type signature” like this:\n\n```nix\n{\n  spago-dhall ? \"spago.dhall\", # the main spago.dhall file name, i.e. \"spago.dhall\"\n  srcs-dhall # array of .dhall files, i.e. [./spago.dhall ./packages.dhall]\n}: []\n```\n\nThe `spago2nix_nativeBuildInputs` function takes as inputs the PureScript\nproject’s Spago `.dhall` files, and produces as output an array of\nderivations to include in a `nativeBuildInputs`. For a derivation which\nhas those `nativeBuildInputs`, the PureScript project can be built\nin the `buildPhase` by executing `build-spago-style`.\n\nExample:\n\n```nix\nstdenv.mkDerivation {\n  name = \"my-purescript-project\";\n  nativeBuildInputs = [\n    easy-purescript-nix.purs\n  ] ++ (\n    spago2nix_nativeBuildInputs {\n      srcs-dhall = [./spago.dhall ./packages.dhall];\n    }\n  );\n  src = nixpkgs.nix-gitignore.gitignoreSource [ \".git\" ] ./.;\n  unpackPhase = ''\n    cp -r $src/src .\n    cp -r $src/test .\n    install-spago-style\n    '';\n  buildPhase = ''\n    build-spago-style \"./src/**/*.purs\" \"./test/**/*.purs\"\n    '';\n  installPhase = ''\n    mkdir -p $out\n    mv output $out/\n    '';\n}\n```\n\nFor another example, see [`test-flake/flake.nix`](test-flake/flake.nix)\nin this repository which shows how to build the __uint__ package.\n\nThe `flake.nix` also has an `app` for running `spago2nix` off of Github,\nfor example:\n\n```sh\nnix run github:justinwoo/spago2nix#spago2nix\n```\n\n## Further Reading\n\nHere is a blog post I did about this project: \u003chttps://github.com/justinwoo/my-blog-posts/blob/master/posts/2019-06-22-spago2nix-why-and-how.md\u003e\n\n## Troubleshooting\n\n#### I get `MissingRevOrRepoResult` on a package with branch name as a version\n\nNix gives out the specific constant SHA256 hash for broken Git fetches, so the error is thrown.\nOne of the causes for a broken fetch is wrong checkout revision. Nix supports fetches by commit hash and tags out of the box, but fails at plain branch names.\n\nYou can use more verbose reference `refs/heads/branch-name` at `packages.dhall` before generating a `.nix` file.\nHowever, __the branch name usage is discouraged in Spago__ ([refer to Note here](https://github.com/spacchetti/spago#override-a-package-in-the-package-set-with-a-remote-one)), it's better using a particular commit hash.\n\n### I don't know how to compile my project in a derivation\n\nSpago2nix will install and build your project dependencies, but you may still want to use `spago` to bundle your project. You should not use Spago installation or build commands in a derivation. Use Spago's `--no-install` and `--no-build` flags when bundling your project as part of the build phase of a derivation:\n\n```nix\npkgs.stdenv.mkDerivation {\n  # \u003c ... \u003e\n  buildPhase = ''\n    ${spago}/bin/spago bundle-app --no-install --no-build --to $out/index.js\n  '';\n  # \u003c ... \u003e\n};\n```\n\nIf you attempt to use Spago commands to install or build in your project, you'll see the following error:\n\n```\nspago: security: createProcess: runInteractiveProcess: exec: does not exist (No such file or directory)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustinwoo%2Fspago2nix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjustinwoo%2Fspago2nix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustinwoo%2Fspago2nix/lists"}