From 29aafc26fa2519bd2624223392eb96179376939c Mon Sep 17 00:00:00 2001 From: Kiara Grouwstra Date: Mon, 14 Apr 2025 11:55:16 +0200 Subject: [PATCH] add deps/ci --- .forgejo/workflows/ci.yaml | 23 +++++++++++ default.nix | 6 +-- npins/default.nix | 80 ++++++++++++++++++++++++++++++++++++++ npins/sources.json | 11 ++++++ 4 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 .forgejo/workflows/ci.yaml create mode 100644 npins/default.nix create mode 100644 npins/sources.json diff --git a/.forgejo/workflows/ci.yaml b/.forgejo/workflows/ci.yaml new file mode 100644 index 0000000..7b5c087 --- /dev/null +++ b/.forgejo/workflows/ci.yaml @@ -0,0 +1,23 @@ +on: + pull_request: + types: + - opened + - synchronize + - reopened + push: + branches: + - main + +jobs: + check-pre-commit: + runs-on: native + steps: + - uses: actions/checkout@v4 + - run: nix build .#checks.x86_64-linux.pre-commit -L + + check-website: + runs-on: native + steps: + - uses: actions/checkout@v4 + - run: nix-build -A tests + - run: nix-build -A build diff --git a/default.nix b/default.nix index 258d1ff..8a02ec3 100644 --- a/default.nix +++ b/default.nix @@ -1,5 +1,5 @@ { - sources ? import ../npins, + sources ? import ./npins, system ? builtins.currentSystem, pkgs ? import sources.nixpkgs { inherit system; @@ -75,12 +75,12 @@ rec { with lib; let source = fileset.toSource { - root = ../.; + root = ./.; fileset = fileset.unions [ ./default.nix ./tests.nix ./lib.nix - ../npins + ./npins ]; }; in diff --git a/npins/default.nix b/npins/default.nix new file mode 100644 index 0000000..5e7d086 --- /dev/null +++ b/npins/default.nix @@ -0,0 +1,80 @@ +# Generated by npins. Do not modify; will be overwritten regularly +let + data = builtins.fromJSON (builtins.readFile ./sources.json); + version = data.version; + + mkSource = + spec: + assert spec ? type; + let + path = + if spec.type == "Git" then + mkGitSource spec + else if spec.type == "GitRelease" then + mkGitSource spec + else if spec.type == "PyPi" then + mkPyPiSource spec + else if spec.type == "Channel" then + mkChannelSource spec + else + builtins.throw "Unknown source type ${spec.type}"; + in + spec // { outPath = path; }; + + mkGitSource = + { + repository, + revision, + url ? null, + hash, + branch ? null, + ... + }: + assert repository ? type; + # At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository + # In the latter case, there we will always be an url to the tarball + if url != null then + (builtins.fetchTarball { + inherit url; + sha256 = hash; # FIXME: check nix version & use SRI hashes + }) + else + assert repository.type == "Git"; + let + urlToName = + url: rev: + let + matched = builtins.match "^.*/([^/]*)(\\.git)?$" repository.url; + + short = builtins.substring 0 7 rev; + + appendShort = if (builtins.match "[a-f0-9]*" rev) != null then "-${short}" else ""; + in + "${if matched == null then "source" else builtins.head matched}${appendShort}"; + name = urlToName repository.url revision; + in + builtins.fetchGit { + url = repository.url; + rev = revision; + inherit name; + # hash = hash; + }; + + mkPyPiSource = + { url, hash, ... }: + builtins.fetchurl { + inherit url; + sha256 = hash; + }; + + mkChannelSource = + { url, hash, ... }: + builtins.fetchTarball { + inherit url; + sha256 = hash; + }; +in +if version == 3 then + builtins.mapAttrs (_: mkSource) data.pins +else + throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`" diff --git a/npins/sources.json b/npins/sources.json new file mode 100644 index 0000000..e6bc997 --- /dev/null +++ b/npins/sources.json @@ -0,0 +1,11 @@ +{ + "pins": { + "nixpkgs": { + "type": "Channel", + "name": "nixpkgs-unstable", + "url": "https://releases.nixos.org/nixpkgs/nixpkgs-25.05pre777917.b7ba7f9f45c5/nixexprs.tar.xz", + "hash": "0jb6b7sv66bn06pchj2l88z0i5dlz0c2vb3z6pjjlq2p8q11zigg" + } + }, + "version": 3 +}