How to get started as NixOS User (original) (raw)
January 25, 2025, 1:44pm #1
I am currently trying to get into purescript development as NixOS user. Spago does not work. I get the same error as described here, but the proposed solution does not work. I was able to follow the getting started guide with purs-nix but I don’t know how to use it with the purescript book. Purs-nix is also missing arm support.
Is there a different tool to follow the book? Next I wanted to try to use distrobox but I hope there would be a simpler solution like a way of using purs-nix with the book as well.
In my experience, purs-nix isn’t working properly anymore.
Here’s how I provision Purescript in a flake file:
{
description = "cheeblr";
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
purescript-overlay = {
url = "github:thomashoneyman/purescript-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-compat.url = "github:edolstra/flake-compat";
flake-compat.flake = false;
};
outputs = { self, nixpkgs, purescript-overlay, ... }: let
name = "cheeblr";
supportedSystems = [
"aarch64-darwin"
"x86_64-darwin"
"x86_64-linux"
];
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system);
in {
devShell = forAllSystems (system: let
overlays = [
purescript-overlay.overlays.default
];
pkgs = import nixpkgs { inherit system overlays; };
vite = pkgs.writeShellApplication {
name = "vite";
runtimeInputs = with pkgs; [ nodejs-slim ];
text = "npx vite --open";
};
concurrent = pkgs.writeShellApplication {
name = "concurrent";
runtimeInputs = with pkgs; [ concurrently ];
text = ''
concurrently\
--color "auto"\
--prefix "[{command}]"\
--handle-input\
--restart-tries 10\
"$@"
'';
};
spago-watch = pkgs.writeShellApplication {
name = "spago-watch";
runtimeInputs = with pkgs; [ entr spago-unstable ];
text = ''find {src,test} | entr -s "spago $*" '';
};
dev = pkgs.writeShellApplication {
name = "dev";
runtimeInputs = with pkgs; [
nodejs-slim
spago-watch
vite
concurrent
];
text = ''
# npm install &&
concurrent "spago-watch build" vite
'';
};
in
pkgs.mkShell {
inherit name;
shellHook = ''
echo "Available commands: dev"
'';
buildInputs = [
pkgs.esbuild
pkgs.nodejs_20
pkgs.nixpkgs-fmt
pkgs.purs
pkgs.purs-tidy
pkgs.purs-backend-es
pkgs.purescript-language-server
pkgs.spago-unstable
vite
dev
]
++ (pkgs.lib.optionals (system == "aarch64-darwin")
(with pkgs.darwin.apple_sdk.frameworks; [
Cocoa
CoreServices
]));
});
};
}
January 25, 2025, 2:57pm #3
So you use nix together with vite?
Is there a way to have something equivalent to spago test
?
I also use a flake and github:thomashoneyman/purescript-overlay
.
You can find a more minimal example of using it along with the lsp, the backend-optimizer and esbuild here:
Sure. You’d just follow my example and expand upon it similarly to how I defined spago-watch shell script in my flake then made sure to add it in the packages part. Anything you can do in the shell can be done there.
Easy as pie.
Where I am having trouble is actually a Haskell.nix backend with external dependencies but that’s a whole other nix world.
March 14, 2025, 10:18am #7
purescript-overlay is the current best Nix infrastructure for PureScript, but it can’t build PureScript packages.
For building PureScript packages I’ve recently started using mkSpagoDerivation by @jeslie0 in purescript-protobuf and I’ve found it quite nice.
Another good option is combining purescript-overlay with devenv.
This is how I configure my purescript project config -
devenv.yaml:
inputs:
nixpkgs:
url: github:cachix/devenv-nixpkgs/rolling
purescript-overlay:
url: github:thomashoneyman/purescript-overlay
devenv.nix
{ pkgs, lib, config, inputs, ... }:
{
overlays = [
# Pull in PureScript tooling
inputs.purescript-overlay.overlays.default
];
packages =
[ pkgs.spago-unstable
pkgs.purs
pkgs.purs-tidy
pkgs.purs-backend-es
pkgs.purescript-language-server
pkgs.esbuild
];
languages.purescript.enable = true;
}