Skip to content

Commit d91d47c

Browse files
committed
flake: use flake-utils, add ruamel.yaml, apply nixfmt
1 parent dfb0063 commit d91d47c

2 files changed

Lines changed: 97 additions & 64 deletions

File tree

flake.lock

Lines changed: 44 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 53 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,62 @@
11
{
2-
description = "A Nix-flake-based Python development environment";
2+
description = "Parsers and algorithms for computational chemistry logfiles (regression data)";
33

4-
inputs.nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1";
4+
inputs = {
5+
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
};
58

6-
outputs = inputs:
9+
outputs =
10+
{
11+
self,
12+
nixpkgs,
13+
flake-utils,
14+
}:
715
let
8-
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
9-
forEachSupportedSystem = f: inputs.nixpkgs.lib.genAttrs supportedSystems (system: f {
10-
pkgs = import inputs.nixpkgs { inherit system; };
11-
});
12-
1316
/*
14-
* Change this value ({major}.{min}) to
15-
* update the Python virtual-environment
16-
* version. When you do this, make sure
17-
* to delete the `.venv` directory to
18-
* have the hook rebuild it for the new
19-
* version, since it won't overwrite an
20-
* existing one. After this, reload the
21-
* development shell to rebuild it.
22-
* You'll see a warning asking you to
23-
* do this when version mismatches are
24-
* present. For safety, removal should
25-
* be a manual step, even if trivial.
26-
*/
17+
Change this value ({major}.{min}) to
18+
update the Python virtual-environment
19+
version. When you do this, make sure
20+
to delete the `.venv` directory to
21+
have the hook rebuild it for the new
22+
version, since it won't overwrite an
23+
existing one. After this, reload the
24+
development shell to rebuild it.
25+
You'll see a warning asking you to
26+
do this when version mismatches are
27+
present. For safety, removal should
28+
be a manual step, even if trivial.
29+
*/
2730
version = "3.13";
2831
in
29-
{
30-
devShells = forEachSupportedSystem ({ pkgs }:
31-
let
32-
concatMajorMinor = v:
33-
pkgs.lib.pipe v [
34-
pkgs.lib.versions.splitVersion
35-
(pkgs.lib.sublist 0 2)
36-
pkgs.lib.concatStrings
37-
];
38-
39-
python = pkgs."python${concatMajorMinor version}";
40-
in
41-
{
42-
default = pkgs.mkShell {
32+
flake-utils.lib.eachDefaultSystem (
33+
system:
34+
let
35+
pkgs = import nixpkgs { inherit system; };
36+
in
37+
{
38+
devShells.default =
39+
let
40+
concatMajorMinor =
41+
v:
42+
pkgs.lib.pipe v [
43+
pkgs.lib.versions.splitVersion
44+
(pkgs.lib.sublist 0 2)
45+
pkgs.lib.concatStrings
46+
];
47+
python = pkgs."python${concatMajorMinor version}";
48+
in
49+
pkgs.mkShellNoCC {
4350
venvDir = ".venv";
4451

4552
postShellHook = ''
46-
venvVersionWarn() {
47-
local venvVersion
48-
venvVersion="$("$venvDir/bin/python" -c 'import platform; print(platform.python_version())')"
53+
venvVersionWarn() {
54+
local venvVersion
55+
venvVersion="$("$venvDir/bin/python" -c 'import platform; print(platform.python_version())')"
4956
50-
[[ "$venvVersion" == "${python.version}" ]] && return
57+
[[ "$venvVersion" == "${python.version}" ]] && return
5158
52-
cat <<EOF
59+
cat <<EOF
5360
Warning: Python version mismatch: [$venvVersion (venv)] != [${python.version}]
5461
Delete '$venvDir' and reload to rebuild for version ${python.version}
5562
EOF
@@ -58,22 +65,12 @@
5865
venvVersionWarn
5966
'';
6067

61-
packages = with python.pkgs; [
62-
venvShellHook
63-
pip
64-
65-
/* Add whatever else you'd like here. */
66-
# pkgs.basedpyright
67-
68-
# pkgs.black
69-
/* or */
70-
# python.pkgs.black
71-
72-
# pkgs.ruff
73-
/* or */
74-
# python.pkgs.ruff
68+
packages = [
69+
python.pkgs.pip
70+
python.pkgs.ruamel-yaml
71+
python.pkgs.venvShellHook
7572
];
7673
};
77-
});
78-
};
74+
}
75+
);
7976
}

0 commit comments

Comments
 (0)