Skip to content

Commit

Permalink
Merge Nix flake (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruuda committed Nov 7, 2022
2 parents a368057 + 12e53bd commit 2d7e982
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 29 deletions.
26 changes: 19 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,26 @@ the future.

## Running

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

nix run --command ./main.py
./main.py --help
./main.py config.toml

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

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

[nix]: https://nixos.org/
[nix-2.3]: https://releases.nixos.org/?prefix=nix/nix-2.3/
Then run with Nix:

nix run . -- --help
nix run . -- config.toml

You can also enter a shell with the right Python version in the environment:

nix develop
./main.py --help
15 changes: 0 additions & 15 deletions default.nix

This file was deleted.

26 changes: 26 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
description = "GitHub Access Manager";

inputs.nixpkgs.url = "nixpkgs/nixos-unstable";

outputs = { self, nixpkgs }:
let
name = "github-access-manager";
version = builtins.substring 0 8 self.lastModifiedDate;
supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
in
{
packages = forAllSystems (system:
let
pkgs = import nixpkgs { inherit system; };
in
{
default = pkgs.stdenv.mkDerivation {
inherit name version;
src = ./.;
buildInputs = [ pkgs.python311 ];
installPhase = ''
mkdir --parents $out/bin
echo "#!${pkgs.python311}/bin/python3" > preamble
cat preamble main.py > $out/bin/github-access-manager
chmod +x $out/bin/github-access-manager
'';
};
}
);
};
}
6 changes: 3 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
import os
import sys
import json
import tomli
import tomllib

from typing import (
Any,
Expand Down Expand Up @@ -412,8 +412,8 @@ def from_toml_dict(data: Dict[str, Any]) -> Configuration:

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

def get_repository_target(self, actual: Repository) -> Repository:
Expand Down
4 changes: 0 additions & 4 deletions nixpkgs-pinned.nix

This file was deleted.

0 comments on commit 2d7e982

Please sign in to comment.