dream2nix/flake.nix

168 lines
4.2 KiB
Nix
Raw Normal View History

{
2022-02-22 11:00:32 +03:00
description = "A framework for 2nix tools";
nixConfig = {
extra-trusted-public-keys = "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=";
extra-substituters = "https://nix-community.cachix.org";
};
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
2023-02-18 22:06:01 +03:00
flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
flake-compat.url = "github:edolstra/flake-compat";
flake-compat.flake = false;
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs";
nix-unit.url = "github:adisbladis/nix-unit";
nix-unit.inputs.nixpkgs.follows = "nixpkgs";
nix-unit.inputs.flake-parts.follows = "flake-parts";
devshell = {
url = "github:numtide/devshell";
flake = false;
};
};
outputs = {
self,
devshell,
flake-parts,
nixpkgs,
pre-commit-hooks,
...
} @ inp: let
2023-07-19 15:33:11 +03:00
l = nixpkgs.lib // builtins;
inputs = inp;
perSystem = {
config,
pkgs,
system,
inputs',
...
2023-07-19 15:33:11 +03:00
}: {
apps = {
# passes through extra flags to treefmt
format.type = "app";
format.program = let
path = l.makeBinPath [
pkgs.alejandra
pkgs.python3.pkgs.black
];
in
l.toString
(pkgs.writeScript "format" ''
export PATH="${path}"
${pkgs.treefmt}/bin/treefmt --clear-cache "$@"
'');
};
2023-07-19 15:33:11 +03:00
# a dev shell for working on dream2nix
# use via 'nix develop . -c $SHELL'
devShells = let
makeDevshell = import "${inp.devshell}/modules" pkgs;
mkShell = config:
(makeDevshell {
configuration = {
inherit config;
imports = [];
};
2023-07-19 15:33:11 +03:00
})
.shell;
in rec {
default = dream2nix-shell;
dream2nix-shell = mkShell {
devshell.name = "dream2nix-devshell";
2023-09-20 23:03:03 +03:00
packages =
[
pkgs.alejandra
pkgs.mdbook
(pkgs.python3.withPackages (ps: [
pkgs.python3.pkgs.black
]))
]
++ (l.optionals pkgs.stdenv.isLinux [
inputs'.nix-unit.packages.nix-unit
]);
2023-07-19 15:33:11 +03:00
commands =
[
{
package = pkgs.treefmt;
category = "formatting";
}
]
# using linux is highly recommended as cntr is amazing for debugging builds
++ l.optional pkgs.stdenv.isLinux {
package = pkgs.cntr;
category = "debugging";
};
devshell.startup = {
preCommitHooks.text = self.checks.${system}.pre-commit-check.shellHook;
dream2nixEnv.text = ''
export NIX_PATH=nixpkgs=${nixpkgs}
'';
};
};
2023-07-19 15:33:11 +03:00
};
2023-07-19 15:33:11 +03:00
checks = {
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
treefmt = {
enable = true;
name = "treefmt";
pass_filenames = false;
entry = l.toString (pkgs.writeScript "treefmt" ''
#!${pkgs.bash}/bin/bash
2023-07-19 15:57:59 +03:00
export PATH="$PATH:${l.makeBinPath [
pkgs.alejandra
pkgs.python3.pkgs.black
]}"
2023-07-19 15:33:11 +03:00
${pkgs.treefmt}/bin/treefmt --clear-cache --fail-on-change
'');
};
};
};
};
2023-07-19 15:33:11 +03:00
packages = {
docs =
pkgs.runCommand
"dream2nix-docs"
{nativeBuildInputs = [pkgs.bash pkgs.mdbook];}
''
bash -c "
errors=$(mdbook build -d $out ${./.}/docs |& grep ERROR)
if [ \"$errors\" ]; then
exit 1
fi
"
'';
};
};
in
2023-02-18 22:06:01 +03:00
flake-parts.lib.mkFlake {inherit inputs;} {
imports = [
2023-07-19 16:48:14 +03:00
./modules/flake-parts/all-modules.nix
./pkgs/fetchPipMetadata/flake-module.nix
];
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
2023-07-19 15:33:11 +03:00
inherit perSystem;
};
}