Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document flake usage #10

Merged
merged 2 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# clojure-nix-locker

Simple and flexible tool to build clojure projects with Nix.

## Usage

The [example/](example) directory has a small clojure program and the nix code required to build it.

### Stable non-flake way

To generate/update the lockfile:
```sh
nix-shell --run clojure-nix-locker
Expand All @@ -15,6 +18,16 @@ To build:
nix-build -A uberjar
```

### With flakes

You can generate a flake example with:

```sh
mkdir play-with-clojure-nix-locker && cd play-with-clojure-nix-locker && nix flake init -t github:bevuta/clojure-nix-locker
```

The [example README](example/README.md) has some next steps.

## Why another tool?

There are two existing projects with a similar goal already, [clj2nix](https://github.com/hlolli/clj2nix) and [clj-nix](https://github.com/jlesquembre/clj-nix).
Expand All @@ -35,6 +48,7 @@ This approach results in a pretty simple implementation and loose coupling to th
As a consequence, things like aliases "just work" without requiring `clojure-nix-locker` to know about them.

Of course, this has its downsides too:

- If the directory layout of these caches changes, this tool breaks.
- Whatever classpath(s) your clojure tools compute at build-time will only work for the duration of that build.

Expand Down
29 changes: 29 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generating the lockfile

To generate the lockfile of all the deps:

```sh
nix run .#locker
```

Run this after modifying `deps.edn`.

# Building uberjar using the lockfile classpath

```sh
nix build .#uberjar
```

Run uberjar:

```sh
./result/bin/simple
```

# Starting a devshell with the locked classpath

```
nix develop
```

It will print out the current locked classpath.
76 changes: 34 additions & 42 deletions example/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 22 additions & 1 deletion example/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

inputs = {
nixpkgs.url = "nixpkgs";
clojure-nix-locker.url = "github:bevuta/clojure-nix-locker";
flake-utils.url = "github:numtide/flake-utils";

clojure-nix-locker.url = "github:bevuta/clojure-nix-locker";
clojure-nix-locker.inputs.nixpkgs.follows = "nixpkgs";
clojure-nix-locker.inputs.flake-utils.follows = "flake-utils";
};

outputs = { self, nixpkgs, flake-utils, clojure-nix-locker, ... }:
Expand Down Expand Up @@ -51,6 +54,21 @@
drv = my-clojure-nix-locker.locker;
};
devShells.default = pkgs.mkShell {
shellHook = ''
# Trace all Bash executions
set -o xtrace

source ${my-clojure-nix-locker.shellEnv}

echo "Current locked classpath:"
${pkgs.clojure}/bin/clojure -Spath

set +o xtrace

echo
echo "Note that \$HOME is overridden and read-only: $HOME"
echo
'';
inputsFrom = [
packages.uberjar
];
Expand All @@ -60,6 +78,9 @@
clojure
clj-kondo
coreutils
# This provides the standalone `clojure-nix-locker` script in the shell
# You can use it, or `nix run .#locker`
# Both does the same
my-clojure-nix-locker.locker
];
};
Expand Down