How to get started as NixOS User

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.

1 Like

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
              ]));
      });
  };
}

1 Like

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:

2 Likes

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.

1 Like