Skip to content

Commit 2d7e982

Browse files
committed
Merge Nix flake (#6)
2 parents a368057 + 12e53bd commit 2d7e982

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
@@ -124,7 +124,7 @@
124124
import os
125125
import sys
126126
import json
127-
import tomli
127+
import tomllib
128128

129129
from typing import (
130130
Any,
@@ -412,8 +412,8 @@ def from_toml_dict(data: Dict[str, Any]) -> Configuration:
412412

413413
@staticmethod
414414
def from_toml_file(fname: str) -> Configuration:
415-
with open(fname, "r", encoding="utf-8") as f:
416-
data = tomli.load(f)
415+
with open(fname, "rb") as f:
416+
data = tomllib.load(f)
417417
return Configuration.from_toml_dict(data)
418418

419419
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)