Nix: Drop flake support in favor of npins

This commit is contained in:
Victor Mignot 2025-01-01 13:25:08 +01:00
parent 385c64186f
commit a4eabf7173
Signed by: dala
SSH key fingerprint: SHA256:+3O9MhlDc2tJL0n+E+Myr7nL+74DP9AXdIXHmIqZTkY
8 changed files with 135 additions and 153 deletions

View file

@ -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 <dala@dalaran.fr>" ]
license = "EUPL-1.2"

18
default.nix Normal file
View file

@ -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;
};
}

View file

@ -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
}

View file

@ -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
'';
};
}
);
}

80
npins/default.nix Normal file
View file

@ -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`"

11
npins/sources.json Normal file
View file

@ -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
}

4
pkgs.nix Normal file
View file

@ -0,0 +1,4 @@
let
inherit (import ./npins) nixpkgs;
in
import nixpkgs { }

21
shell.nix Normal file
View file

@ -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
];
}