diff --git a/examples/hello/flake.lock b/examples/hello/flake.lock index 6104356..5505f5d 100644 --- a/examples/hello/flake.lock +++ b/examples/hello/flake.lock @@ -34,12 +34,14 @@ "inputs": { "flake-utils": "flake-utils", "nedryland": "nedryland", - "nixpkgs": "nixpkgs", + "nixpkgs": [ + "pkgs" + ], "nixpkgs_22_11": "nixpkgs_22_11" }, "locked": { "lastModified": 0, - "narHash": "sha256-NFEuL/D/npkPfeEAwQh8dmaBBNLKjTobUwmKDgh4M2w=", + "narHash": "sha256-O57VX55Q9YeY8awWHDFwhdrblOSpcePg8DErohora1Y=", "path": "../../", "type": "path" }, @@ -57,35 +59,20 @@ ] }, "locked": { - "lastModified": 1675871162, - "narHash": "sha256-2Onmc2zq/FJIG7mB4Vm5G8+6mMEJCArEt+YWHPUXB4c=", + "lastModified": 1699346145, + "narHash": "sha256-jlPDDo/tLb4GjJK4iO7iNtkJA9YUHtRgDKJDf2/IitM=", "owner": "goodbyekansas", "repo": "nedryland", - "rev": "de46d2e7db2eb46cfaeaa9056e7553d665a7d447", + "rev": "1f30728cd66257bd6911de73fbf5630ff97100b9", "type": "github" }, "original": { "owner": "goodbyekansas", - "ref": "8.3.0", + "ref": "9.0.0", "repo": "nedryland", "type": "github" } }, - "nixpkgs": { - "locked": { - "lastModified": 1672580127, - "narHash": "sha256-3lW3xZslREhJogoOkjeZtlBtvFMyxHku7I/9IVehhT8=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "0874168639713f547c05947c76124f78441ea46c", - "type": "github" - }, - "original": { - "id": "nixpkgs", - "ref": "nixos-22.05", - "type": "indirect" - } - }, "nixpkgs_22_11": { "locked": { "lastModified": 1673800717, @@ -103,16 +90,16 @@ }, "pkgs": { "locked": { - "lastModified": 1680122840, - "narHash": "sha256-zCQ/9iFHzCW5JMYkkHMwgK1/1/kTMgCMHq4THPINpAU=", + "lastModified": 1703992652, + "narHash": "sha256-C0o8AUyu8xYgJ36kOxJfXIroy9if/G6aJbNOpA5W0+M=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "a575c243c23e2851b78c00e9fa245232926ec32f", + "rev": "32f63574c85fbc80e4ba1fbb932cde9619bad25e", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixos-22.11", + "ref": "nixos-23.11", "repo": "nixpkgs", "type": "github" } diff --git a/examples/hello/flake.nix b/examples/hello/flake.nix index e3f78d3..73be2a3 100644 --- a/examples/hello/flake.nix +++ b/examples/hello/flake.nix @@ -2,8 +2,11 @@ description = "Example project demonstrating simple components using Nedryglot languages."; inputs = { - pkgs.url = github:NixOS/nixpkgs/nixos-22.11; - nedryglot.url = path:../../; + pkgs.url = github:NixOS/nixpkgs/nixos-23.11; + nedryglot = { + url = path:../../; + inputs.nixpkgs.follows = "pkgs"; + }; nedryland.follows = "nedryglot/nedryland"; }; @@ -12,7 +15,15 @@ # TODO: not necessarily system = "x86_64-linux"; - pkgs' = pkgs.legacyPackages."${system}"; + pkgs' = import pkgs { + inherit system; + config = { + allowUnfreePredicate = pkg: + builtins.elem + (builtins.parseDrvName pkg.name or pkg.pname).name + [ "terraform" ]; + }; + }; project = import ./project.nix { nedryland = nedryland.lib."${system}"; nedryglot = nedryglot.lib."${system}"; diff --git a/examples/overrides/flake.nix b/examples/overrides/flake.nix index 35c048e..94d276b 100644 --- a/examples/overrides/flake.nix +++ b/examples/overrides/flake.nix @@ -2,18 +2,20 @@ description = "Example project demonstrating how to override language configurations."; inputs = { - pkgs.url = github:NixOS/nixpkgs/nixos-22.11; - nedryland.url = github:goodbyekansas/nedryland/move-to-nedryglot; + pkgs.url = github:NixOS/nixpkgs/nixos-23.11; + nedryglot.url = path:../../; + nedryland.follows = "nedryglot/nedryland"; oxalica.url = github:oxalica/rust-overlay; }; - outputs = { pkgs, nedryland, oxalica, ... }: + outputs = { pkgs, nedryglot, nedryland, oxalica, ... }: let # TODO: not necessarily system = "x86_64-linux"; pkgs' = pkgs.legacyPackages."${system}"; project = import ./project.nix { + nedryglot = nedryglot.lib."${system}"; nedryland = nedryland.lib."${system}"; oxalica = oxalica.overlays.default; pkgs = pkgs'; diff --git a/examples/overrides/project.nix b/examples/overrides/project.nix index d62e0a5..c0236ab 100644 --- a/examples/overrides/project.nix +++ b/examples/overrides/project.nix @@ -1,4 +1,4 @@ -{ nedryland, oxalica, pkgs }: +{ nedryland, oxalica, nedryglot, pkgs }: let nedry = nedryland { inherit pkgs; }; in @@ -18,7 +18,7 @@ nedry.mkProject baseExtensions = let - glot = import ../../default.nix { }; + glot = nedryglot; in [ glot.languages diff --git a/flake.lock b/flake.lock index 1c7eda5..38a6e1e 100644 --- a/flake.lock +++ b/flake.lock @@ -54,16 +54,16 @@ }, "nixpkgs": { "locked": { - "lastModified": 1672580127, - "narHash": "sha256-3lW3xZslREhJogoOkjeZtlBtvFMyxHku7I/9IVehhT8=", + "lastModified": 1703992652, + "narHash": "sha256-C0o8AUyu8xYgJ36kOxJfXIroy9if/G6aJbNOpA5W0+M=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "0874168639713f547c05947c76124f78441ea46c", + "rev": "32f63574c85fbc80e4ba1fbb932cde9619bad25e", "type": "github" }, "original": { "id": "nixpkgs", - "ref": "nixos-22.05", + "ref": "nixos-23.11", "type": "indirect" } }, diff --git a/flake.nix b/flake.nix index b3e80c5..4d5aa46 100644 --- a/flake.nix +++ b/flake.nix @@ -5,15 +5,24 @@ url = github:goodbyekansas/nedryland/9.0.0; inputs.nixpkgs.follows = "nixpkgs"; }; + inputs.flake-utils.url = github:numtide/flake-utils; - inputs.nixpkgs.url = "nixpkgs/nixos-22.05"; + inputs.nixpkgs.url = "nixpkgs/nixos-23.11"; inputs.nixpkgs_22_11.url = "nixpkgs/nixos-22.11"; outputs = { nedryland, flake-utils, nixpkgs, nixpkgs_22_11, ... }: flake-utils.lib.eachDefaultSystem (system: let - pkgs = nixpkgs.legacyPackages."${system}"; + pkgs = import nixpkgs { + inherit system; + config = { + allowUnfreePredicate = pkg: + builtins.elem + (builtins.parseDrvName pkg.name or pkg.pname).name + [ "terraform" ]; + }; + }; nedry = nedryland.lib."${system}" { inherit pkgs; }; diff --git a/python/default.nix b/python/default.nix index 6676f94..de1978f 100644 --- a/python/default.nix +++ b/python/default.nix @@ -15,8 +15,8 @@ let outputs = pythonPackage.outputs or [ "out" ] ++ [ "wheel" ]; postInstall = '' ${pythonPackage.postInstall or ""} - mkdir -p "$wheel" - cp dist/*.whl "$wheel" + mkdir -p "${builtins.placeholder "wheel"}" + cp dist/*.whl "${builtins.placeholder "wheel"}" ''; } ); diff --git a/python/hooks/default.nix b/python/hooks/default.nix index 0113c16..db3c95e 100644 --- a/python/hooks/default.nix +++ b/python/hooks/default.nix @@ -157,13 +157,14 @@ let ]; extraArgs = "--rootdir=./"; }; + depsAttr = if lib.versionOlder lib.version "23.05pre-git" then "deps" else "propagatedBuildInputs"; in { check = _: pythonPkgs: makeSetupHook { name = "check-hook"; - deps = with pythonPkgs; [ + "${depsAttr}" = with pythonPkgs; [ findutils (coverageWithConfig coverage) (flake8WithConfig flake8) diff --git a/python/package.nix b/python/package.nix index 931f602..7c2b8b6 100644 --- a/python/package.nix +++ b/python/package.nix @@ -5,7 +5,6 @@ args@{ name , src , srcExclude ? [ ] , preBuild ? "" -, format ? "setuptools" , setuptoolsLibrary ? false , doStandardTests ? true , ... @@ -42,9 +41,6 @@ let } else gitignoreSource args.src; attrs = builtins.removeAttrs args [ "srcExclude" "shellInputs" "targetSetup" "docs" "docsConfig" ]; - hookAndChecks = [ (checkHook src pythonPkgs) ] - ++ (resolveInputs "checkInputs" attrs.checkInputs or [ ]); - # Aside from propagating dependencies, buildPythonPackage also injects # code into and wraps executables with the paths included in this list. @@ -78,20 +74,25 @@ let }); pythonPackageArgs = (attrs // { - inherit version format preBuild doStandardTests pythonVersion propagatedBuildInputs; + inherit version preBuild doStandardTests pythonVersion propagatedBuildInputs; src = if lib.isStorePath src then src else filteredSrc; pname = name; # Don't install dependencies with pip, let nix handle that preInstall = '' pipInstallFlags+=('--no-deps') + ${attrs.preInstall or ""} ''; + nativeCheckInputs = (lib.optional (lib.versionAtLeast lib.version "23.05pre-git") (checkHook src pythonPkgs)) + ++ (resolveInputs "nativeCheckInputs" attrs.nativeCheckInputs or [ ]); + # Dependencies needed for running the checkPhase. These are added to nativeBuildInputs when doCheck = true. # Items listed in tests_require go here. - checkInputs = hookAndChecks + checkInputs = (lib.optional (lib.versionOlder lib.version "23.05pre-git") (checkHook src pythonPkgs)) + ++ (resolveInputs "checkInputs" attrs.checkInputs or [ ]) ++ (builtins.map (input: pythonPkgs."types-${input.pname or input.name}" or null) (builtins.filter lib.isDerivation propagatedBuildInputs)) - ++ (lib.optional (format == "setuptools") pythonPkgs.types-setuptools); + ++ (lib.optional (attrs.format or "" == "setuptools") pythonPkgs.types-setuptools); # Build-time only dependencies. Typically executables as well # as the items listed in setup_requires @@ -102,8 +103,7 @@ let buildInputs = resolveInputs "buildInputs" attrs.buildInputs or [ ]; passthru = { - shellInputs = hookAndChecks - ++ [ pythonPkgs.python-lsp-server pythonPkgs.pylsp-mypy pythonPkgs.pyls-isort targetSetup ] + shellInputs = [ pythonPkgs.python-lsp-server pythonPkgs.pylsp-mypy pythonPkgs.pyls-isort targetSetup ] ++ args.shellInputs or [ ]; inherit pythonPackageArgs; } // attrs.passthru or { }; diff --git a/rust/default.nix b/rust/default.nix index 64586b2..5253318 100644 --- a/rust/default.nix +++ b/rust/default.nix @@ -46,8 +46,7 @@ let { inherit name attrs hostTriple; mkPackage = pkgs.callPackage ./package.nix ({ - inherit base hostTriple buildTriple; - rootCallPackage = callPackage; + inherit base hostTriple buildTriple python3; } // rustToolsetArgs); } // lib.optionalAttrs (output != null) { inherit output; }; diff --git a/rust/package.nix b/rust/package.nix index 8a5f2ce..6422365 100644 --- a/rust/package.nix +++ b/rust/package.nix @@ -3,7 +3,7 @@ , lib , pkgs , removeReferencesTo -, rootCallPackage +, pkgsBuildBuild , symlinkJoin , python3 , hostTriple @@ -23,6 +23,7 @@ attrs@{ name , ... }: let + rootCallPackage = pkgsBuildBuild.callPackage; # "Compiler type" dependencies, buildPlatform = hostPlatform != targetPlatform # host = the platform that the resulting binary will run on (i.e. the host platform of # the produced artifact, not our host platform) @@ -83,8 +84,8 @@ let { name = "rust-setup-hook"; substitutions = { - rustLibSrc = lib.optionalString (rustPlatform.rust.rustc ? src) rustPlatform.rustLibSrc; - addPrefixupHook = lib.optionalString (rustPlatform.rust.rustc ? src) '' + rustLibSrc = lib.optionalString (rustc ? src) rustPlatform.rustLibSrc; + addPrefixupHook = lib.optionalString (rustc ? src) '' preFixupHooks+=(remove_rustlibsrc) ''; }; @@ -94,7 +95,7 @@ in base.mkDerivation ( safeAttrs // { - inherit stdenv propagatedBuildInputs buildInputs runner checkInputs; + inherit stdenv propagatedBuildInputs runner checkInputs buildInputs; shellCommands = { cargo = { script = '' @@ -152,15 +153,26 @@ base.mkDerivation && !(builtins.any (pred: pred path type) srcExclude); nativeBuildInputs = [ + rustc + cargo rustHooks cacert removeReferencesTo ] - ++ (builtins.attrValues rustPlatform.rust) ++ nativeBuildInputs; lintInputs = [ - clippy + # workaround for https://github.com/NixOS/nixpkgs/issues/278508 + (clippy.overrideAttrs + (a: { + pname = "${a.pname}-patched"; + nativeBuildInputs = a.nativeBuildInputs or [ ] ++ [ pkgsBuildBuild.makeWrapper ]; + preFixup = '' + ${a.preFixup or ""} + mv $out/bin/clippy-driver $out/bin/.clippy-driver + makeWrapper $out/bin/.clippy-driver $out/bin/clippy-driver --add-flags "--sysroot ${rustc}" + ''; + })) rustfmt ]; diff --git a/rust/rust-setuphook.sh b/rust/rust-setuphook.sh index c14af62..0a9468c 100644 --- a/rust/rust-setuphook.sh +++ b/rust/rust-setuphook.sh @@ -3,8 +3,10 @@ declare -a CRATEPATH=() setup_cratepath() { shopt -s globstar - for cratepath in $(dirname "$1"/**/Cargo.toml); do - CRATEPATH+=("$cratepath") + shopt -s nullglob + + for cratepath in "$1"/**/Cargo.toml; do + CRATEPATH+=("$(dirname "$cratepath")") done } diff --git a/tests/python.nix b/tests/python.nix index 228b0fc..71bb11e 100644 --- a/tests/python.nix +++ b/tests/python.nix @@ -26,12 +26,13 @@ assert dependency.python.pythonVersion == (builtins.head dependency.python.build # Test that checkInputs are included by default but not if doCheck = false; let + attr = if pkgs.lib.versionOlder pkgs.lib.version "23.05pre-git" then "checkInputs" else "nativeCheckInputs"; withChecks = (python.mkClient { name = "with-checks"; version = "test"; src = ./.; nativeBuildInputs = [ "native-build-input-1" ]; - checkInputs = [ "check-input-1" ]; + "${attr}" = [ "check-input-1" ]; }).python; withoutChecks = (python.mkClient { name = "without-checks"; @@ -39,7 +40,7 @@ let doCheck = false; src = ./.; nativeBuildInputs = [ "native-build-input-1" ]; - checkInputs = [ "check-input-1" ]; + "${attr}" = [ "check-input-1" ]; }).python; in assert builtins.elem "check-input-1" withChecks.nativeBuildInputs; @@ -49,27 +50,34 @@ assert !builtins.elem "check-input-1" withoutChecks.nativeBuildInputs; # Client with python overridden, should have corresponding pythonVersion in the output let clientOverriddenVersion = (python.override { - python = pkgs.python; + python = pkgs.python3; }).mkClient { name = "python-version-default"; version = "ultra"; src = null; }; in -assert clientOverriddenVersion.python.pythonVersion == pkgs.python; +assert clientOverriddenVersion.python.pythonVersion == pkgs.python3; # Multiple python version and dependencies accesses the correct python let - pythonLang = (python.override { - python = pkgs.python310; - pythonVersions = { - # Note that it is not required to include python310 in the set - # since it is the default. You can include it in case you want - # to have a python310 target but it will be the same as the - # `python` target. - inherit (pkgs) python38 python311; + pythons = { + "22.11pre-git" = { + python = pkgs.python310; + pythonVersions = { + inherit (pkgs) python38 python311; + }; }; - }); + default = { + python = pkgs.python311; + pythonVersions = { + inherit (pkgs) python39 python312; + }; + }; + }; + + pythons' = (pythons.${pkgs.lib.version} or pythons.default); + pythonLang = python.override pythons'; lib = pythonLang.mkLibrary { name = "bibblan"; @@ -92,9 +100,11 @@ let in builtins.length pythonDeps == expectedPythonDepsLen && builtins.all (py: py.pythonModule == pythonVersion) pythonDeps; in -assert checker pkgs.python310 clientWithNixpkgDep.python; -assert checker pkgs.python311 clientWithNixpkgDep.python311; -assert checker pkgs.python38 clientWithNixpkgDep.python38; +assert checker pythons'.python clientWithNixpkgDep.python; +# check that all passed in pythonVersions are included in the output +assert builtins.filter + (p: !(builtins.hasAttr p clientWithNixpkgDep)) + (builtins.attrNames pythons'.pythonVersions) == [ ]; # Ensure that we get wheel for setuptools projects but not for custom ones let