split dev into config and overrides, hook in via impure.nix
This commit is contained in:
6
.envrc
6
.envrc
@@ -47,3 +47,9 @@
|
||||
printf "%s\n" "$now" >.direnv/pull-date
|
||||
direnv allow # cheeky
|
||||
)
|
||||
|
||||
export NIX_PATH_ORIG="${NIX_PATH:-}"
|
||||
|
||||
# pkgs/top-level/impure.nix go brrr
|
||||
export NIXPKGS_CONFIG="$(realpath config.nix)"
|
||||
export NIX_PATH="$NIX_PATH${NIX_PATH:+:}nixpkgs-overlays=$(realpath overlays.nix)"
|
||||
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,5 +1,6 @@
|
||||
*
|
||||
!/justfile
|
||||
!/dev.nix
|
||||
!/config.nix
|
||||
!/overlays.nix
|
||||
!/.gitignore
|
||||
!/.envrc
|
||||
|
||||
6
config.nix
Normal file
6
config.nix
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
allowUnfree = true;
|
||||
# allowInsecure = true;
|
||||
# allowBroken = true;
|
||||
checkMeta = true;
|
||||
}
|
||||
29
justfile
29
justfile
@@ -7,6 +7,11 @@ export invokedir := invocation_directory()
|
||||
export epoch := `date +%s`
|
||||
export GUM_FILTER_HEIGHT := "15"
|
||||
export GIT := `command -v git-wait >/dev/null && echo "git-wait" || echo "git"`
|
||||
# will trigger a direnv reload when we enter $SHELL
|
||||
export DIRENV_WATCHES := ""
|
||||
# please no surprises for now
|
||||
export NIXPKGS_CONFIG := ""
|
||||
export NIX_PATH := `echo "${NIX_PATH_ORIG:-"${NIX_PATH:-}"}"`
|
||||
|
||||
# required programs: git nix nom gum fzf tee nix-update
|
||||
|
||||
@@ -730,27 +735,3 @@ _packages_json:
|
||||
@_fmt:
|
||||
just --unstable --fmt
|
||||
#sd "\n+(@_[a-zA-Z_-]+:)" "\n" justfile
|
||||
|
||||
#sync ./dev.nix
|
||||
dev:
|
||||
#!/usr/bin/env -S bash -euo pipefail
|
||||
[[ -f "$invokedir"/flake.nix
|
||||
&& -f "$invokedir"/default.nix
|
||||
&& -e "$invokedir"/.git
|
||||
&& -f "$invokedir"/pkgs/top-level/impure.nix
|
||||
]] || ! echo >&2 "ERROR: not in nixpkgs root"
|
||||
|
||||
# local .gitignore for dev.nix
|
||||
if ! grep -qxF "/dev.nix" master/.git/info/exclude; then
|
||||
echo "/dev.nix" >> master/.git/info/exclude
|
||||
fi
|
||||
|
||||
if [[ ! -f "$invokedir"/dev.nix ]]; then
|
||||
(set -x; cp dev.nix "$invokedir"/dev.nix)
|
||||
elif [[ dev.nix -nt "$invokedir"/dev.nix ]]; then
|
||||
(set -x; cp -f dev.nix "$invokedir"/dev.nix)
|
||||
elif diff -qs dev.nix "$invokedir"/default.nix; then
|
||||
:
|
||||
else
|
||||
! echo >&2 "dunnolol"
|
||||
fi
|
||||
|
||||
@@ -1,30 +1,9 @@
|
||||
#!/usr/bin/env -S nix-instantiate --parse
|
||||
{ ... }@cliArgs:
|
||||
let
|
||||
lib = import ./lib;
|
||||
lib = import ./master/lib;
|
||||
# merge = sets: lib.foldl' lib.recursiveUpdate {} sets;
|
||||
apply = val: f: f val;
|
||||
appendIfMissing = list: val: if builtins.elem val list then list else list ++ [ val ];
|
||||
|
||||
mkPkgs =
|
||||
args:
|
||||
import ./. (
|
||||
apply (lib.recursiveUpdate cliArgs args) (prev: rec {
|
||||
# system = ;
|
||||
# crossSystem = ;
|
||||
config.allowUnfree = true;
|
||||
# config.allowInsecure = true;
|
||||
# config.allowBroken = true;
|
||||
config.checkMeta = true;
|
||||
overlays = prev.overlays or [ ] ++ [
|
||||
overlay.withShellCheck
|
||||
overlay.withDebug
|
||||
overlay.withTwostagePythonBuildPassthru
|
||||
# overlay.withPytestCheckHooks
|
||||
];
|
||||
})
|
||||
);
|
||||
|
||||
mkDerivationOverlay =
|
||||
let
|
||||
# from pkgs/stdenv/adapters.nix
|
||||
@@ -48,7 +27,9 @@ let
|
||||
|
||||
# TODO: need we override any other stdenvs?
|
||||
mkStdenvOverlay = f: final: prev: {
|
||||
stdenv = (prev.addAttrsToDerivation { } prev.stdenv).override (f final prev prev.stdenv.mkDerivation);
|
||||
stdenv = (prev.addAttrsToDerivation { } prev.stdenv).override (
|
||||
f final prev prev.stdenv.mkDerivation
|
||||
);
|
||||
# stdenvNoCC = (prev.addAttrsToDerivation { } prev.stdenvNoCC).override (f final prev prev.stdenvNoCC.mkDerivation);
|
||||
# stdenvLLVM = (prev.addAttrsToDerivation { } prev.stdenvLLVM).override (f final prev prev.stdenvLLVM.mkDerivation);
|
||||
};
|
||||
@@ -67,7 +48,7 @@ let
|
||||
let
|
||||
stdenv' = stdenv // {
|
||||
# mkDerivation = stdenv.mkDerivationFromStdenv stdenv;
|
||||
mkDerivation = prevMkDerivation;
|
||||
mkDerivation = prevMkDerivation; # HACK
|
||||
};
|
||||
in
|
||||
f final prev stdenv' finalAttrs prevAttrs
|
||||
@@ -78,16 +59,16 @@ let
|
||||
|
||||
# none of these overlays should cause a mass-rebuild, they should only add optional functionality
|
||||
|
||||
# TODO: cccache and sccache
|
||||
# TODO: fetchurl.passthru.unpacked
|
||||
# TODO: mkDerivation.passthru.withOil: add <package>.withOil which run build with osh, https://oils.pub/osh.html#2-you-get-precise-error-messages
|
||||
# TODO: mkDerivation.passthru.withGDB: add <package>.withGDB which runs the full build with gdb
|
||||
# TODO: mkDerivation.passthru.withDebInfo: like overlay.withDebug but with cmakeBuildType = "RelWithDebInfo" mode
|
||||
|
||||
# usage: nix-build ./dev.nix -A <package>.withDebug
|
||||
overlay.withDebug = mkDerivationOverlay (
|
||||
overlays.withDebug = mkDerivationOverlay (
|
||||
final: prev: prevStdenv: finalAttrs: prevAttrs: {
|
||||
passthru = {
|
||||
# withDebug = prevStdenv;
|
||||
withDebug = prevStdenv.mkDerivation (
|
||||
prevAttrs
|
||||
// {
|
||||
@@ -102,7 +83,7 @@ let
|
||||
);
|
||||
|
||||
# usage: nix-build ./dev.nix -A <package>.shellcheck
|
||||
overlay.withShellCheck = mkDerivationOverlay (
|
||||
overlays.withShellCheck = mkDerivationOverlay (
|
||||
final: prev: prevStdenv: finalAttrs: prevAttrs:
|
||||
let
|
||||
snippets = lib.pipe finalAttrs [
|
||||
@@ -159,23 +140,24 @@ let
|
||||
|
||||
# very hacky, not guaranteed to work, but may save a lot of .whl rebuilds
|
||||
# usage: nix-build ./dev.nix -A python3Packages.<package>.twostage
|
||||
overlay.withTwostagePythonBuildPassthru = final: prev: {
|
||||
# usage: nix-build ./dev.nix -A python3Packages.<package>.twostage.first
|
||||
overlays.withTwostagePythonBuildPassthru = final: prev: {
|
||||
pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [
|
||||
(
|
||||
pythonFinal: pythonPrev:
|
||||
let
|
||||
mkTwostage =
|
||||
builder:
|
||||
buildPythonPackage:
|
||||
(
|
||||
args:
|
||||
builder (
|
||||
buildPythonPackage (
|
||||
args
|
||||
// {
|
||||
passthru = {
|
||||
twostage =
|
||||
let
|
||||
# TODO: assert "dist" in finalPackage.outputs?
|
||||
first = builder (
|
||||
first = buildPythonPackage (
|
||||
args
|
||||
// {
|
||||
name = "${args.name or "${args.pname}-${args.version}"}-wheels";
|
||||
@@ -210,7 +192,7 @@ let
|
||||
postInstallCheck = null;
|
||||
}
|
||||
);
|
||||
second = builder (
|
||||
second = buildPythonPackage (
|
||||
args
|
||||
// {
|
||||
buildPhase = ''
|
||||
@@ -240,7 +222,7 @@ let
|
||||
};
|
||||
|
||||
# usage: nativeBuildInputs = [ pytestCheckHookWithGdb ];
|
||||
overlay.withPytestCheckHooks = final: prev: {
|
||||
overlays.withPytestCheckHooks = final: prev: {
|
||||
pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [
|
||||
(pythonFinal: pythonPrev: {
|
||||
pytestCheckHookWithGdb = pythonFinal.pytestCheckHook.override (old: {
|
||||
@@ -294,19 +276,39 @@ let
|
||||
];
|
||||
};
|
||||
|
||||
overlays.toplevelCudaRocmPkgs =
|
||||
final: prev:
|
||||
let
|
||||
mkPkgs =
|
||||
{
|
||||
config ? { },
|
||||
# overlays ? [ ],
|
||||
}:
|
||||
import prev.path {
|
||||
# if we don't specify overlays then impure.nix will do its thing
|
||||
# overlays = prev.overlays + overlays;
|
||||
config = prev.config // config;
|
||||
};
|
||||
in
|
||||
{
|
||||
pkgsCuda = mkPkgs { config.cudaSupport = true; };
|
||||
pkgsRocm = mkPkgs { config.rocmSupport = true; };
|
||||
# pkgsDarwin?
|
||||
# pkgsLinux?
|
||||
# pkgsFreeBSD?
|
||||
# pkgsNetBSD?
|
||||
# pkgsOpenBSD?
|
||||
# pkgsWindows?
|
||||
};
|
||||
|
||||
in
|
||||
(mkPkgs { })
|
||||
// {
|
||||
pkgsCuda = mkPkgs {
|
||||
config.enableCuda = true;
|
||||
};
|
||||
pkgsRocm = mkPkgs {
|
||||
config.enableRocm = true;
|
||||
};
|
||||
# pkgsDarwin
|
||||
# pkgsLinux
|
||||
# pkgsFreeBSD
|
||||
# pkgsNetBSD
|
||||
# pkgsOpenBSD
|
||||
# pkgsWindows
|
||||
}
|
||||
[
|
||||
overlays.withShellCheck
|
||||
overlays.withDebug
|
||||
overlays.withInvalidateFetcherByDrvHash
|
||||
overlays.withTwostagePythonBuildPassthru
|
||||
overlays.withPytestCheckHooks
|
||||
overlays.toplevelCudaRocmPkgs
|
||||
# WIP:
|
||||
# overlays.withCudaOrRocm
|
||||
]
|
||||
Reference in New Issue
Block a user