Skip to content

Commit 8202b5c

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 8202b5c

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
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

9+
### Stable non-flake way
10+
811
To generate/update the lockfile:
912
```sh
1013
nix-shell --run clojure-nix-locker
@@ -15,6 +18,16 @@ To build:
1518
nix-build -A uberjar
1619
```
1720

21+
### With flakes
22+
23+
You can generate a flake example with:
24+
25+
```sh
26+
mkdir play-with-clojure-nix-locker && cd play-with-clojure-nix-locker && nix flake init -t github:bevuta/clojure-nix-locker
27+
```
28+
29+
The [example README](example/README.md) has some next steps.
30+
1831
## Why another tool?
1932

2033
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 +48,7 @@ This approach results in a pretty simple implementation and loose coupling to th
3548
As a consequence, things like aliases "just work" without requiring `clojure-nix-locker` to know about them.
3649

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

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)