diff --git a/nix/default.nix b/nix/default.nix index 84552c4d52..fe498d5a56 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -21,28 +21,49 @@ let in if localCommonSrc != "" then localCommonSrc - else - let sources = import ./sources.nix; in sources.common; + else sources.common; + + sources = import sourcesnix { sourcesFile = ./sources.json; inherit pkgs; }; + + sourcesnix = builtins.fetchurl + https://raw.githubusercontent.com/nmattia/niv/506b896788d9705899592a303de95d8819504c55/nix/sources.nix; + + pkgs = import commonSrc { + inherit system crossSystem config; + overlays = [ + ( + self: super: + let + nixFmt = self.lib.nixFmt { root = ../.; }; + in + { + sources = super.sources // sources; + + inherit releaseVersion; + + isMaster = super.isMaster or false; + + # The dfinity-sdk.packages.cargo-security-audit job has this RustSec + # advisory-db as a dependency so we add it here to the package set so + # that job has access to it. + # Hydra injects the latest RustSec-advisory-db, otherwise we piggy + # back on the one defined in sources.json. + RustSec-advisory-db = + if ! isNull RustSec-advisory-db + then RustSec-advisory-db + else self.sources.advisory-db; + + motoko = import self.sources.motoko { system = self.system; }; + dfinity = (import self.sources.dfinity { inherit (self) system; }).dfinity.rs; + napalm = self.callPackage self.sources.napalm { + pkgs = self // { nodejs = self.nodejs-12_x; }; + }; + + inherit (nixFmt) nix-fmt; + nix-fmt-check = nixFmt.check; + } // import ./overlays/dfinity-sdk.nix self super + ) + ] ++ overlays; + }; in -import commonSrc { - inherit system crossSystem config; - overlays = import ./overlays ++ [ - ( - _self: super: - { - inherit - releaseVersion - ; - # The dfinity-sdk.packages.cargo-security-audit job has this RustSec - # advisory-db as a dependency so we add it here to the package set so - # that job has access to it. - # Hydra injects the latest RustSec-advisory-db, otherwise we piggy - # back on the one defined in sources.json. - RustSec-advisory-db = - if ! isNull RustSec-advisory-db - then RustSec-advisory-db - else super.sources.advisory-db; - } - ) - ] ++ overlays; -} +pkgs diff --git a/nix/overlays/default.nix b/nix/overlays/default.nix deleted file mode 100644 index c5bdbd9573..0000000000 --- a/nix/overlays/default.nix +++ /dev/null @@ -1,22 +0,0 @@ -[ - (_self: super: { isMaster = super.isMaster or false; }) - (import ./sources.nix) - ( - self: _: - let - nixFmt = self.lib.nixFmt { root = ../../.; }; - in - # some dependencies - { - motoko = import self.sources.motoko { system = self.system; }; - dfinity = (import self.sources.dfinity { inherit (self) system; }).dfinity.rs; - napalm = self.callPackage self.sources.napalm { - pkgs = self // { nodejs = self.nodejs-12_x; }; - }; - - inherit (nixFmt) nix-fmt; - nix-fmt-check = nixFmt.check; - } - ) - (import ./dfinity-sdk.nix) -] diff --git a/nix/overlays/sources.nix b/nix/overlays/sources.nix deleted file mode 100644 index a0be4f88cb..0000000000 --- a/nix/overlays/sources.nix +++ /dev/null @@ -1,11 +0,0 @@ -# This nixpkgs overlay adds the `sources` attribute to the nixpkgs set which is defined -# as an attribute set of fetched source code managed by `niv`. -# -# Why use an overlay? -# -# Without an overlay derivations that need to reference external source code -# have to use `import ../../../nix/sources.nix` where the path of `../../../` -# depends on where the derivation is defined relative to `/nix/sources.nix`. -# -# With this overlay derivations can just use the `sources` argument from pkgs. -self: super: { sources = super.sources // import ../sources.nix { pkgs = super; }; } diff --git a/nix/sources.nix b/nix/sources.nix deleted file mode 100644 index 6e2bf23180..0000000000 --- a/nix/sources.nix +++ /dev/null @@ -1,138 +0,0 @@ -# This file has been generated by Niv. - -let - - # - # The fetchers. fetch_ fetches specs of type . - # - - fetch_file = pkgs: spec: - if spec.builtin or true then - builtins_fetchurl { inherit (spec) url sha256; } - else - pkgs.fetchurl { inherit (spec) url sha256; }; - - fetch_tarball = pkgs: spec: - if spec.builtin or true then - builtins_fetchTarball { inherit (spec) url sha256; } - else - pkgs.fetchzip { inherit (spec) url sha256; }; - - fetch_git = spec: - builtins.fetchGit { url = spec.repo; inherit (spec) rev ref; }; - - fetch_builtin-tarball = spec: - builtins.trace - '' - WARNING: - The niv type "builtin-tarball" will soon be deprecated. You should - instead use `builtin = true`. - - $ niv modify -a type=tarball -a builtin=true - '' - builtins_fetchTarball { inherit (spec) url sha256; }; - - fetch_builtin-url = spec: - builtins.trace - '' - WARNING: - The niv type "builtin-url" will soon be deprecated. You should - instead use `builtin = true`. - - $ niv modify -a type=file -a builtin=true - '' - (builtins_fetchurl { inherit (spec) url sha256; }); - - # - # Various helpers - # - - # The set of packages used when specs are fetched using non-builtins. - mkPkgs = sources: - if hasNixpkgsPath - then - if hasThisAsNixpkgsPath - then import (builtins_fetchTarball { inherit (mkNixpkgs sources) url sha256; }) {} - else import {} - else - import (builtins_fetchTarball { inherit (mkNixpkgs sources) url sha256; }) {}; - - mkNixpkgs = sources: - if builtins.hasAttr "nixpkgs" sources - then sources.nixpkgs - else abort - '' - Please specify either (through -I or NIX_PATH=nixpkgs=...) or - add a package called "nixpkgs" to your sources.json. - ''; - - hasNixpkgsPath = (builtins.tryEval ).success; - hasThisAsNixpkgsPath = - (builtins.tryEval ).success && == ./.; - - # The actual fetching function. - fetch = pkgs: name: spec: - - if ! builtins.hasAttr "type" spec then - abort "ERROR: niv spec ${name} does not have a 'type' attribute" - else if spec.type == "file" then fetch_file pkgs spec - else if spec.type == "tarball" then fetch_tarball pkgs spec - else if spec.type == "git" then fetch_git spec - else if spec.type == "builtin-tarball" then fetch_builtin-tarball spec - else if spec.type == "builtin-url" then fetch_builtin-url spec - else - abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; - - # Ports of functions for older nix versions - - # a Nix version of mapAttrs if the built-in doesn't exist - mapAttrs = builtins.mapAttrs or ( - f: set: with builtins; - listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) - ); - - # fetchTarball version that is compatible between all the versions of Nix - builtins_fetchTarball = { url, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchTarball; - in - if lessThan nixVersion "1.12" then - fetchTarball { inherit url; } - else - fetchTarball attrs; - - # fetchurl version that is compatible between all the versions of Nix - builtins_fetchurl = { url, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchurl; - in - if lessThan nixVersion "1.12" then - fetchurl { inherit url; } - else - fetchurl attrs; - - # Create the final "sources" from the config - mkSources = config: - mapAttrs ( - name: spec: - if builtins.hasAttr "outPath" spec - then abort - "The values in sources.json should not have an 'outPath' attribute" - else - spec // { outPath = fetch config.pkgs name spec; } - ) config.sources; - - # The "config" used by the fetchers - mkConfig = - { sourcesFile ? ./sources.json - , sources ? builtins.fromJSON (builtins.readFile sourcesFile) - , pkgs ? mkPkgs sources - }: rec { - # The sources, i.e. the attribute set of spec name to spec - inherit sources; - - # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers - inherit pkgs; - }; -in -mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); }