From a4eabf71732fbbef24aaf4131a9dc8718c07ab5d Mon Sep 17 00:00:00 2001 From: Victor Mignot Date: Wed, 1 Jan 2025 13:25:08 +0100 Subject: [PATCH] Nix: Drop flake support in favor of npins --- Cargo.toml | 2 +- default.nix | 18 +++++++++ flake.lock | 94 ---------------------------------------------- flake.nix | 58 ---------------------------- npins/default.nix | 80 +++++++++++++++++++++++++++++++++++++++ npins/sources.json | 11 ++++++ pkgs.nix | 4 ++ shell.nix | 21 +++++++++++ 8 files changed, 135 insertions(+), 153 deletions(-) create mode 100644 default.nix delete mode 100644 flake.lock delete mode 100644 flake.nix create mode 100644 npins/default.nix create mode 100644 npins/sources.json create mode 100644 pkgs.nix create mode 100644 shell.nix diff --git a/Cargo.toml b/Cargo.toml index 25b0d8b..3c1473d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yorokobot" -description = "A Discord bot to handle a topic subscription system" +description = "Discord bot implementing a topic management system" version = "0.2.1" authors = [ "Victor Mignot " ] license = "EUPL-1.2" diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..e743b49 --- /dev/null +++ b/default.nix @@ -0,0 +1,18 @@ +{ + pkgs ? import ./pkgs.nix, + ... +}: +pkgs.rustPlatform.buildRustPackage { + pname = "yorokobot"; + version = "0.2.1"; + + src = ./.; + + cargoSha256 = "sha256-FfhyVjCZRvjbSAQ8aGTegjtSh5d4vMSoxzk+xagmj9w="; + + meta = with pkgs.lib; { + description = "Discord bot implementing a topic management system"; + homepage = "https://git.dalaran.fr/dala/yorokobot"; + license = licenses.eupl12; + }; +} diff --git a/flake.lock b/flake.lock deleted file mode 100644 index 83c7256..0000000 --- a/flake.lock +++ /dev/null @@ -1,94 +0,0 @@ -{ - "nodes": { - "flake-utils": { - "locked": { - "lastModified": 1659877975, - "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_2": { - "locked": { - "lastModified": 1656928814, - "narHash": "sha256-RIFfgBuKz6Hp89yRr7+NR5tzIAbn52h8vT6vXkYjZoM=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "7e2a3b3dfd9af950a856d66b0a7d01e3c18aa249", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1663494472, - "narHash": "sha256-fSowlaoXXWcAM8m9wA6u+eTJJtvruYHMA+Lb/tFi/qM=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "f677051b8dc0b5e2a9348941c99eea8c4b0ff28f", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_2": { - "locked": { - "lastModified": 1659102345, - "narHash": "sha256-Vbzlz254EMZvn28BhpN8JOi5EuKqnHZ3ujFYgFcSGvk=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "11b60e4f80d87794a2a4a8a256391b37c59a1ea7", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs", - "rust-overlay": "rust-overlay" - } - }, - "rust-overlay": { - "inputs": { - "flake-utils": "flake-utils_2", - "nixpkgs": "nixpkgs_2" - }, - "locked": { - "lastModified": 1663729386, - "narHash": "sha256-aKdxkiYUGuvgy+eKq4jubf/gZN7TBoF6huE4w0chhDE=", - "owner": "oxalica", - "repo": "rust-overlay", - "rev": "0300688a98e053712108d4e22d5bdcf9c9106d8c", - "type": "github" - }, - "original": { - "owner": "oxalica", - "repo": "rust-overlay", - "type": "github" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/flake.nix b/flake.nix deleted file mode 100644 index 41d4429..0000000 --- a/flake.nix +++ /dev/null @@ -1,58 +0,0 @@ -{ - description = "Discord Bot managing users interests."; - - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - rust-overlay.url = "github:oxalica/rust-overlay"; - flake-utils.url = "github:numtide/flake-utils"; - }; - - outputs = {self, nixpkgs, rust-overlay, flake-utils, ...}: - flake-utils.lib.eachDefaultSystem (system: - let - overlays = [ (import rust-overlay) ]; - pkgs = import nixpkgs { - inherit system overlays; - }; - in - with pkgs; - { - packages.default = pkgs.rustPlatform.buildRustPackage rec { - pname = "yorokobot"; - version = "0.2.1"; - - src = self; - - cargoSha256 = "sha256-FfhyVjCZRvjbSAQ8aGTegjtSh5d4vMSoxzk+xagmj9w="; - - meta = with pkgs.lib; { - description = "Discord bot implementing a topic management system"; - homepage = "https://sr.ht/~dala/yorokobot"; - license = licenses.agpl3; - }; - }; - - devShells.default = mkShell { - buildInputs = [ - ( - rust-bin.stable.latest.default.override { - extensions = [ "rust-src" ]; - } - ) - ]; - - packages = with pkgs; [ - rust-analyzer - rustfmt - gdb - ]; - - shellHook = '' - set -a - source .env - set +a - ''; - }; - } - ); -} 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..8048345 --- /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.05pre730187.0e82ab234249/nixexprs.tar.xz", + "hash": "0s5snh81d5n9zxcn9n2fqk6jcinfd5ys97fcw8qyrs9dlprp1slw" + } + }, + "version": 3 +} \ No newline at end of file diff --git a/pkgs.nix b/pkgs.nix new file mode 100644 index 0000000..8ff761a --- /dev/null +++ b/pkgs.nix @@ -0,0 +1,4 @@ +let + inherit (import ./npins) nixpkgs; +in +import nixpkgs { } diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..01595e0 --- /dev/null +++ b/shell.nix @@ -0,0 +1,21 @@ +{ + pkgs ? import ./pkgs.nix, + ... +}: +pkgs.mkShell { + strictDeps = true; + + nativeBuildInputs = with pkgs; [ + rustc + cargo + ]; + + packages = with pkgs; [ + clippy + rust-analyzer + rustfmt + gdb + nixfmt-rfc-style + nil + ]; +}