dream2nix/flake.nix

155 lines
5.1 KiB
Nix
Raw Normal View History

{
description = "dream2nix: A generic framework for 2nix tools";
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
# required for translator nodejs/pure/package-lock
nix-parsec = { url = "github:nprindle/nix-parsec"; flake = false; };
2021-10-20 12:39:11 +03:00
# required for translator pip
mach-nix = { url = "mach-nix"; flake = false; };
# required for builder nodejs/node2nix
node2nix = { url = "github:svanderburg/node2nix"; flake = false; };
};
outputs = { self, mach-nix, nix-parsec, nixpkgs, node2nix, }@inp:
let
2021-10-28 17:20:20 +03:00
b = builtins;
2021-09-14 05:00:29 +03:00
lib = nixpkgs.lib;
2021-10-05 10:36:57 +03:00
supportedSystems = [ "x86_64-linux" "x86_64-darwin" ];
2021-10-03 11:14:27 +03:00
forAllSystems = f: lib.genAttrs supportedSystems (system:
f system (import nixpkgs { inherit system; overlays = [ self.overlay ]; })
);
2021-10-28 17:20:20 +03:00
# 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"
];
nix-parsec = [
"parsec.nix"
"lexer.nix"
];
};
# create a directory containing the files listed in externalPaths
makeExternalDir = pkgs: pkgs.runCommand "dream2nix-external" {}
(lib.concatStringsSep "\n"
(lib.mapAttrsToList
(inputName: paths:
lib.concatStringsSep "\n"
(lib.forEach
paths
(path: ''
mkdir -p $out/${inputName}/$(dirname ${path})
cp ${inp."${inputName}"}/${path} $out/${inputName}/${path}
'')))
externalPaths));
externalDirFor = forAllSystems (system: makeExternalDir);
# An interface to access files of external projects.
# This implementation aceeses 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}");
2021-10-28 17:20:20 +03:00
2021-10-31 06:38:51 +03:00
overridesDir = "${./overrides}";
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 {
externalDir = externalDirFor."${system}";
2021-10-31 06:38:51 +03:00
inherit externalSources lib overridesDir pkgs;
2021-09-14 05:00:29 +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)
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-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.
lib = (import ./src/lib.nix {
inherit externalSources overridesDir lib;
2021-10-28 17:20:20 +03:00
nixpkgsSrc = "${nixpkgs}";
})
# system specific dream2nix library
// (forAllSystems (system: pkgs:
import ./src {
inherit
externalSources
lib
overridesDir
pkgs
;
}
));
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-10-03 11:14:27 +03:00
defaultApp = forAllSystems (system: pkgs: self.apps."${system}".cli);
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:
lib.mapAttrs (appName: app:
{
type = "app";
2021-10-28 17:20:20 +03:00
program = b.toString app.program;
}
2021-10-05 08:25:39 +03:00
) dream2nixFor."${system}".apps.apps
);
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 {
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
++ lib.optionals stdenv.isLinux [ cntr ];
2021-09-16 17:05:31 +03:00
shellHook = ''
export NIX_PATH=nixpkgs=${nixpkgs}
export d2nExternalDir=${externalDirFor."${system}"}
export dream2nixWithExternals=${dream2nixFor."${system}".dream2nixWithExternals}
2021-10-31 06:38:51 +03:00
export d2nOverridesDir=${./overrides}
echo -e "\nManually execute 'export dream2nixWithExternals={path to your dream2nix checkout}'"
2021-09-16 17:05:31 +03:00
'';
});
checks = forAllSystems (system: pkgs: import ./checks.nix {
inherit lib pkgs;
dream2nix = dream2nixFor."${system}";
});
};
}