chore: migrate to flake

This commit is contained in:
Luj 2025-06-05 19:52:17 +02:00
parent 8194610c03
commit 685826a052
Signed by: luj
GPG key ID: 6FC74C847011FD83
6 changed files with 85 additions and 166 deletions

2
.envrc
View file

@ -1 +1 @@
use nix
use flake

View file

@ -1,63 +0,0 @@
let
inputs = import ./deps;
system = "x86_64-linux";
pkgs = import inputs.nixpkgs { inherit system; };
pre-commit-hook = (import inputs."git-hooks.nix").run {
src = ./.;
hooks = {
statix.enable = true;
deadnix.enable = true;
rfc101 = {
enable = true;
name = "RFC-101 formatting";
entry = "${pkgs.lib.getExe pkgs.nixfmt-rfc-style}";
files = "\\.nix$";
};
commitizen.enable = true;
};
};
in
rec {
devShells.default = pkgs.mkShell {
nativeBuildInputs = [ pkgs.bashInteractive ];
buildInputs = with pkgs; [
quarto
texliveFull
jose
clevis
jq
];
shellHook = ''
${pre-commit-hook.shellHook}
'';
};
packages.x86_64-linux = {
website = pkgs.callPackage (
{ stdenv, quarto, ... }:
stdenv.mkDerivation {
name = "fosdem24-clevis";
src = ./.;
buildInputs = [ quarto ];
buildPhase = ''
mkdir _slides
HOME=. quarto render index.qmd --to revealjs --output-dir _slides
'';
installPhase = ''
cp -r _slides $out
'';
}
) { };
};
checks.default = {
inherit packages;
};
}

79
deps/default.nix vendored
View file

@ -1,79 +0,0 @@
# Generated by npins. Do not modify; will be overwritten regularly
let
data = builtins.fromJSON (builtins.readFile ./sources.json);
inherit (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,
...
}:
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 {
inherit (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`"

23
deps/sources.json vendored
View file

@ -1,23 +0,0 @@
{
"pins": {
"git-hooks.nix": {
"type": "Git",
"repository": {
"type": "GitHub",
"owner": "cachix",
"repo": "git-hooks.nix"
},
"branch": "master",
"revision": "f451c19376071a90d8c58ab1a953c6e9840527fd",
"url": "https://github.com/cachix/git-hooks.nix/archive/f451c19376071a90d8c58ab1a953c6e9840527fd.tar.gz",
"hash": "1gdkg3bcxqzccb7gzp2gvbwjk7lnv3p9sl10113z9dnmn6bx8lz8"
},
"nixpkgs": {
"type": "Channel",
"name": "nixpkgs-unstable",
"url": "https://releases.nixos.org/nixpkgs/nixpkgs-24.11pre658316.e36e9f57337d/nixexprs.tar.xz",
"hash": "0z1dl3aaxhia642i9xfv571r040axkbm1zyxylgmhsqkra5lxk8z"
}
},
"version": 3
}

27
flake.lock generated Normal file
View file

@ -0,0 +1,27 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1743931715,
"narHash": "sha256-bEWnr2OeYC5KDmYUR7QP+I/T8bnYt/Rc5iwfXUGP/Uo=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "b49ceb963bf623f1d779b782dbf3289ddb313c47",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

57
flake.nix Normal file
View file

@ -0,0 +1,57 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
};
outputs =
{ nixpkgs, ... }:
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
in
rec {
devShells.default = pkgs.mkShell {
nativeBuildInputs = [ pkgs.bashInteractive ];
buildInputs = with pkgs; [
quarto
texliveFull
];
};
packages.x86_64-linux = {
default = pkgs.callPackage (
{
stdenv,
quarto,
which,
...
}:
stdenv.mkDerivation {
name = "coap-february-2025";
src = ./.;
buildInputs = [
quarto
which
];
buildPhase = ''
mkdir _slides
HOME=. quarto render index.qmd --output-dir _slides
'';
installPhase = ''
cp -r _slides $out
rm $out/index.qmd
rm $out/*.nix
'';
}
) { };
};
checks.default = {
inherit packages;
};
};
}