diff --git a/default.nix b/default.nix index 1c353d67..267e53ac 100644 --- a/default.nix +++ b/default.nix @@ -1,3 +1,5 @@ -{ pkgs ? import { } }: +{ pkgs ? import { } +, pureLib ? import ./pure-lib { inherit (pkgs) lib; } +}: -pkgs.callPackage ./lib { } +pkgs.callPackage ./lib { inherit pureLib; } diff --git a/flake.lock b/flake.lock index 5999137c..756785fd 100644 --- a/flake.lock +++ b/flake.lock @@ -1,6 +1,26 @@ { "nodes": { - "root": {} + "nixpkgs": { + "locked": { + "lastModified": 1724300212, + "narHash": "sha256-x3jl6OWTs+L9C7EtscuWZmGZWI0iSBDafvg3X7JMa1A=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "4de4818c1ffa76d57787af936e8a23648bda6be4", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } }, "root": "root", "version": 7 diff --git a/flake.nix b/flake.nix index 2e93fdfa..f06e5c2a 100644 --- a/flake.nix +++ b/flake.nix @@ -1,16 +1,18 @@ { description = "A Nix library for building cargo projects. Never build twice thanks to incremental artifact caching."; - inputs = { }; + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; nixConfig = { extra-substituters = [ "https://crane.cachix.org" ]; extra-trusted-public-keys = [ "crane.cachix.org-1:8Scfpmn9w+hGdXH/Q9tTLiYAE/2dnJYRJP7kl80GuRk=" ]; }; - outputs = { ... }: + outputs = { nixpkgs, ... }: let + lib = import ./pure-lib { inherit (nixpkgs) lib; }; mkLib = pkgs: import ./default.nix { + pureLib = lib; inherit pkgs; }; nodes = (builtins.fromJSON (builtins.readFile ./test/flake.lock)).nodes; @@ -48,7 +50,7 @@ ]; in { - inherit mkLib; + inherit lib mkLib; overlays.default = _final: _prev: { }; @@ -121,7 +123,6 @@ }; } // eachDefaultSystem (system: let - nixpkgs = inputFromLock "nixpkgs"; pkgs = import nixpkgs { inherit system; }; diff --git a/lib/default.nix b/lib/default.nix index bb805055..a693d691 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,4 +1,5 @@ { lib +, pureLib , stdenv , makeScopeWithSplicing' , splicePackages @@ -40,13 +41,8 @@ let scopeFn = self: let inherit (self) callPackage; - - internalCrateNameFromCargoToml = callPackage ./internalCrateNameFromCargoToml.nix { }; - internalCrateNameForCleanSource = callPackage ./internalCrateNameForCleanSource.nix { - inherit internalCrateNameFromCargoToml; - }; in - { + pureLib // { appendCrateRegistries = input: self.overrideScope (_final: prev: { crateRegistries = prev.crateRegistries // (lib.foldl (a: b: a // b) { } input); }); @@ -65,28 +61,13 @@ let cargoNextest = callPackage ./cargoNextest.nix { }; cargoTarpaulin = callPackage ./cargoTarpaulin.nix { }; cargoTest = callPackage ./cargoTest.nix { }; - cleanCargoSource = callPackage ./cleanCargoSource.nix { - inherit internalCrateNameForCleanSource; - }; - cleanCargoToml = callPackage ./cleanCargoToml.nix { }; configureCargoCommonVarsHook = callPackage ./setupHooks/configureCargoCommonVars.nix { }; configureCargoVendoredDepsHook = callPackage ./setupHooks/configureCargoVendoredDeps.nix { }; craneUtils = callPackage ../pkgs/crane-utils { }; - crateNameFromCargoToml = callPackage ./crateNameFromCargoToml.nix { - inherit internalCrateNameFromCargoToml; - }; - - crateRegistries = self.registryFromDownloadUrl { - dl = "https://static.crates.io/crates"; - indexUrl = "https://github.com/rust-lang/crates.io-index"; - }; - devShell = callPackage ./devShell.nix { }; downloadCargoPackage = callPackage ./downloadCargoPackage.nix { }; downloadCargoPackageFromGit = callPackage ./downloadCargoPackageFromGit.nix { }; - filterCargoSources = callPackage ./filterCargoSources.nix { }; - findCargoFiles = callPackage ./findCargoFiles.nix { }; inheritCargoArtifactsHook = callPackage ./setupHooks/inheritCargoArtifacts.nix { }; installCargoArtifactsHook = callPackage ./setupHooks/installCargoArtifacts.nix { }; installFromCargoBuildLogHook = callPackage ./setupHooks/installFromCargoBuildLog.nix { }; @@ -110,36 +91,26 @@ let lib.warnIf needsSplicing warningMsg (lib.genAttrs attrsForToolchainOverride (_: toolchain)) ); - path = callPackage ./path.nix { - inherit internalCrateNameForCleanSource; - }; - - registryFromDownloadUrl = callPackage ./registryFromDownloadUrl.nix { }; - registryFromGitIndex = callPackage ./registryFromGitIndex.nix { }; - registryFromSparse = callPackage ./registryFromSparse.nix { }; removeReferencesToVendoredSourcesHook = callPackage ./setupHooks/removeReferencesToVendoredSources.nix { }; replaceCargoLockHook = callPackage ./setupHooks/replaceCargoLockHook.nix { }; taploFmt = callPackage ./taploFmt.nix { }; - urlForCargoPackage = callPackage ./urlForCargoPackage.nix { }; vendorCargoDeps = callPackage ./vendorCargoDeps.nix { }; vendorMultipleCargoDeps = callPackage ./vendorMultipleCargoDeps.nix { }; vendorCargoRegistries = callPackage ./vendorCargoRegistries.nix { }; vendorGitDeps = callPackage ./vendorGitDeps.nix { }; writeTOML = callPackage ./writeTOML.nix { }; }; - - craneSpliced = makeScopeWithSplicing' { - f = scopeFn; - otherSplices = { - selfBuildBuild = lib.makeScope pkgsBuildBuild.newScope scopeFn; - selfBuildHost = lib.makeScope pkgsBuildHost.newScope scopeFn; - selfBuildTarget = lib.makeScope pkgsBuildTarget.newScope scopeFn; - selfHostHost = lib.makeScope pkgsHostHost.newScope scopeFn; - selfHostTarget = lib.makeScope pkgsHostTarget.newScope scopeFn; - selfTargetTarget = lib.optionalAttrs (pkgsTargetTarget?newScope) (lib.makeScope pkgsTargetTarget.newScope scopeFn); - }; - keep = self: lib.optionalAttrs (self?cargo) - (lib.genAttrs attrsForToolchainOverride (n: self.${n})); - }; in -lib.warnIf isUnsupported msg (craneSpliced) +makeScopeWithSplicing' { + f = scopeFn; + otherSplices = { + selfBuildBuild = lib.makeScope pkgsBuildBuild.newScope scopeFn; + selfBuildHost = lib.makeScope pkgsBuildHost.newScope scopeFn; + selfBuildTarget = lib.makeScope pkgsBuildTarget.newScope scopeFn; + selfHostHost = lib.makeScope pkgsHostHost.newScope scopeFn; + selfHostTarget = lib.makeScope pkgsHostTarget.newScope scopeFn; + selfTargetTarget = lib.optionalAttrs (pkgsTargetTarget?newScope) (lib.makeScope pkgsTargetTarget.newScope scopeFn); + }; + keep = self: lib.optionalAttrs (self?cargo) + (lib.genAttrs attrsForToolchainOverride (n: self.${n})); +} diff --git a/lib/cleanCargoSource.nix b/pure-lib/cleanCargoSource.nix similarity index 100% rename from lib/cleanCargoSource.nix rename to pure-lib/cleanCargoSource.nix diff --git a/lib/cleanCargoToml.nix b/pure-lib/cleanCargoToml.nix similarity index 100% rename from lib/cleanCargoToml.nix rename to pure-lib/cleanCargoToml.nix diff --git a/lib/crateNameFromCargoToml.nix b/pure-lib/crateNameFromCargoToml.nix similarity index 100% rename from lib/crateNameFromCargoToml.nix rename to pure-lib/crateNameFromCargoToml.nix diff --git a/pure-lib/default.nix b/pure-lib/default.nix new file mode 100644 index 00000000..2e593176 --- /dev/null +++ b/pure-lib/default.nix @@ -0,0 +1,49 @@ +{ lib +}: + +let + minSupported = "24.05"; + current = lib.concatStringsSep "." (lib.lists.sublist 0 2 (lib.splitVersion lib.version)); + isUnsupported = lib.versionOlder current minSupported; + msg = "crane requires at least nixpkgs-${minSupported}, supplied nixpkgs-${current}"; + + pureLib = + let + internalCrateNameFromCargoToml = import ./internalCrateNameFromCargoToml.nix { inherit lib; }; + internalCrateNameForCleanSource = import ./internalCrateNameForCleanSource.nix { + inherit internalCrateNameFromCargoToml; + }; + + crateRegistries = registryFromDownloadUrl { + dl = "https://static.crates.io/crates"; + indexUrl = "https://github.com/rust-lang/crates.io-index"; + }; + + filterCargoSources = import ./filterCargoSources.nix { inherit lib; }; + + registryFromDownloadUrl = import ./registryFromDownloadUrl.nix { inherit lib; }; + in + { + inherit crateRegistries filterCargoSources registryFromDownloadUrl; + + cleanCargoSource = import ./cleanCargoSource.nix { + inherit filterCargoSources internalCrateNameForCleanSource lib; + }; + cleanCargoToml = import ./cleanCargoToml.nix { }; + + crateNameFromCargoToml = import ./crateNameFromCargoToml.nix { + inherit internalCrateNameFromCargoToml lib; + }; + + findCargoFiles = import ./findCargoFiles.nix { inherit lib; }; + + path = import ./path.nix { + inherit internalCrateNameForCleanSource lib; + }; + + registryFromGitIndex = import ./registryFromGitIndex.nix { inherit registryFromDownloadUrl; }; + registryFromSparse = import ./registryFromSparse.nix { inherit registryFromDownloadUrl lib; }; + urlForCargoPackage = import ./urlForCargoPackage.nix { inherit crateRegistries lib; }; + }; +in +lib.warnIf isUnsupported msg pureLib diff --git a/lib/filterCargoSources.nix b/pure-lib/filterCargoSources.nix similarity index 100% rename from lib/filterCargoSources.nix rename to pure-lib/filterCargoSources.nix diff --git a/lib/findCargoFiles.nix b/pure-lib/findCargoFiles.nix similarity index 100% rename from lib/findCargoFiles.nix rename to pure-lib/findCargoFiles.nix diff --git a/lib/internalCrateNameForCleanSource.nix b/pure-lib/internalCrateNameForCleanSource.nix similarity index 100% rename from lib/internalCrateNameForCleanSource.nix rename to pure-lib/internalCrateNameForCleanSource.nix diff --git a/lib/internalCrateNameFromCargoToml.nix b/pure-lib/internalCrateNameFromCargoToml.nix similarity index 100% rename from lib/internalCrateNameFromCargoToml.nix rename to pure-lib/internalCrateNameFromCargoToml.nix diff --git a/lib/path.nix b/pure-lib/path.nix similarity index 100% rename from lib/path.nix rename to pure-lib/path.nix diff --git a/lib/registryFromDownloadUrl.nix b/pure-lib/registryFromDownloadUrl.nix similarity index 100% rename from lib/registryFromDownloadUrl.nix rename to pure-lib/registryFromDownloadUrl.nix diff --git a/lib/registryFromGitIndex.nix b/pure-lib/registryFromGitIndex.nix similarity index 100% rename from lib/registryFromGitIndex.nix rename to pure-lib/registryFromGitIndex.nix diff --git a/lib/registryFromSparse.nix b/pure-lib/registryFromSparse.nix similarity index 100% rename from lib/registryFromSparse.nix rename to pure-lib/registryFromSparse.nix diff --git a/lib/urlForCargoPackage.nix b/pure-lib/urlForCargoPackage.nix similarity index 100% rename from lib/urlForCargoPackage.nix rename to pure-lib/urlForCargoPackage.nix