124 lines
3.5 KiB
Nix
124 lines
3.5 KiB
Nix
# flake.nix — repo-lib
|
|
{
|
|
description = "Pure-first repo development platform for Nix flakes";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
|
|
git-hooks.url = "github:cachix/git-hooks.nix";
|
|
treefmt-nix.url = "github:numtide/treefmt-nix";
|
|
};
|
|
|
|
outputs =
|
|
{
|
|
self,
|
|
nixpkgs,
|
|
treefmt-nix,
|
|
git-hooks,
|
|
...
|
|
}:
|
|
let
|
|
lib = nixpkgs.lib;
|
|
repoLib = import ./packages/repo-lib/lib.nix {
|
|
inherit nixpkgs treefmt-nix git-hooks;
|
|
releaseScriptPath = ./packages/release/release.sh;
|
|
shellHookTemplatePath = ./packages/repo-lib/shell-hook.sh;
|
|
};
|
|
supportedSystems = repoLib.systems.default;
|
|
importPkgs = nixpkgsInput: system: import nixpkgsInput { inherit system; };
|
|
|
|
projectOutputs = repoLib.mkRepo {
|
|
inherit self nixpkgs;
|
|
src = ./.;
|
|
config = {
|
|
release = {
|
|
steps = [
|
|
{
|
|
replace = {
|
|
path = "template/flake.nix";
|
|
regex = ''^([[:space:]]*repo-lib\.url = ")git\+https://git\.dgren\.dev/eric/nix-flake-lib[^"]*(";)'';
|
|
replacement = ''\1git+https://git.dgren.dev/eric/nix-flake-lib?ref=$FULL_TAG\2'';
|
|
};
|
|
}
|
|
{
|
|
replace = {
|
|
path = "README.md";
|
|
regex = ''(nix flake new myapp -t ')git\+https://git\.dgren\.dev/eric/nix-flake-lib[^']*(#default' --refresh)'';
|
|
replacement = ''\1git+https://git.dgren.dev/eric/nix-flake-lib?ref=$FULL_TAG\2'';
|
|
};
|
|
}
|
|
{
|
|
replace = {
|
|
path = "README.md";
|
|
regex = ''^([[:space:]]*inputs\.repo-lib\.url = ")git\+https://git\.dgren\.dev/eric/nix-flake-lib[^"]*(";)'';
|
|
replacement = ''\1git+https://git.dgren.dev/eric/nix-flake-lib?ref=$FULL_TAG\2'';
|
|
};
|
|
}
|
|
];
|
|
};
|
|
};
|
|
perSystem =
|
|
{
|
|
pkgs,
|
|
system,
|
|
...
|
|
}:
|
|
{
|
|
tools = [
|
|
(repoLib.tools.fromPackage {
|
|
name = "Nix";
|
|
package = pkgs.nix;
|
|
version.args = [ "--version" ];
|
|
})
|
|
];
|
|
|
|
shell.packages = [ self.packages.${system}.release ];
|
|
};
|
|
};
|
|
|
|
testChecks = lib.genAttrs supportedSystems (
|
|
system:
|
|
let
|
|
pkgs = importPkgs nixpkgs system;
|
|
in
|
|
{
|
|
release-tests =
|
|
pkgs.runCommand "release-tests"
|
|
{
|
|
nativeBuildInputs = with pkgs; [
|
|
bash
|
|
git
|
|
gnused
|
|
coreutils
|
|
gnugrep
|
|
nix
|
|
perl
|
|
];
|
|
}
|
|
''
|
|
export REPO_LIB_ROOT=${./.}
|
|
export NIXPKGS_FLAKE_PATH=${nixpkgs}
|
|
export HOME="$TMPDIR"
|
|
export NIX_CONFIG="experimental-features = nix-command flakes"
|
|
${pkgs.bash}/bin/bash ${./tests/release.sh}
|
|
touch "$out"
|
|
'';
|
|
}
|
|
);
|
|
in
|
|
projectOutputs
|
|
// {
|
|
lib = repoLib;
|
|
|
|
templates = {
|
|
default = {
|
|
path = ./template;
|
|
description = "Product repo using repo-lib";
|
|
};
|
|
};
|
|
|
|
checks = lib.genAttrs supportedSystems (
|
|
system: projectOutputs.checks.${system} // testChecks.${system}
|
|
);
|
|
};
|
|
}
|