-
Notifications
You must be signed in to change notification settings - Fork 3
/
default.nix
86 lines (77 loc) · 2.9 KB
/
default.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
{ pkgs ? import <nixpkgs> {} }:
let
lib = pkgs.lib;
es = lib.escapeShellArg;
standaloneLocker = let
locker = pkgs.writers.writePython3Bin "locker" {
libraries = [ pkgs.python3Packages.GitPython ];
# We don't care about lines being too long
flakeIgnore = [ "E501" ];
} ./locker.py;
in pkgs.runCommand "standalone-clojure-nix-locker-with-clojure" {
buildInputs = [ pkgs.makeWrapper ];
} ''
makeWrapper ${locker}/bin/locker \
$out/bin/standalone-clojure-nix-locker \
--prefix PATH : ${lib.makeBinPath [ pkgs.babashka ]}
'';
utils = import ./utils.nix { inherit pkgs; };
in {
inherit standaloneLocker;
lockfile =
{ # The git repository of this lockfile's project. If specified, a clean
# version of this repository (including uncommitted changes but without
# untracked files) will be available for lockfile generation
src ? null
, # The path to the lockfile, e.g. `./deps.lock.json`
lockfile
, # Specify the maven repositories to use, overriding the defaults
mavenRepos ?
[
"https://repo1.maven.org/maven2/"
"https://repo.clojars.org/"
]
}: rec {
commandLocker = command: pkgs.writeShellApplication {
name = "clojure-nix-locker";
runtimeInputs = [
pkgs.coreutils
pkgs.git
pkgs.gnutar
pkgs.gzip
pkgs.nix-prefetch-git
];
text = ''
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' exit
mkdir "$tmp"/{root,home}
pushd "$tmp/root"
${lib.optionalString (src != null)
(if builtins.pathExists (src + "/.git") then ''
# Copies all git-tracked files (including uncommitted changes and submodules)
# Why not `git archive $(git stash create)`? Because that doesn't include submodules
# Why not `git worktree create`? Because that doesn't include uncommitted changes
# Why --ignore-failed-read? Because `git ls-files` includes deleted files
git -C ${es (toString src)} ls-files -z \
| tar -C ${es (toString src)} --ignore-failed-read -cz --null -T - \
| tar -xzf -
'' else ''
cp -rT ${es (toString src)} .
'')
}
# flakes are copied to the nix store first and the files are therefore RO
chmod -R +w .
# Ensures that clojure creates all the caches in our empty separate home directory
export JAVA_TOOL_OPTIONS="-Duser.home=$tmp/home"
${command}
popd
${standaloneLocker}/bin/standalone-clojure-nix-locker "$tmp/home" > ${es (toString lockfile)}
'';
};
homeDirectory = import ./createHome.nix {
inherit pkgs src lockfile mavenRepos;
};
shellEnv = utils.shellEnv homeDirectory;
wrapClojure = utils.wrapClojure homeDirectory;
};
}