From 4fbdc79d080c1354286b0f14f2b0ff3155ca9e40 Mon Sep 17 00:00:00 2001 From: Connor Prussin Date: Sun, 8 Dec 2019 14:37:16 -0800 Subject: [PATCH] Move niv stuff out of nix/* --- default.nix | 2 +- niv-sources.nix | 3 ++ pkgs/dircolors-solarized/default.nix | 2 +- pkgs/notify-send/default.nix | 2 +- pkgs/zoom-frm/default.nix | 2 +- pkgs/zsh-git-prompt/default.nix | 2 +- shell.nix | 18 +++++++--- nix/sources.json => sources.json | 0 nix/sources.nix => sources.nix | 54 ++++++++++++++++------------ 9 files changed, 53 insertions(+), 32 deletions(-) create mode 100644 niv-sources.nix rename nix/sources.json => sources.json (100%) rename nix/sources.nix => sources.nix (72%) diff --git a/default.nix b/default.nix index 2923f340..991e8257 100644 --- a/default.nix +++ b/default.nix @@ -1,4 +1,4 @@ -{ sources ? import ./nix/sources.nix }: +{ sources ? import ./niv-sources.nix }: let pkgs = import sources.nixpkgs {}; diff --git a/niv-sources.nix b/niv-sources.nix new file mode 100644 index 00000000..21a52751 --- /dev/null +++ b/niv-sources.nix @@ -0,0 +1,3 @@ +import ./sources.nix { + sourcesFile = ./sources.json; +} diff --git a/pkgs/dircolors-solarized/default.nix b/pkgs/dircolors-solarized/default.nix index 3f4ec688..b00b9871 100644 --- a/pkgs/dircolors-solarized/default.nix +++ b/pkgs/dircolors-solarized/default.nix @@ -1,7 +1,7 @@ { stdenv }: let - sources = import ../../nix/sources.nix; + sources = import ../../niv-sources.nix; in stdenv.mkDerivation { diff --git a/pkgs/notify-send/default.nix b/pkgs/notify-send/default.nix index f69aa5d8..26943ade 100644 --- a/pkgs/notify-send/default.nix +++ b/pkgs/notify-send/default.nix @@ -1,7 +1,7 @@ { stdenv, lib, makeWrapper, glib }: let - sources = import ../../nix/sources.nix; + sources = import ../../niv-sources.nix; in stdenv.mkDerivation { diff --git a/pkgs/zoom-frm/default.nix b/pkgs/zoom-frm/default.nix index 4392f944..39869617 100644 --- a/pkgs/zoom-frm/default.nix +++ b/pkgs/zoom-frm/default.nix @@ -1,7 +1,7 @@ { epkgs }: let - sources = import ../../nix/sources.nix; + sources = import ../../niv-sources.nix; in epkgs.trivialBuild { diff --git a/pkgs/zsh-git-prompt/default.nix b/pkgs/zsh-git-prompt/default.nix index 0179e9af..be3bec37 100644 --- a/pkgs/zsh-git-prompt/default.nix +++ b/pkgs/zsh-git-prompt/default.nix @@ -1,7 +1,7 @@ { stdenv, makeWrapper, python, git }: let - sources = import ../../nix/sources.nix; + sources = import ../../niv-sources.nix; in stdenv.mkDerivation rec { diff --git a/shell.nix b/shell.nix index 3a64b28f..e4b9f479 100644 --- a/shell.nix +++ b/shell.nix @@ -1,9 +1,19 @@ -{ sources ? import ./nix/sources.nix }: +{ sources ? import ./niv-sources.nix }: let pkgs = import sources.nixpkgs {}; - niv = import sources.niv {}; + nivPkgs = import sources.niv {}; + + niv = pkgs.symlinkJoin { + name = "niv"; + paths = [ nivPkgs.niv ]; + buildInputs = [ pkgs.makeWrapper ]; + postBuild = '' + wrapProgram $out/bin/niv \ + --add-flags "--sources-json ${toString ./sources.json}" + ''; + }; nix-linter = pkgs.callPackage sources.nix-linter {}; @@ -19,7 +29,7 @@ let home-manager = sources.home-manager; }; - files = "$(find . -name '*.nix' -not -path './nix/*')"; + files = "$(find . -name '*.nix' -not -wholename './sources.nix')"; lint = pkgs.writeShellScriptBin "lint" "nix-linter ${files}"; @@ -66,7 +76,7 @@ pkgs.mkShell { buildInputs = [ pkgs.git pkgs.nixpkgs-fmt - niv.niv + niv nix-linter.nix-linter lint format diff --git a/nix/sources.json b/sources.json similarity index 100% rename from nix/sources.json rename to sources.json diff --git a/nix/sources.nix b/sources.nix similarity index 72% rename from nix/sources.nix rename to sources.nix index 4c0351c0..718ea6fe 100644 --- a/nix/sources.nix +++ b/sources.nix @@ -6,13 +6,13 @@ let # The fetchers. fetch_ fetches specs of type . # - fetch_file = spec: + 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 = spec: + fetch_tarball = pkgs: spec: if spec.builtin or true then builtins_fetchTarball { inherit (spec) url sha256; } else @@ -43,27 +43,21 @@ let '' (builtins_fetchurl { inherit (spec) url sha256; }); - # - # The sources to fetch. - # - - sources = builtins.fromJSON (builtins.readFile ./sources.json); - # # Various helpers # # The set of packages used when specs are fetched using non-builtins. - pkgs = + mkPkgs = sources: if hasNixpkgsPath then if hasThisAsNixpkgsPath - then import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {} + then import (builtins_fetchTarball { inherit (mkNixpkgs sources) url sha256; }) {} else import {} else - import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {}; + import (builtins_fetchTarball { inherit (mkNixpkgs sources) url sha256; }) {}; - sources_nixpkgs = + mkNixpkgs = sources: if builtins.hasAttr "nixpkgs" sources then sources.nixpkgs else abort @@ -77,12 +71,12 @@ let (builtins.tryEval ).success && == ./.; # The actual fetching function. - fetch = name: spec: + 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 spec - else if spec.type == "tarball" then fetch_tarball spec + 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 @@ -117,12 +111,26 @@ let 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 + }: rec { + # The sources, i.e. the attribute set of spec name to spec + sources = builtins.fromJSON (builtins.readFile sourcesFile); + # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers + pkgs = mkPkgs sources; + }; in -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 name spec; } -) sources +mkSources (mkConfig {}) // + { __functor = _: settings: mkSources (mkConfig settings); }