Skip to content

Commit c600e12

Browse files
committed
Add shellHook into devShells.default and document how to init and use the flake
- This shows how to control the classpath locations that `clojure` uses - Make explicit that $HOME is read-only
1 parent 0a8b56c commit c600e12

File tree

3 files changed

+53
-6
lines changed

3 files changed

+53
-6
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
# clojure-nix-locker
2+
23
Simple and flexible tool to build clojure projects with Nix.
34

45
## Usage
56

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

8-
To generate/update the lockfile:
9-
```sh
10-
nix-shell --run clojure-nix-locker
11-
```
9+
You can generate it with:
1210

13-
To build:
1411
```sh
15-
nix-build -A uberjar
12+
mkdir play-with-clojure-nix-locker && cd play-with-clojure-nix-locker && nix flake init -t github:bevuta/clojure-nix-locker
1613
```
1714

15+
The [example README](example/README.md) has some next steps.
16+
1817
## Why another tool?
1918

2019
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).
@@ -35,6 +34,7 @@ This approach results in a pretty simple implementation and loose coupling to th
3534
As a consequence, things like aliases "just work" without requiring `clojure-nix-locker` to know about them.
3635

3736
Of course, this has its downsides too:
37+
3838
- If the directory layout of these caches changes, this tool breaks.
3939
- Whatever classpath(s) your clojure tools compute at build-time will only work for the duration of that build.
4040

example/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Generating the lockfile
2+
3+
To generate the lockfile of all the deps:
4+
5+
```sh
6+
nix run .#locker
7+
```
8+
9+
Run this after modifying `deps.edn`.
10+
11+
# Building uberjar using the lockfile classpath
12+
13+
```sh
14+
nix build .#uberjar
15+
```
16+
17+
Run uberjar:
18+
19+
```sh
20+
./result/bin/simple
21+
```
22+
23+
# Starting a devshell with the locked classpath
24+
25+
```
26+
nix develop
27+
```
28+
29+
It will print out the current locked classpath.

example/flake.nix

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@
5454
drv = my-clojure-nix-locker.locker;
5555
};
5656
devShells.default = pkgs.mkShell {
57+
shellHook = ''
58+
# Trace all Bash executions
59+
set -o xtrace
60+
61+
source ${my-clojure-nix-locker.shellEnv}
62+
63+
echo "Current locked classpath:"
64+
${pkgs.clojure}/bin/clojure -Spath
65+
66+
set +o xtrace
67+
68+
echo
69+
echo "Note that \$HOME is overridden and read-only: $HOME"
70+
echo
71+
'';
5772
inputsFrom = [
5873
packages.uberjar
5974
];
@@ -63,6 +78,9 @@
6378
clojure
6479
clj-kondo
6580
coreutils
81+
# This provides the standalone `clojure-nix-locker` script in the shell
82+
# You can use it, or `nix run .#locker`
83+
# Both does the same
6684
my-clojure-nix-locker.locker
6785
];
6886
};

0 commit comments

Comments
 (0)