2021-09-10 00:42:56 +03:00
|
|
|
{
|
2022-02-22 11:00:32 +03:00
|
|
|
description = "A framework for 2nix tools";
|
2021-09-10 00:42:56 +03:00
|
|
|
|
2022-07-12 22:45:29 +03:00
|
|
|
nixConfig = {
|
|
|
|
extra-trusted-public-keys = "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=";
|
|
|
|
extra-substituters = "https://nix-community.cachix.org";
|
|
|
|
};
|
|
|
|
|
2021-09-10 00:42:56 +03:00
|
|
|
inputs = {
|
|
|
|
nixpkgs.url = "nixpkgs/nixos-unstable";
|
2021-11-11 11:11:17 +03:00
|
|
|
|
2022-11-19 07:16:59 +03:00
|
|
|
flake-parts.url = "github:hercules-ci/flake-parts";
|
|
|
|
|
2022-03-07 09:57:22 +03:00
|
|
|
### dev dependencies
|
2022-06-05 20:59:19 +03:00
|
|
|
alejandra.url = "github:kamadorueda/alejandra";
|
2022-03-07 09:57:22 +03:00
|
|
|
alejandra.inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
|
|
|
|
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
|
|
|
|
pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
flake-utils-pre-commit.url = "github:numtide/flake-utils";
|
|
|
|
pre-commit-hooks.inputs.flake-utils.follows = "flake-utils-pre-commit";
|
|
|
|
|
2022-06-05 20:59:19 +03:00
|
|
|
devshell = {
|
|
|
|
url = "github:numtide/devshell";
|
|
|
|
flake = false;
|
|
|
|
};
|
|
|
|
|
2022-03-07 09:57:22 +03:00
|
|
|
### framework dependencies
|
2021-11-11 11:11:17 +03:00
|
|
|
# required for builder go/gomod2nix
|
2022-03-07 13:12:07 +03:00
|
|
|
gomod2nix = {
|
|
|
|
url = "github:tweag/gomod2nix";
|
|
|
|
flake = false;
|
|
|
|
};
|
2021-11-11 11:11:17 +03:00
|
|
|
|
2021-10-20 12:39:11 +03:00
|
|
|
# required for translator pip
|
2022-03-07 13:12:07 +03:00
|
|
|
mach-nix = {
|
|
|
|
url = "mach-nix";
|
|
|
|
flake = false;
|
|
|
|
};
|
2021-10-20 12:39:11 +03:00
|
|
|
|
2021-11-06 07:38:04 +03:00
|
|
|
# required for utils.satisfiesSemver
|
2022-03-07 13:12:07 +03:00
|
|
|
poetry2nix = {
|
|
|
|
url = "github:nix-community/poetry2nix/1.21.0";
|
|
|
|
flake = false;
|
|
|
|
};
|
2022-02-28 07:23:44 +03:00
|
|
|
|
|
|
|
# required for builder rust/crane
|
2022-03-07 13:12:07 +03:00
|
|
|
crane = {
|
|
|
|
url = "github:ipetkov/crane";
|
|
|
|
flake = false;
|
|
|
|
};
|
2022-10-14 19:10:35 +03:00
|
|
|
|
|
|
|
# required for haskell translators
|
|
|
|
all-cabal-json = {
|
|
|
|
url = "github:nix-community/all-cabal-json/hackage";
|
|
|
|
flake = false;
|
|
|
|
};
|
2022-10-13 12:12:04 +03:00
|
|
|
|
|
|
|
ghc-utils = {
|
|
|
|
url = "git+https://gitlab.haskell.org/bgamari/ghc-utils";
|
|
|
|
flake = false;
|
|
|
|
};
|
2021-09-10 00:42:56 +03:00
|
|
|
};
|
|
|
|
|
2021-11-06 07:38:04 +03:00
|
|
|
outputs = {
|
|
|
|
self,
|
2022-03-07 09:57:22 +03:00
|
|
|
alejandra,
|
2022-06-05 20:59:19 +03:00
|
|
|
devshell,
|
2022-11-19 07:16:59 +03:00
|
|
|
flake-parts,
|
2021-11-11 11:11:17 +03:00
|
|
|
gomod2nix,
|
2021-11-06 07:38:04 +03:00
|
|
|
mach-nix,
|
|
|
|
nixpkgs,
|
|
|
|
poetry2nix,
|
2022-03-07 09:57:22 +03:00
|
|
|
pre-commit-hooks,
|
2022-02-28 07:23:44 +03:00
|
|
|
crane,
|
2022-10-14 19:10:35 +03:00
|
|
|
all-cabal-json,
|
2022-10-13 12:12:04 +03:00
|
|
|
ghc-utils,
|
2022-03-07 09:57:22 +03:00
|
|
|
...
|
2022-03-07 13:12:07 +03:00
|
|
|
} @ inp: let
|
|
|
|
b = builtins;
|
|
|
|
l = lib // builtins;
|
|
|
|
|
|
|
|
lib = nixpkgs.lib;
|
|
|
|
|
|
|
|
# To use dream2nix in non-flake + non-IFD enabled repos, the source code of dream2nix
|
|
|
|
# must be installed into these repos (using nix run dream2nix#install).
|
|
|
|
# The problem is, all of dream2nix' dependecies need to be installed as well.
|
|
|
|
# Therefore 'externalPaths' contains all relevant files of external projects
|
|
|
|
# which dream2nix depends on. Exactly these files will be installed.
|
|
|
|
externalPaths = {
|
|
|
|
mach-nix = [
|
|
|
|
"lib/extractor/default.nix"
|
|
|
|
"lib/extractor/distutils.patch"
|
|
|
|
"lib/extractor/setuptools.patch"
|
|
|
|
"LICENSE"
|
|
|
|
];
|
|
|
|
poetry2nix = [
|
|
|
|
"semver.nix"
|
|
|
|
"LICENSE"
|
|
|
|
];
|
|
|
|
crane = [
|
|
|
|
"lib/buildDepsOnly.nix"
|
|
|
|
"lib/buildPackage.nix"
|
|
|
|
"lib/cargoBuild.nix"
|
|
|
|
"lib/cleanCargoToml.nix"
|
|
|
|
"lib/findCargoFiles.nix"
|
|
|
|
"lib/mkCargoDerivation.nix"
|
|
|
|
"lib/mkDummySrc.nix"
|
|
|
|
"lib/writeTOML.nix"
|
2022-09-02 04:44:34 +03:00
|
|
|
"pkgs/cargoHelperFunctions.sh"
|
2022-03-07 13:12:07 +03:00
|
|
|
"pkgs/configureCargoCommonVarsHook.sh"
|
|
|
|
"pkgs/configureCargoVendoredDepsHook.sh"
|
|
|
|
"pkgs/installFromCargoBuildLogHook.sh"
|
|
|
|
"pkgs/inheritCargoArtifactsHook.sh"
|
|
|
|
"pkgs/installCargoArtifactsHook.sh"
|
|
|
|
"LICENSE"
|
|
|
|
];
|
2022-09-20 22:25:09 +03:00
|
|
|
devshell = [
|
|
|
|
"modules/back-compat.nix"
|
|
|
|
"modules/commands.nix"
|
|
|
|
"modules/default.nix"
|
|
|
|
"modules/devshell.nix"
|
|
|
|
"modules/env.nix"
|
|
|
|
"modules/modules.nix"
|
|
|
|
"modules/modules-docs.nix"
|
|
|
|
"nix/ansi.nix"
|
|
|
|
"nix/mkNakedShell.nix"
|
|
|
|
"nix/source.nix"
|
|
|
|
"nix/strOrPackage.nix"
|
|
|
|
"nix/writeDefaultShellScript.nix"
|
|
|
|
"extra/language/c.nix"
|
|
|
|
"LICENSE"
|
|
|
|
];
|
2022-03-07 13:12:07 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
# create a directory containing the files listed in externalPaths
|
|
|
|
makeExternalDir = import ./src/utils/external-dir.nix;
|
|
|
|
|
|
|
|
# An interface to access files of external projects.
|
|
|
|
# This implementation accesses the flake inputs directly,
|
|
|
|
# but if dream2nix is used without flakes, it defaults
|
|
|
|
# to another implementation of that function which
|
|
|
|
# uses the installed external paths instead (see default.nix)
|
|
|
|
externalSources =
|
|
|
|
lib.genAttrs
|
|
|
|
(lib.attrNames externalPaths)
|
|
|
|
(inputName: inp."${inputName}");
|
|
|
|
|
2022-10-15 01:05:42 +03:00
|
|
|
/*
|
|
|
|
Inputs that are not required for building, and therefore not need to be
|
|
|
|
copied alongside a dream2nix installation.
|
|
|
|
*/
|
|
|
|
inputs = inp;
|
|
|
|
|
2022-07-24 18:58:24 +03:00
|
|
|
overridesDirs = [(toString ./overrides)];
|
2022-03-07 13:12:07 +03:00
|
|
|
|
|
|
|
# System independent dream2nix api.
|
|
|
|
# Similar to drem2nixFor but will require 'system(s)' or 'pkgs' as an argument.
|
|
|
|
# Produces flake-like output schema.
|
2022-11-19 07:16:59 +03:00
|
|
|
d2n-lib = import ./src/lib.nix {
|
|
|
|
inherit externalPaths externalSources inputs overridesDirs lib;
|
|
|
|
nixpkgsSrc = "${nixpkgs}";
|
2022-10-28 19:57:59 +03:00
|
|
|
};
|
|
|
|
|
2022-11-19 07:16:59 +03:00
|
|
|
perSystem = {
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
system,
|
|
|
|
...
|
|
|
|
}: let
|
|
|
|
externalDir = makeExternalDir {
|
|
|
|
inherit externalPaths externalSources pkgs;
|
|
|
|
};
|
|
|
|
d2n = import ./src {
|
|
|
|
inherit externalDir externalPaths externalSources inputs lib pkgs;
|
|
|
|
config = {inherit overridesDirs;};
|
|
|
|
};
|
|
|
|
docsCli = pkgs.callPackage ./src/utils/view-docs {
|
|
|
|
dream2nixDocsSrc = "${self}/docs/src";
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
# all apps including cli, install, etc.
|
|
|
|
apps =
|
|
|
|
d2n.framework.flakeApps
|
2022-03-07 13:12:07 +03:00
|
|
|
// {
|
|
|
|
tests-unit.type = "app";
|
|
|
|
tests-unit.program =
|
|
|
|
b.toString
|
2022-11-19 07:16:59 +03:00
|
|
|
(d2n.callPackageDream ./tests/unit {
|
2022-03-07 13:12:07 +03:00
|
|
|
inherit self;
|
|
|
|
});
|
|
|
|
|
2022-08-11 22:27:21 +03:00
|
|
|
tests-integration.type = "app";
|
|
|
|
tests-integration.program =
|
|
|
|
b.toString
|
2022-11-19 07:16:59 +03:00
|
|
|
(d2n.callPackageDream ./tests/integration {
|
2022-08-11 22:27:21 +03:00
|
|
|
inherit self;
|
|
|
|
});
|
|
|
|
|
2022-11-14 17:42:35 +03:00
|
|
|
tests-integration-d2n-flakes.type = "app";
|
|
|
|
tests-integration-d2n-flakes.program =
|
|
|
|
b.toString
|
2022-11-19 07:16:59 +03:00
|
|
|
(d2n.callPackageDream ./tests/integration-d2n-flakes {
|
2022-11-14 17:42:35 +03:00
|
|
|
inherit self;
|
|
|
|
});
|
|
|
|
|
2022-03-27 18:11:32 +03:00
|
|
|
tests-examples.type = "app";
|
|
|
|
tests-examples.program =
|
|
|
|
b.toString
|
2022-11-19 07:16:59 +03:00
|
|
|
(d2n.callPackageDream ./tests/examples {
|
2022-03-27 18:11:32 +03:00
|
|
|
inherit self;
|
|
|
|
});
|
|
|
|
|
2022-03-07 13:12:07 +03:00
|
|
|
tests-all.type = "app";
|
|
|
|
tests-all.program =
|
|
|
|
l.toString
|
2022-11-19 07:16:59 +03:00
|
|
|
(d2n.framework.utils.writePureShellScript
|
2022-03-07 13:12:07 +03:00
|
|
|
[
|
|
|
|
alejandra.defaultPackage.${system}
|
|
|
|
pkgs.coreutils
|
|
|
|
pkgs.gitMinimal
|
|
|
|
pkgs.nix
|
|
|
|
]
|
|
|
|
''
|
2022-03-07 13:26:06 +03:00
|
|
|
echo "check for correct formatting"
|
2022-08-20 19:37:08 +03:00
|
|
|
WORKDIR=$(realpath ./.)
|
|
|
|
cd $TMPDIR
|
2022-03-07 13:26:06 +03:00
|
|
|
cp -r $WORKDIR ./repo
|
|
|
|
cd ./repo
|
2022-11-19 07:16:59 +03:00
|
|
|
${config.apps.format.program} --fail-on-change
|
2022-03-07 13:26:06 +03:00
|
|
|
cd -
|
|
|
|
|
2022-03-07 13:12:07 +03:00
|
|
|
echo "running unit tests"
|
2022-11-19 07:16:59 +03:00
|
|
|
${config.apps.tests-unit.program}
|
2022-03-07 13:12:07 +03:00
|
|
|
|
2022-08-11 22:27:21 +03:00
|
|
|
echo "running integration tests"
|
2022-11-19 07:16:59 +03:00
|
|
|
${config.apps.tests-integration.program}
|
2022-08-11 22:27:21 +03:00
|
|
|
|
2022-03-27 18:11:32 +03:00
|
|
|
echo "checking flakes under ./examples"
|
2022-11-19 07:16:59 +03:00
|
|
|
${config.apps.tests-examples.program}
|
2022-03-27 18:11:32 +03:00
|
|
|
|
2022-03-07 13:12:07 +03:00
|
|
|
echo "running nix flake check"
|
|
|
|
cd $WORKDIR
|
2022-04-04 14:47:02 +03:00
|
|
|
nix flake show >/dev/null
|
2022-03-07 13:12:07 +03:00
|
|
|
nix flake check
|
2022-03-07 09:57:22 +03:00
|
|
|
'');
|
2022-03-07 13:12:07 +03:00
|
|
|
|
|
|
|
# passes through extra flags to treefmt
|
|
|
|
format.type = "app";
|
|
|
|
format.program =
|
|
|
|
l.toString
|
|
|
|
(pkgs.writeScript "format" ''
|
|
|
|
export PATH="${alejandra.defaultPackage.${system}}/bin"
|
2022-03-07 13:47:49 +03:00
|
|
|
${pkgs.treefmt}/bin/treefmt --clear-cache "$@"
|
2022-03-07 13:12:07 +03:00
|
|
|
'');
|
2022-06-13 22:27:05 +03:00
|
|
|
|
|
|
|
docs.type = "app";
|
2022-11-19 07:16:59 +03:00
|
|
|
docs.program = "${docsCli}/bin/d2n-docs";
|
|
|
|
};
|
2022-03-07 13:12:07 +03:00
|
|
|
|
2022-11-19 07:16:59 +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 = [];
|
|
|
|
};
|
|
|
|
})
|
|
|
|
.shell;
|
|
|
|
in rec {
|
|
|
|
default = dream2nix-shell;
|
|
|
|
dream2nix-shell = mkShell {
|
|
|
|
devshell.name = "dream2nix-devshell";
|
|
|
|
|
|
|
|
commands =
|
|
|
|
[
|
|
|
|
{package = pkgs.nix;}
|
|
|
|
{
|
|
|
|
package = pkgs.mdbook;
|
|
|
|
category = "documentation";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
package = docsCli;
|
|
|
|
category = "documentation";
|
|
|
|
help = "CLI for listing and viewing dream2nix documentation";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
package = pkgs.treefmt;
|
|
|
|
category = "formatting";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
package = alejandra.defaultPackage.${system};
|
|
|
|
category = "formatting";
|
|
|
|
}
|
|
|
|
]
|
|
|
|
# using linux is highly recommended as cntr is amazing for debugging builds
|
|
|
|
++ lib.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}
|
|
|
|
export d2nExternalDir=${externalDir}
|
|
|
|
export dream2nixWithExternals=${d2n.dream2nixWithExternals}
|
|
|
|
|
|
|
|
if [ -e ./overrides ]; then
|
|
|
|
export d2nOverridesDir=$(realpath ./overrides)
|
|
|
|
else
|
|
|
|
export d2nOverridesDir=${./overrides}
|
|
|
|
echo -e "\nManually execute 'export d2nOverridesDir={path to your dream2nix overrides dir}'"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -e ../dream2nix ]; then
|
|
|
|
export dream2nixWithExternals=$(realpath ./src)
|
|
|
|
else
|
|
|
|
export dream2nixWithExternals=${./src}
|
|
|
|
echo -e "\nManually execute 'export dream2nixWithExternals={path to your dream2nix checkout}'"
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
};
|
2022-06-05 20:59:19 +03:00
|
|
|
};
|
|
|
|
};
|
2022-11-19 07:16:59 +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
|
|
|
|
export PATH="$PATH:${alejandra.defaultPackage.${system}}/bin"
|
|
|
|
${pkgs.treefmt}/bin/treefmt --clear-cache --fail-on-change
|
|
|
|
'');
|
|
|
|
};
|
|
|
|
cleanup = {
|
|
|
|
enable = true;
|
|
|
|
name = "cleaned";
|
|
|
|
entry = l.toString (pkgs.writeScript "cleaned" ''
|
|
|
|
#!${pkgs.bash}/bin/bash
|
|
|
|
for badFile in $(find ./examples | grep 'flake.lock\|dream2nix-packages'); do
|
|
|
|
rm -rf $badFile
|
|
|
|
git add $badFile || :
|
|
|
|
done
|
|
|
|
'');
|
|
|
|
};
|
|
|
|
is-cleaned = {
|
|
|
|
enable = true;
|
|
|
|
name = "is-cleaned";
|
|
|
|
entry = l.toString (pkgs.writeScript "is-cleaned" ''
|
|
|
|
#!${pkgs.bash}/bin/bash
|
|
|
|
if find ./examples | grep -q 'flake.lock\|dream2nix-packages'; then
|
|
|
|
echo "./examples should not contain any flake.lock files or dream2nix-packages directories" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
'');
|
|
|
|
};
|
2022-06-19 11:20:55 +03:00
|
|
|
};
|
2022-03-07 13:26:06 +03:00
|
|
|
};
|
2022-04-20 17:41:37 +03:00
|
|
|
};
|
2022-11-19 07:16:59 +03:00
|
|
|
packages = {
|
|
|
|
docs =
|
|
|
|
pkgs.runCommand
|
|
|
|
"dream2nix-docs"
|
|
|
|
{nativeBuildInputs = [pkgs.mdbook];}
|
|
|
|
''
|
|
|
|
mdbook build -d $out ${./.}/docs
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2022-04-08 13:59:24 +03:00
|
|
|
|
2022-11-19 07:16:59 +03:00
|
|
|
flake = {
|
|
|
|
lib = d2n-lib;
|
|
|
|
# kept for compat
|
|
|
|
lib2 = d2n-lib;
|
2022-06-13 22:27:05 +03:00
|
|
|
|
2022-11-19 07:16:59 +03:00
|
|
|
flakeModuleBeta = {
|
|
|
|
imports = [./src/modules/flake-parts];
|
|
|
|
dream2nix.lib = d2n-lib;
|
|
|
|
};
|
|
|
|
templates =
|
|
|
|
{
|
|
|
|
default = self.templates.simple;
|
|
|
|
simple = {
|
|
|
|
description = "Simple dream2nix flake";
|
|
|
|
path = ./templates/simple;
|
|
|
|
welcomeText = ''
|
|
|
|
You just created a simple dream2nix package!
|
2022-11-16 11:25:33 +03:00
|
|
|
|
2022-11-19 07:16:59 +03:00
|
|
|
start with typing `nix flake show` to discover the projects attributes.
|
2022-11-16 11:25:33 +03:00
|
|
|
|
2022-11-19 07:16:59 +03:00
|
|
|
commands:
|
2022-11-16 11:25:33 +03:00
|
|
|
|
2022-11-19 07:16:59 +03:00
|
|
|
- `nix develop` <-- enters the devShell
|
|
|
|
- `nix build .#` <-- builds the default package (`.#default`)
|
2022-11-16 11:25:33 +03:00
|
|
|
|
|
|
|
|
2022-11-19 07:16:59 +03:00
|
|
|
Start hacking and -_- have some fun!
|
2022-11-16 11:25:33 +03:00
|
|
|
|
2022-11-19 07:16:59 +03:00
|
|
|
> dont forget to add nix `result` folder to your `.gitignore`
|
2022-11-16 11:25:33 +03:00
|
|
|
|
2022-11-19 07:16:59 +03:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|
|
|
|
// (b.mapAttrs (name: value: {
|
|
|
|
description = "Example: ${name} template";
|
|
|
|
path = ./examples/${name};
|
|
|
|
}) (l.filterAttrs (n: v: v == "directory") (b.readDir ./examples)));
|
|
|
|
};
|
|
|
|
in
|
|
|
|
flake-parts.lib.mkFlake {inherit self;} {
|
|
|
|
systems = [
|
|
|
|
"x86_64-linux"
|
|
|
|
"aarch64-linux"
|
|
|
|
"x86_64-darwin"
|
|
|
|
"aarch64-darwin"
|
|
|
|
];
|
|
|
|
inherit flake perSystem;
|
|
|
|
};
|
2021-09-10 00:42:56 +03:00
|
|
|
}
|