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
|
|
|
|
|
|
|
inputs = {
|
|
|
|
nixpkgs.url = "nixpkgs/nixos-unstable";
|
2021-11-11 11:11:17 +03:00
|
|
|
|
2022-03-07 09:57:22 +03:00
|
|
|
### dev dependencies
|
|
|
|
alejandra.url = github:kamadorueda/alejandra;
|
|
|
|
alejandra.inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
|
|
|
|
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
|
|
|
|
pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
# upstream flake-utils dep not supporting `aarch64-darwin` yet
|
|
|
|
flake-utils-pre-commit.url = "github:numtide/flake-utils";
|
|
|
|
pre-commit-hooks.inputs.flake-utils.follows = "flake-utils-pre-commit";
|
|
|
|
|
|
|
|
### 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-10-07 07:50:40 +03:00
|
|
|
# required for builder nodejs/node2nix
|
2022-03-07 13:12:07 +03:00
|
|
|
node2nix = {
|
|
|
|
url = "github:svanderburg/node2nix";
|
|
|
|
flake = false;
|
|
|
|
};
|
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;
|
|
|
|
};
|
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,
|
2021-11-11 11:11:17 +03:00
|
|
|
gomod2nix,
|
2021-11-06 07:38:04 +03:00
|
|
|
mach-nix,
|
|
|
|
nixpkgs,
|
|
|
|
node2nix,
|
|
|
|
poetry2nix,
|
2022-03-07 09:57:22 +03:00
|
|
|
pre-commit-hooks,
|
2022-02-28 07:23:44 +03:00
|
|
|
crane,
|
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;
|
|
|
|
|
|
|
|
# dream2nix lib (system independent utils)
|
|
|
|
dlib = import ./src/lib {inherit lib;};
|
|
|
|
|
|
|
|
supportedSystems = ["x86_64-linux" "x86_64-darwin" "aarch64-darwin"];
|
|
|
|
|
|
|
|
forSystems = systems: f:
|
|
|
|
lib.genAttrs systems
|
|
|
|
(system: f system nixpkgs.legacyPackages.${system});
|
|
|
|
|
|
|
|
forAllSystems = forSystems supportedSystems;
|
|
|
|
|
|
|
|
# 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"
|
|
|
|
];
|
|
|
|
node2nix = [
|
|
|
|
"nix/node-env.nix"
|
|
|
|
"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"
|
|
|
|
"pkgs/configureCargoCommonVarsHook.sh"
|
|
|
|
"pkgs/configureCargoVendoredDepsHook.sh"
|
|
|
|
"pkgs/installFromCargoBuildLogHook.sh"
|
|
|
|
"pkgs/inheritCargoArtifactsHook.sh"
|
|
|
|
"pkgs/installCargoArtifactsHook.sh"
|
|
|
|
"pkgs/remapSourcePathPrefixHook.sh"
|
|
|
|
"LICENSE"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
# create a directory containing the files listed in externalPaths
|
|
|
|
makeExternalDir = import ./src/utils/external-dir.nix;
|
|
|
|
|
|
|
|
externalDirFor = forAllSystems (system: pkgs:
|
|
|
|
makeExternalDir {
|
2021-11-06 12:06:34 +03:00
|
|
|
inherit externalPaths externalSources pkgs;
|
|
|
|
});
|
2021-10-29 15:49:38 +03:00
|
|
|
|
2022-03-07 13:12:07 +03:00
|
|
|
# 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}");
|
|
|
|
|
|
|
|
overridesDirs = ["${./overrides}"];
|
|
|
|
|
|
|
|
# system specific dream2nix api
|
|
|
|
dream2nixFor = forAllSystems (system: pkgs:
|
|
|
|
import ./src rec {
|
2021-10-29 15:49:38 +03:00
|
|
|
externalDir = externalDirFor."${system}";
|
2022-02-23 10:59:42 +03:00
|
|
|
inherit dlib externalPaths externalSources lib pkgs;
|
2021-11-06 12:06:34 +03:00
|
|
|
config = {
|
|
|
|
inherit overridesDirs;
|
|
|
|
};
|
2021-09-14 05:00:29 +03:00
|
|
|
});
|
2021-09-10 00:42:56 +03:00
|
|
|
|
2022-03-07 13:12:07 +03:00
|
|
|
pre-commit-check = forAllSystems (
|
|
|
|
system: pkgs:
|
2022-03-07 09:57:22 +03:00
|
|
|
pre-commit-hooks.lib.${system}.run {
|
|
|
|
src = ./.;
|
|
|
|
hooks = {
|
|
|
|
treefmt = {
|
|
|
|
enable = true;
|
|
|
|
name = "treefmt";
|
|
|
|
pass_filenames = true;
|
|
|
|
entry = l.toString (pkgs.writeScript "treefmt" ''
|
|
|
|
#!${pkgs.bash}/bin/bash
|
|
|
|
export PATH="$PATH:${alejandra.defaultPackage.${system}}/bin"
|
|
|
|
${pkgs.treefmt}/bin/treefmt --fail-on-change "$@"
|
|
|
|
'');
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
2022-03-07 13:12:07 +03:00
|
|
|
);
|
|
|
|
in {
|
|
|
|
# System independent dream2nix api.
|
|
|
|
# Similar to drem2nixFor but will require 'system(s)' or 'pkgs' as an argument.
|
|
|
|
# Produces flake-like output schema.
|
|
|
|
lib =
|
|
|
|
(import ./src/lib.nix {
|
|
|
|
inherit dlib externalPaths externalSources overridesDirs lib;
|
|
|
|
nixpkgsSrc = "${nixpkgs}";
|
|
|
|
})
|
|
|
|
# system specific dream2nix library
|
|
|
|
// (forAllSystems (system: pkgs: dream2nixFor."${system}"));
|
|
|
|
|
|
|
|
# with project discovery enabled
|
|
|
|
lib2 = import ./src/libV2.nix {
|
|
|
|
inherit dlib externalPaths externalSources overridesDirs lib;
|
|
|
|
nixpkgsSrc = "${nixpkgs}";
|
|
|
|
};
|
|
|
|
|
|
|
|
# the dream2nix cli to be used with 'nix run dream2nix'
|
|
|
|
defaultApp =
|
|
|
|
forAllSystems (system: pkgs: self.apps."${system}".dream2nix);
|
|
|
|
|
|
|
|
# all apps including cli, install, etc.
|
|
|
|
apps = forAllSystems (
|
|
|
|
system: pkgs:
|
|
|
|
dream2nixFor."${system}".apps.flakeApps
|
|
|
|
// {
|
|
|
|
tests-impure.type = "app";
|
|
|
|
tests-impure.program =
|
|
|
|
b.toString
|
|
|
|
(dream2nixFor."${system}".callPackageDream ./tests/impure {});
|
|
|
|
|
|
|
|
tests-unit.type = "app";
|
|
|
|
tests-unit.program =
|
|
|
|
b.toString
|
|
|
|
(dream2nixFor."${system}".callPackageDream ./tests/unit {
|
|
|
|
inherit self;
|
|
|
|
});
|
|
|
|
|
|
|
|
tests-all.type = "app";
|
|
|
|
tests-all.program =
|
|
|
|
l.toString
|
|
|
|
(dream2nixFor.${system}.utils.writePureShellScript
|
|
|
|
[
|
|
|
|
alejandra.defaultPackage.${system}
|
|
|
|
pkgs.coreutils
|
|
|
|
pkgs.gitMinimal
|
|
|
|
pkgs.nix
|
|
|
|
]
|
|
|
|
''
|
2022-03-07 13:26:06 +03:00
|
|
|
echo "check for correct formatting"
|
|
|
|
cp -r $WORKDIR ./repo
|
|
|
|
cd ./repo
|
|
|
|
${self.apps.${system}.format.program} --fail-on-change
|
|
|
|
cd -
|
|
|
|
|
2022-03-07 13:12:07 +03:00
|
|
|
echo "running unit tests"
|
|
|
|
${self.apps.${system}.tests-unit.program}
|
|
|
|
|
|
|
|
echo "running impure CLI tests"
|
|
|
|
${self.apps.${system}.tests-impure.program}
|
|
|
|
|
|
|
|
echo "running nix flake check"
|
|
|
|
cd $WORKDIR
|
|
|
|
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
|
|
|
'');
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
# a dev shell for working on dream2nix
|
|
|
|
# use via 'nix develop . -c $SHELL'
|
|
|
|
devShell = forAllSystems (system: pkgs:
|
|
|
|
pkgs.mkShell {
|
|
|
|
buildInputs =
|
|
|
|
(with pkgs; [
|
|
|
|
nix
|
|
|
|
treefmt
|
|
|
|
])
|
|
|
|
++ [
|
|
|
|
alejandra.defaultPackage."${system}"
|
|
|
|
]
|
|
|
|
# using linux is highly recommended as cntr is amazing for debugging builds
|
|
|
|
++ lib.optionals pkgs.stdenv.isLinux [pkgs.cntr];
|
|
|
|
|
|
|
|
shellHook =
|
2022-03-07 13:47:49 +03:00
|
|
|
# TODO: pre-commit shellHook disabled until this is solved:
|
|
|
|
# https://github.com/cachix/pre-commit-hooks.nix/issues/140
|
|
|
|
# self.checks.${system}.pre-commit-check.shellHook
|
|
|
|
''
|
2022-03-07 13:12:07 +03:00
|
|
|
export NIX_PATH=nixpkgs=${nixpkgs}
|
|
|
|
export d2nExternalDir=${externalDirFor."${system}"}
|
|
|
|
export dream2nixWithExternals=${dream2nixFor."${system}".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
|
|
|
|
'';
|
|
|
|
});
|
|
|
|
|
|
|
|
checks =
|
|
|
|
l.recursiveUpdate
|
|
|
|
(forAllSystems (system: pkgs: (import ./tests/pure {
|
|
|
|
inherit lib pkgs;
|
|
|
|
dream2nix = dream2nixFor."${system}";
|
|
|
|
})))
|
2022-03-07 13:26:06 +03:00
|
|
|
(forAllSystems (system: pkgs: {
|
|
|
|
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 --fail-on-change
|
|
|
|
'');
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}));
|
2022-03-07 13:12:07 +03:00
|
|
|
};
|
2021-09-10 00:42:56 +03:00
|
|
|
}
|