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
|
|
|
|
|
|
|
# required for builder go/gomod2nix
|
|
|
|
gomod2nix = { url = "github:tweag/gomod2nix"; flake = false; };
|
|
|
|
|
2021-10-20 12:39:11 +03:00
|
|
|
# required for translator pip
|
|
|
|
mach-nix = { url = "mach-nix"; flake = false; };
|
|
|
|
|
2021-10-07 07:50:40 +03:00
|
|
|
# required for builder nodejs/node2nix
|
2021-09-20 22:52:31 +03:00
|
|
|
node2nix = { url = "github:svanderburg/node2nix"; flake = false; };
|
2021-11-06 07:38:04 +03:00
|
|
|
|
|
|
|
# required for utils.satisfiesSemver
|
|
|
|
poetry2nix = { url = "github:nix-community/poetry2nix/1.21.0"; flake = false; };
|
2021-09-10 00:42:56 +03:00
|
|
|
};
|
|
|
|
|
2021-11-06 07:38:04 +03:00
|
|
|
outputs = {
|
|
|
|
self,
|
2021-11-11 11:11:17 +03:00
|
|
|
gomod2nix,
|
2021-11-06 07:38:04 +03:00
|
|
|
mach-nix,
|
|
|
|
nixpkgs,
|
|
|
|
node2nix,
|
|
|
|
poetry2nix,
|
|
|
|
}@inp:
|
2021-09-10 00:42:56 +03:00
|
|
|
let
|
|
|
|
|
2021-10-28 17:20:20 +03:00
|
|
|
b = builtins;
|
|
|
|
|
2021-09-14 05:00:29 +03:00
|
|
|
lib = nixpkgs.lib;
|
2021-09-10 00:42:56 +03:00
|
|
|
|
2022-02-23 10:59:42 +03:00
|
|
|
# dream2nix lib (system independent utils)
|
|
|
|
dlib = import ./src/lib { inherit lib; };
|
|
|
|
|
2022-01-30 00:45:36 +03:00
|
|
|
supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" ];
|
2021-09-10 00:42:56 +03:00
|
|
|
|
2021-10-03 11:14:27 +03:00
|
|
|
forAllSystems = f: lib.genAttrs supportedSystems (system:
|
|
|
|
f system (import nixpkgs { inherit system; overlays = [ self.overlay ]; })
|
|
|
|
);
|
2021-09-10 00:42:56 +03:00
|
|
|
|
2021-10-28 17:20:20 +03:00
|
|
|
# To use dream2nix in non-flake + non-IFD enabled repos, the source code of dream2nix
|
2021-10-29 15:49:38 +03:00
|
|
|
# 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"
|
|
|
|
];
|
2021-11-06 07:38:04 +03:00
|
|
|
poetry2nix = [
|
|
|
|
"semver.nix"
|
|
|
|
"LICENSE"
|
2021-10-29 15:49:38 +03:00
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
# create a directory containing the files listed in externalPaths
|
2021-11-06 12:06:34 +03:00
|
|
|
makeExternalDir = import ./src/utils/external-dir.nix;
|
|
|
|
|
|
|
|
externalDirFor = forAllSystems (system: pkgs: makeExternalDir {
|
|
|
|
inherit externalPaths externalSources pkgs;
|
|
|
|
});
|
2021-10-29 15:49:38 +03:00
|
|
|
|
|
|
|
# An interface to access files of external projects.
|
2022-02-22 11:00:32 +03:00
|
|
|
# This implementation accesses the flake inputs directly,
|
2021-10-29 15:49:38 +03:00
|
|
|
# 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}");
|
2021-10-28 17:20:20 +03:00
|
|
|
|
2021-11-05 13:06:14 +03:00
|
|
|
overridesDirs = [ "${./overrides}" ];
|
2021-10-31 06:38:51 +03:00
|
|
|
|
2021-10-28 17:20:20 +03:00
|
|
|
# system specific dream2nix api
|
2021-10-03 11:14:27 +03:00
|
|
|
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
|
|
|
|
|
|
|
in
|
|
|
|
{
|
2021-10-28 17:20:20 +03:00
|
|
|
# overlay with flakes enabled nix
|
|
|
|
# (all of dream2nix cli dependends on nix ^2.4)
|
2021-10-29 15:49:38 +03:00
|
|
|
overlay = final: prev: {
|
|
|
|
nix = prev.writeScriptBin "nix" ''
|
|
|
|
${final.nixUnstable}/bin/nix --option experimental-features "nix-command flakes" "$@"
|
2021-10-03 11:14:27 +03:00
|
|
|
'';
|
|
|
|
};
|
2021-09-10 00:42:56 +03:00
|
|
|
|
2021-10-28 17:20:20 +03:00
|
|
|
# System independent dream2nix api.
|
|
|
|
# Similar to drem2nixFor but will require 'system(s)' or 'pkgs' as an argument.
|
|
|
|
# Produces flake-like output schema.
|
2021-11-02 11:13:34 +03:00
|
|
|
lib = (import ./src/lib.nix {
|
2022-02-23 12:51:47 +03:00
|
|
|
inherit dlib externalPaths externalSources overridesDirs lib;
|
2021-10-28 17:20:20 +03:00
|
|
|
nixpkgsSrc = "${nixpkgs}";
|
2021-11-02 11:13:34 +03:00
|
|
|
})
|
|
|
|
# system specific dream2nix library
|
2022-02-23 10:59:42 +03:00
|
|
|
// (forAllSystems (system: pkgs: dream2nixFor."${system}"));
|
2021-09-16 17:05:31 +03:00
|
|
|
|
2021-10-28 17:20:20 +03:00
|
|
|
# the dream2nix cli to be used with 'nix run dream2nix'
|
2021-11-05 13:06:14 +03:00
|
|
|
defaultApp =
|
|
|
|
forAllSystems (system: pkgs: self.apps."${system}".dream2nix);
|
2021-09-13 20:08:28 +03:00
|
|
|
|
2021-10-28 17:20:20 +03:00
|
|
|
# all apps including cli, install, etc.
|
2021-10-03 11:14:27 +03:00
|
|
|
apps = forAllSystems (system: pkgs:
|
2021-11-17 07:23:31 +03:00
|
|
|
dream2nixFor."${system}".apps.flakeApps // {
|
2021-11-20 07:10:42 +03:00
|
|
|
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;
|
|
|
|
});
|
2021-11-17 07:23:31 +03:00
|
|
|
}
|
2021-09-23 18:01:15 +03:00
|
|
|
);
|
2021-09-16 17:05:31 +03:00
|
|
|
|
2021-10-28 17:20:20 +03:00
|
|
|
# a dev shell for working on dream2nix
|
|
|
|
# use via 'nix develop . -c $SHELL'
|
2021-10-03 11:14:27 +03:00
|
|
|
devShell = forAllSystems (system: pkgs: pkgs.mkShell {
|
2021-10-07 07:50:40 +03:00
|
|
|
|
|
|
|
buildInputs = with pkgs;
|
|
|
|
(with pkgs; [
|
|
|
|
nixUnstable
|
|
|
|
])
|
2021-10-28 17:20:20 +03:00
|
|
|
# using linux is highly recommended as cntr is amazing for debugging builds
|
2021-10-07 07:50:40 +03:00
|
|
|
++ lib.optionals stdenv.isLinux [ cntr ];
|
|
|
|
|
2021-09-16 17:05:31 +03:00
|
|
|
shellHook = ''
|
|
|
|
export NIX_PATH=nixpkgs=${nixpkgs}
|
2021-10-29 15:49:38 +03:00
|
|
|
export d2nExternalDir=${externalDirFor."${system}"}
|
2021-10-22 10:29:38 +03:00
|
|
|
export dream2nixWithExternals=${dream2nixFor."${system}".dream2nixWithExternals}
|
2021-10-26 11:23:35 +03:00
|
|
|
|
2021-12-02 10:15:40 +03:00
|
|
|
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
|
2021-09-16 17:05:31 +03:00
|
|
|
'';
|
|
|
|
});
|
2021-10-29 15:49:38 +03:00
|
|
|
|
2021-11-17 07:23:31 +03:00
|
|
|
checks = forAllSystems (system: pkgs: import ./tests/pure {
|
2021-10-29 15:49:38 +03:00
|
|
|
inherit lib pkgs;
|
|
|
|
dream2nix = dream2nixFor."${system}";
|
|
|
|
});
|
2021-09-10 00:42:56 +03:00
|
|
|
};
|
|
|
|
}
|