Skip to content

Commit da2bcaa

Browse files
authored
Merge pull request #7 from jappeace-sloth/fix-devuan-keyerror
Fix KeyError on devuan-based distros (#6)
2 parents 47c09b3 + 50a3d35 commit da2bcaa

11 files changed

Lines changed: 438 additions & 0 deletions

File tree

‎.github/workflows/test.yml‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: "Test"
2+
on:
3+
pull_request:
4+
push:
5+
jobs:
6+
checks:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v6
10+
- uses: cachix/install-nix-action@v31
11+
with:
12+
extra_nix_config: |
13+
experimental-features = nix-command flakes
14+
- name: Nix store cache
15+
uses: nix-community/cache-nix-action@v6
16+
with:
17+
primary-key: nix-${{ hashFiles('npins/sources.json', 'nix/*.nix') }}
18+
restore-prefixes-first-match: nix-
19+
# All the work lives in nix/ci.nix so it reproduces locally; CI just calls it.
20+
- run: nix-build nix/ci.nix -A checks
21+
- name: Cancel workflow on failure
22+
if: failure()
23+
continue-on-error: true
24+
run: gh run cancel ${{ github.run_id }}
25+
env:
26+
GH_TOKEN: ${{ github.token }}

‎.gitignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@
88
out
99

1010
__pycache__
11+
12+
# nix build output symlinks
13+
result
14+
result-*

‎correct.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@
6262
(re.compile("^debian,linspire$"), "debian,ubuntu,linspire"),
6363
# debian clusterfuck
6464
(re.compile("^debian,ubuntu,knoppix$"), "debian,ubuntu,debian,knoppix"),
65+
# devuan forked debian, distrowatch lists distros as based on devuan
66+
# directly without tracing back to the independent debian root
67+
(re.compile("^devuan"), "debian,devuan"),
6568

6669
# distrowatch didn't want to put up with the numbers
6770
(re.compile("m0n0wall"), "monowall"),

‎nix/ci.nix‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# The real CI work lives here so it can be reproduced locally with a single
2+
# `nix-build nix/ci.nix`. GitHub Actions only wraps this. It builds the exact
3+
# python environment the app needs, byte-compiles every module to catch syntax
4+
# errors, and runs the test suite as a sandboxed derivation.
5+
{ pkgs ? import ./pin.nix }:
6+
let
7+
# Runtime deps: fetchdists.py uses requests + beautifulsoup4, the rest of the
8+
# pipeline (graph/correct/svg) is stdlib only.
9+
pythonEnv = pkgs.python3.withPackages (packages: [
10+
packages.requests
11+
packages.beautifulsoup4
12+
]);
13+
14+
# Only the source tree, not the git metadata or a stray out/ cache dir.
15+
src = pkgs.lib.cleanSource ../.;
16+
17+
checks = pkgs.runCommand "distrowatch1graph1svg-checks"
18+
{ nativeBuildInputs = [ pythonEnv ]; }
19+
''
20+
cp -r ${src}/. build
21+
chmod -R u+w build
22+
cd build
23+
24+
echo "== byte-compiling every module =="
25+
python3 -m compileall -q *.py
26+
27+
echo "== running test suite =="
28+
for test in test_*.py; do
29+
echo "--- $test ---"
30+
python3 "$test"
31+
done
32+
33+
touch $out
34+
'';
35+
in {
36+
# `nix-build nix/ci.nix -A checks` (or just the default below) runs everything.
37+
inherit checks pythonEnv;
38+
}

‎nix/config.nix‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Decision: keep nixpkgs config in one file so shell.nix and nix/ci.nix import
2+
# the exact same package set. Alternatives considered: inlining config at each
3+
# import site (drifts out of sync). No unfree packages are needed here.
4+
{
5+
}

‎nix/pin.nix‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Thin shim over npins so every consumer (shell.nix, nix/ci.nix) pulls the same
2+
# pinned nixpkgs. Bump the pin with: npins update nixpkgs
3+
import (import ../npins).nixpkgs { config = import ./config.nix; }

‎npins/default.nix‎

Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
/*
2+
This file is provided under the MIT licence:
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
6+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
8+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9+
*/
10+
# Generated by npins. Do not modify; will be overwritten regularly
11+
let
12+
# Backwards-compatibly make something that previously didn't take any arguments take some
13+
# The function must return an attrset, and will unfortunately be eagerly evaluated
14+
# Same thing, but it catches eval errors on the default argument so that one may still call it with other arguments
15+
mkFunctor =
16+
fn:
17+
let
18+
e = builtins.tryEval (fn { });
19+
in
20+
(if e.success then e.value else { error = fn { }; }) // { __functor = _self: fn; };
21+
22+
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295
23+
range =
24+
first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1);
25+
26+
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257
27+
stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1));
28+
29+
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269
30+
stringAsChars = f: s: concatStrings (map f (stringToCharacters s));
31+
concatStrings = builtins.concatStringsSep "";
32+
33+
# If the environment variable NPINS_OVERRIDE_${name} is set, then use
34+
# the path directly as opposed to the fetched source.
35+
# (Taken from Niv for compatibility)
36+
mayOverride =
37+
name: path:
38+
let
39+
envVarName = "NPINS_OVERRIDE_${saneName}";
40+
saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name;
41+
ersatz = builtins.getEnv envVarName;
42+
in
43+
if ersatz == "" then
44+
path
45+
else
46+
# this turns the string into an actual Nix path (for both absolute and
47+
# relative paths)
48+
builtins.trace "Overriding path of \"${name}\" with \"${ersatz}\" due to set \"${envVarName}\"" (
49+
if builtins.substring 0 1 ersatz == "/" then
50+
/. + ersatz
51+
else
52+
/. + builtins.getEnv "PWD" + "/${ersatz}"
53+
);
54+
55+
mkSource =
56+
name: spec:
57+
{
58+
pkgs ? null,
59+
}:
60+
assert spec ? type;
61+
let
62+
# Unify across builtin and pkgs fetchers.
63+
# `fetchGit` requires a wrapper because of slight API differences.
64+
fetchers =
65+
if pkgs == null then
66+
{
67+
inherit (builtins) fetchTarball fetchurl;
68+
# Frustratingly, due to flakes and `fetchTree`, `fetchGit`
69+
# has a different signature than the other builtin
70+
# fetchers
71+
fetchGit = args: (builtins.fetchGit args).outPath;
72+
}
73+
else
74+
{
75+
fetchTarball =
76+
{
77+
url,
78+
sha256,
79+
}:
80+
pkgs.fetchzip {
81+
inherit url sha256;
82+
extension = "tar";
83+
};
84+
inherit (pkgs) fetchurl;
85+
fetchGit =
86+
{
87+
url,
88+
submodules,
89+
rev,
90+
name,
91+
narHash,
92+
}:
93+
pkgs.fetchgit {
94+
inherit url rev name;
95+
fetchSubmodules = submodules;
96+
hash = narHash;
97+
};
98+
};
99+
100+
path =
101+
if spec.type == "Git" then
102+
mkGitSource fetchers spec
103+
else if spec.type == "GitRelease" then
104+
mkGitSource fetchers spec
105+
else if spec.type == "PyPi" then
106+
mkPyPiSource fetchers spec
107+
else if spec.type == "Channel" then
108+
mkChannelSource fetchers spec
109+
else if spec.type == "Url" || spec.type == "MutableUrl" then
110+
mkUrlSource fetchers spec
111+
else if spec.type == "Container" then
112+
mkContainerSource pkgs spec
113+
else
114+
builtins.throw "Unknown source type ${spec.type}";
115+
in
116+
spec // { outPath = mayOverride name path; };
117+
118+
mkGitSource =
119+
{
120+
fetchTarball,
121+
fetchGit,
122+
...
123+
}:
124+
{
125+
repository,
126+
revision,
127+
url ? null,
128+
submodules,
129+
hash,
130+
...
131+
}:
132+
assert repository ? type;
133+
# At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository
134+
# In the latter case, there we will always be an url to the tarball
135+
if url != null && !submodules then
136+
fetchTarball {
137+
inherit url;
138+
sha256 = hash;
139+
}
140+
else
141+
let
142+
url =
143+
if repository.type == "Git" then
144+
repository.url
145+
else if repository.type == "GitHub" then
146+
"https://github.com/${repository.owner}/${repository.repo}.git"
147+
else if repository.type == "GitLab" then
148+
"${repository.server}/${repository.repo_path}.git"
149+
else if repository.type == "Forgejo" then
150+
"${repository.server}/${repository.owner}/${repository.repo}.git"
151+
else
152+
throw "Unrecognized repository type ${repository.type}";
153+
urlToName =
154+
url: rev:
155+
let
156+
matched = builtins.match "^.*/([^/]*)(\\.git)?$" url;
157+
158+
short = builtins.substring 0 7 rev;
159+
160+
appendShort = if (builtins.match "[a-f0-9]*" rev) != null then "-${short}" else "";
161+
in
162+
"${if matched == null then "source" else builtins.head matched}${appendShort}";
163+
name = urlToName url revision;
164+
in
165+
fetchGit {
166+
rev = revision;
167+
narHash = hash;
168+
169+
inherit name submodules url;
170+
};
171+
172+
mkPyPiSource =
173+
{ fetchurl, ... }:
174+
{
175+
url,
176+
hash,
177+
...
178+
}:
179+
fetchurl {
180+
inherit url;
181+
sha256 = hash;
182+
};
183+
184+
mkChannelSource =
185+
{ fetchTarball, ... }:
186+
{
187+
url,
188+
hash,
189+
...
190+
}:
191+
fetchTarball {
192+
inherit url;
193+
sha256 = hash;
194+
};
195+
196+
mkUrlSource =
197+
{
198+
fetchTarball,
199+
fetchurl,
200+
...
201+
}:
202+
{
203+
url,
204+
hash,
205+
unpack,
206+
...
207+
}:
208+
(if unpack then fetchTarball else fetchurl) {
209+
inherit url;
210+
sha256 = hash;
211+
};
212+
213+
mkContainerSource =
214+
pkgs:
215+
{
216+
image_name,
217+
image_tag,
218+
image_digest,
219+
hash,
220+
...
221+
}@args:
222+
if pkgs == null then
223+
builtins.throw "container sources require passing in a Nixpkgs value: https://github.com/andir/npins/blob/master/README.md#using-the-nixpkgs-fetchers"
224+
else
225+
pkgs.dockerTools.pullImage (
226+
{
227+
imageName = image_name;
228+
imageDigest = image_digest;
229+
finalImageTag = image_tag;
230+
hash = hash;
231+
}
232+
// (if args.arch or null != null then { arch = args.arch; } else { })
233+
);
234+
235+
in
236+
mkFunctor (
237+
{
238+
input ? ./sources.json,
239+
}:
240+
let
241+
data =
242+
if builtins.isPath input then
243+
# while `readFile` will throw an error anyways if the path doesn't exist,
244+
# we still need to check beforehand because *our* error can be caught but not the one from the builtin
245+
# See: <https://git.lix.systems/lix-project/lix/issues/1098>
246+
if builtins.pathExists input then
247+
builtins.fromJSON (builtins.readFile input)
248+
else
249+
throw "Input path ${toString input} does not exist"
250+
else if builtins.isAttrs input then
251+
input
252+
else
253+
throw "Unsupported input type ${builtins.typeOf input}, must be a path or an attrset";
254+
version = data.version;
255+
in
256+
if version == 8 then
257+
builtins.mapAttrs (name: spec: mkFunctor (mkSource name spec)) data.pins
258+
else
259+
throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`"
260+
)

‎npins/sources.json‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"pins": {
3+
"nixpkgs": {
4+
"type": "Git",
5+
"repository": {
6+
"type": "GitHub",
7+
"owner": "NixOS",
8+
"repo": "nixpkgs"
9+
},
10+
"branch": "nixos-unstable",
11+
"submodules": false,
12+
"revision": "e7a3ca8092b61ff85b6a45bf863ea2b2d6a661b3",
13+
"url": "https://github.com/NixOS/nixpkgs/archive/e7a3ca8092b61ff85b6a45bf863ea2b2d6a661b3.tar.gz",
14+
"hash": "sha256-UgCQzxeWI75XM8G+hPrPh+MKzEPjG3SpAj7dtqSbksA="
15+
}
16+
},
17+
"version": 8
18+
}

‎requirements.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
requests
2+
beautifulsoup4

‎shell.nix‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Dev shell pinned through npins (same nixpkgs as nix/ci.nix). Enter with
2+
# `nix-shell`; you get python3 with the app's runtime deps plus gnuclad and
3+
# inkscape which __main__.py shells out to for the svg/png rendering.
4+
{ pkgs ? import ./nix/pin.nix }:
5+
pkgs.mkShell {
6+
packages = [
7+
(pkgs.python3.withPackages (python: [
8+
python.requests
9+
python.beautifulsoup4
10+
]))
11+
pkgs.gnuclad
12+
pkgs.inkscape
13+
];
14+
}

0 commit comments

Comments
 (0)