Skip to content

Commit 12e53bd

Browse files
committed
Use Nix flakes, use built-in tomllib
Flakes are said to be the future ... the convenient "nix run" command from Nix 2.3 has been repurposed in later versions and there is no direct replacement. 2.3 is quite old by now, so jump on the flakes bandwagon. This also changes the Python script to no longer use the external "tomli" package, but to use the built-in "tomllib" instead (which is the former "tomli" brought into the stdlib).
1 parent 3eb0bb6 commit 12e53bd

File tree

6 files changed

+81
-29
lines changed

6 files changed

+81
-29
lines changed

README.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,26 @@ the future.
1010

1111
## Running
1212

13-
Run in an environment with all dependencies available with [Nix][nix] [2.3][nix-2.3]:
13+
GitHub access manager needs Python 3.11 or later (for TOML support) and has no
14+
dependencies outside of the standard library.
1415

15-
nix run --command ./main.py
16+
./main.py --help
17+
./main.py config.toml
1618

17-
Alternatively, use Python 3.11 which has toml support in the standard library,
18-
or set up a virtualenv and `pip install tomli`.
19+
Optionally, a Nix flake is provided to run with a pinned Python version. You
20+
need [Nix 2.10 or later](https://nixos.org/download.html). Then run `nix`
21+
with either `--extra-experimental-features nix-command` and
22+
`--extra-experimental-features flakes`, or add them to your
23+
`~/.config/nix/nix.conf`:
1924

20-
See the docstring in `main.py` for more information, or run with `--help`.
25+
experimental-features = nix-command flakes
2126

22-
[nix]: https://nixos.org/
23-
[nix-2.3]: https://releases.nixos.org/?prefix=nix/nix-2.3/
27+
Then run with Nix:
28+
29+
nix run . -- --help
30+
nix run . -- config.toml
31+
32+
You can also enter a shell with the right Python version in the environment:
33+
34+
nix develop
35+
./main.py --help

default.nix

Lines changed: 0 additions & 15 deletions
This file was deleted.

flake.lock

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

flake.nix

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
description = "GitHub Access Manager";
3+
4+
inputs.nixpkgs.url = "nixpkgs/nixos-unstable";
5+
6+
outputs = { self, nixpkgs }:
7+
let
8+
name = "github-access-manager";
9+
version = builtins.substring 0 8 self.lastModifiedDate;
10+
supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
11+
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
12+
in
13+
{
14+
packages = forAllSystems (system:
15+
let
16+
pkgs = import nixpkgs { inherit system; };
17+
in
18+
{
19+
default = pkgs.stdenv.mkDerivation {
20+
inherit name version;
21+
src = ./.;
22+
buildInputs = [ pkgs.python311 ];
23+
installPhase = ''
24+
mkdir --parents $out/bin
25+
echo "#!${pkgs.python311}/bin/python3" > preamble
26+
cat preamble main.py > $out/bin/github-access-manager
27+
chmod +x $out/bin/github-access-manager
28+
'';
29+
};
30+
}
31+
);
32+
};
33+
}

main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
import os
119119
import sys
120120
import json
121-
import tomli
121+
import tomllib
122122

123123
from typing import (
124124
Any,
@@ -406,8 +406,8 @@ def from_toml_dict(data: Dict[str, Any]) -> Configuration:
406406

407407
@staticmethod
408408
def from_toml_file(fname: str) -> Configuration:
409-
with open(fname, "r", encoding="utf-8") as f:
410-
data = tomli.load(f)
409+
with open(fname, "rb") as f:
410+
data = tomllib.load(f)
411411
return Configuration.from_toml_dict(data)
412412

413413
def get_repository_target(self, actual: Repository) -> Repository:

nixpkgs-pinned.nix

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)