{"id":20548378,"url":"https://github.com/jeslie0/mkspagoderivation","last_synced_at":"2025-10-15T03:19:43.424Z","repository":{"id":200235114,"uuid":"705082742","full_name":"jeslie0/mkSpagoDerivation","owner":"jeslie0","description":"Reproducible PureScript projects with Nix","archived":false,"fork":false,"pushed_at":"2025-10-05T02:05:06.000Z","size":174,"stargazers_count":26,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-05T04:13:58.268Z","etag":null,"topics":["flakes","nix","purescript","spago"],"latest_commit_sha":null,"homepage":"https://github.com/jeslie0/mkSpagoDerivation","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/jeslie0.png","metadata":{"files":{"readme":"README.org","changelog":"CHANGELOG.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-10-15T00:48:55.000Z","updated_at":"2025-10-05T02:05:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"2efcc84b-08db-4b08-a023-8be3261ddffb","html_url":"https://github.com/jeslie0/mkSpagoDerivation","commit_stats":null,"previous_names":["jeslie0/mkspagoderivation"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/jeslie0/mkSpagoDerivation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeslie0%2FmkSpagoDerivation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeslie0%2FmkSpagoDerivation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeslie0%2FmkSpagoDerivation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeslie0%2FmkSpagoDerivation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jeslie0","download_url":"https://codeload.github.com/jeslie0/mkSpagoDerivation/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeslie0%2FmkSpagoDerivation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279042499,"owners_count":26091262,"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","status":"online","status_checked_at":"2025-10-15T02:00:07.814Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["flakes","nix","purescript","spago"],"created_at":"2024-11-16T02:13:13.482Z","updated_at":"2025-10-15T03:19:43.419Z","avatar_url":"https://github.com/jeslie0.png","language":"Nix","funding_links":[],"categories":[],"sub_categories":[],"readme":"#+title: mkSpagoDerivation\n#+author: James Leslie\n[[https://img.shields.io/badge/built%20for-PureScript-1d222d.svg]][[https://img.shields.io/github/license/jeslie0/mkelmderivation.svg]][[https://img.shields.io/github/actions/workflow/status/jeslie0/mkSpagoDerivation/run_tests.yaml.svg]][[https://img.shields.io/github/v/release/jeslie0/mkSpagoDerivation.svg]]\n\nThis flake provides an unopinionated approach to packaging [[https://github.com/purescript/purescript][PureScript]] projects with the [[https://github.com/NixOS/nixpkgs][Nix]] package manager. Utilising [[https://github.com/purescript/registry][PureScript's registry]] and the new [[https://github.com/purescript/spago][spago@next]], this repository facilitates the creation of reproducible builds for PureScript projects with minimal complexity. This works by treating a PureScript project's =spago.lock= as a single source of truth for dependencies.\n\n* Table of contents                                                     :toc:\n- [[#examples][Examples]]\n- [[#out-of-date-registry][Out of date registry]]\n- [[#limitations][Limitations]]\n- [[#notes][Notes]]\n  - [[#hooks][Hooks]]\n- [[#related][Related]]\n- [[#license][License]]\n\n* Examples\nThe most important function that this flake provides is the ~mkSpagoDerivation~ function, exposed as both an output and via an overlay. This provides a wrapper around ~stdenv.mkDerivation~ which puts all of your project's dependencies in the right place, making it easy for you to build your projects in a reproducible way.\n\nImportantly, the =spago.lock= file is required for ~mkSpagoDerivation~ to determine your project's dependencies. Optionally, if you provide your project's =spago.yaml= file, then your project's name will be extracted and used. You can provide a =name= or =pname= argument instead.\n\nHere is a simple =flake.nix= that builds a PureScript project.\n#+begin_src nix\n{\n  inputs = {\n    nixpkgs.url = \"github:nixos/nixpkgs/nixpkgs-unstable\";\n    flake-utils.url = \"github:numtide/flake-utils\";\n    mkSpagoDerivation.url = \"github:jeslie0/mkSpagoDerivation\";\n    ps-overlay.url = \"github:thomashoneyman/purescript-overlay\";\n  };\n\n  outputs = { self, nixpkgs, flake-utils, mkSpagoDerivation, ps-overlay }:\n    flake-utils.lib.eachDefaultSystem (\n      system:\n      let\n        pkgs = import nixpkgs {\n          inherit system;\n          overlays = [ mkSpagoDerivation.overlays.default\n                       ps-overlay.overlays.default ];\n        };\n      in\n        {\n          packages.default =\n            pkgs.mkSpagoDerivation {\n              spagoYaml = ./spago.yaml;\n              spagoLock = ./spago.lock;\n              src = ./.;\n              nativeBuildInputs = [ pkgs.purs-unstable pkgs.spago-unstable pkgs.esbuild ];\n              version = \"0.1.0\";\n              buildPhase = \"spago bundle\";\n              installPhase = \"mkdir $out; cp index.js $out\";\n              buildNodeModulesArgs = {\n                npmRoot = ./.;\n                nodejs = pkgs.nodejs;\n              };\n            };\n        }\n    );\n}\n#+end_src\n\nThe only attribute ~mkSpagoDerivation~ requires is ~src~. The ~spagoYaml~ attribute will default to =${src}/spago.yaml= and likewise, ~spagoLock~ defaults to =${src}/spago.lock=. Everything else is passed into ~mkDerivation~.\n\nSome Spago projects have dependencies from NPM. To automatically take care of fetching NPM packages, the ~buildNodeModulesArgs~\nattribute allows specifing an argument set that is passed to the [[https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage-importNpmLock.buildNodeModules][importNpmLock.buildNodeModules]] function. This will build a =node_modules= directory for use in the derivation. See the [[./tests/nodeModulesTest][nodeModulesTest]] for an example. This attribute is completely optional and can be left out of the =mkSpagoDerivation= arguments if no ~node_modules~ directory is required. \n\nThere are no assumptions about the which version of the compiler is used - you must specify which copy of Spago and PureScript you want to use. Dependencies can be added through ~buildInputs~ or ~nativeBuildInputs~. The following example demonstrates this, by using [[https://github.com/aristanetworks/purescript-backend-optimizer][purescript-backend-optimizer]] and using the unstable PureScript compiler from the PureScript Overlay.\n#+begin_src nix\n{\n  inputs = {\n    nixpkgs.url = \"github:nixos/nixpkgs/nixpkgs-unstable\";\n    flake-utils.url = \"github:numtide/flake-utils\";\n    ps-overlay.url = \"github:thomashoneyman/purescript-overlay\";\n    mkSpagoDerivation.url = \"github:jeslie0/mkSpagoDerivation\";\n  };\n\n  outputs = { self, nixpkgs, flake-utils, ps-overlay, mkSpagoDerivation }:\n    flake-utils.lib.eachDefaultSystem (\n      system:\n      let\n        pkgs = import nixpkgs {\n          inherit system;\n          overlays = [ mkSpagoDerivation.overlays.default\n                       ps-overlay.overlays.default\n                     ];\n        };\n      in\n        {\n          packages.default =\n            pkgs.mkSpagoDerivation {\n              spagoYaml = ./spago.yaml;\n              spagoLock = ./spago.lock;\n              src = ./.;\n              version = \"0.1.0\";\n              nativeBuildInputs = [ pkgs.esbuild pkgs.purs-backend-es pkgs.purs-unstable pkgs.spago-unstable ];\n              buildPhase = \"spago build \u0026\u0026 purs-backend-es bundle-app --no-build --minify --to=main.min.js\";\n              installPhase = \"mkdir $out; cp -r main.min.js $out\";\n            };\n        }\n    );\n}\n#+end_src\n\nSome other useful functions are exposed. One is ~buildDotSpago~, which builds a project's =.spago= directory. It takes an attribute set ~{ spagoLock, src }~, which respectively are the paths to the project's ~spago.lock~ and the root of the project. Another useful function is ~buildSpagoNodeJs~, which builds the =spago-nodejs= directory, typically located in the user's =.cache= directory.\n\n* Out of date registry\nIt is possible for this repository to not have the most up-to-date registry set. If you cant wait for the GitHub action to update this repository, you can override the =registry= and =registry-index= inputs to this flake.\n#+begin_src nix\n{\n  inputs = {\n    nixpkgs.url = \"github:nixos/nixpkgs/nixpkgs-unstable\";\n    flake-utils.url = \"github:numtide/flake-utils\";\n    ps-overlay.url = \"github:thomashoneyman/purescript-overlay\";\n    mkSpagoDerivation = {\n      url = \"github:jeslie0/mkSpagoDerivation\";\n      inputs = {\n        registry.url = \"github:purescript/registry/066f77d3b668fd7916e0af493d8d8ec7a850d774\";\n        registry-index.url = \"github:purescript/registry-index/53cfacb3b1677120eb5e6c11a1f2449d1049c2ce\";\n      };\n    };\n  };\n\n  outputs = { self, nixpkgs, flake-utils, ps-overlay, mkSpagoDerivation }:\n  ...\n#+end_src\n\n* Limitations\nAt the time of writing, this project only supports PureScript projects that make use of the newer spago@next releases. In particular, the project needs a ~spago.yaml~ file and a ~spago.lock~ file is required too.\n\n* Notes\n** Hooks\nThe ~buildPhase~ and ~installPhase~ always run =pre= and =post= hooks, even if the commands provided by the user don't specify them.\n* Related\n- [[https://github.com/purifix/purifix/][purifix]]\n  A different tool to package PureScript programs with Nix.\n- [[https://github.com/justinwoo/spago2nix][spago2nix]]\n  Another tool for packaging PureScript programs with Nix.\n- [[https://github.com/justinwoo/easy-purescript-nix][easy-purescript-nix]]\n  A repository and Nix flake that provides lots of PureScript tools.\n- [[https://github.com/purs-nix/purs-nix][purs-nix]]\n  A tool for Nix based PureScript development.\n- [[https://github.com/jeslie0/mkElmDerivation][mkElmDerivation]]\n  A similar tool (that I created) to package [[https://elm-lang.org/][Elm]] applications with Nix.\n* License\nAll of this repository is under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeslie0%2Fmkspagoderivation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjeslie0%2Fmkspagoderivation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeslie0%2Fmkspagoderivation/lists"}