Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
154 lines (145 loc) · 4.84 KB
/
Copy pathflake.nix
File metadata and controls
154 lines (145 loc) · 4.84 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
nixpkgs_master.url = "github:NixOS/nixpkgs/master";
systems.url = "github:nix-systems/default";
flake-utils.url = "github:numtide/flake-utils";
flake-utils.inputs.systems.follows = "systems";
git-hooks = {
url = "github:cachix/git-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
flake-utils,
git-hooks,
treefmt-nix,
...
}@inputs:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
config.cudaSupport = true;
};
mpkgs = import inputs.nixpkgs_master {
inherit system;
config.allowUnfree = true;
config.cudaSupport = true;
};
libList = [
# Add needed packages here
mpkgs.stdenv.cc.cc.lib
pkgs.libGL
pkgs.glib
pkgs.zlib
]
++ pkgs.lib.optionals pkgs.stdenv.isLinux (with pkgs; [ ]);
treefmtEval = treefmt-nix.lib.evalModule pkgs {
projectRootFile = "flake.nix";
programs.nixfmt.enable = true;
programs.ruff-check.enable = true;
programs.ruff-format.enable = true;
};
portablePreCommitConfig = pkgs.writeText "pre-commit-config.yaml" ''
# DO NOT MODIFY
# Generated by `nix run .#update-pre-commit-config`
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v${pkgs.ruff.version}
hooks:
- id: ruff-check
args: [--fix]
types_or: [python, pyi]
- id: ruff-format
types_or: [python, pyi]
'';
updatePreCommitConfig = pkgs.writeShellApplication {
name = "update-pre-commit-config";
runtimeInputs = [
pkgs.coreutils
pkgs.git
];
text = ''
repoRoot="$(git rev-parse --show-toplevel)"
rm -f "$repoRoot/.pre-commit-config.yaml"
install -m 0644 ${portablePreCommitConfig} "$repoRoot/.pre-commit-config.yaml"
'';
};
pre-commit-check = git-hooks.lib.${system}.run {
src = ./.;
package = pkgs.prek;
install.enable = false;
hooks.treefmt = {
enable = true;
package = treefmtEval.config.build.wrapper;
};
};
in
with pkgs;
{
apps.update-pre-commit-config = {
type = "app";
program = "${updatePreCommitConfig}/bin/update-pre-commit-config";
meta.description = "Regenerate the portable pre-commit configuration";
};
checks = {
inherit pre-commit-check;
formatting = treefmtEval.config.build.check self;
pre-commit-config = runCommand "pre-commit-config-check" { nativeBuildInputs = [ diffutils ]; } ''
diff --unified ${portablePreCommitConfig} ${self}/.pre-commit-config.yaml
touch $out
'';
};
formatter = treefmtEval.config.build.wrapper;
devShells = {
default =
let
python_with_pkgs = pkgs.python311.withPackages (pp: [
# Add python pkgs here that you need from nix repos
]);
in
mkShell {
NIX_LD = runCommand "ld.so" { } ''
ln -s "$(cat '${pkgs.stdenv.cc}/nix-support/dynamic-linker')" $out
'';
NIX_LD_LIBRARY_PATH = lib.makeLibraryPath libList;
packages = [
python_with_pkgs
python311Packages.venvShellHook
mpkgs.uv
prek
]
++ libList;
venvDir = "./.venv";
postVenvCreation = ''
unset SOURCE_DATE_EPOCH
'';
postShellHook = ''
unset SOURCE_DATE_EPOCH
'';
shellHook = ''
if ${pkgs.git}/bin/git rev-parse --git-dir > /dev/null 2>&1; then
repoRoot="$(${pkgs.git}/bin/git rev-parse --show-toplevel)"
(cd "$repoRoot" && prek install --config .pre-commit-config.yaml)
fi
export LD_LIBRARY_PATH=$NIX_LD_LIBRARY_PATH:$LD_LIBRARY_PATH
export PYTHON_KEYRING_BACKEND=keyring.backends.fail.Keyring
runHook venvShellHook
uv sync --frozen --all-extras --dev
export PYTHONPATH=${python_with_pkgs}/${python_with_pkgs.sitePackages}:$PYTHONPATH
'';
};
};
}
);
}