aboutsummaryrefslogtreecommitdiff
path: root/nix
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-05-07 17:15:13 -0700
committerFuwn <[email protected]>2021-05-07 17:15:13 -0700
commit19ea676d2571e38de767443f5695dd4cedd29a64 (patch)
tree5eb4bd08035b380355006957c73a3199f52e0980 /nix
downloadresume-md-19ea676d2571e38de767443f5695dd4cedd29a64.tar.xz
resume-md-19ea676d2571e38de767443f5695dd4cedd29a64.zip
feat(resume): :star:
Diffstat (limited to 'nix')
-rw-r--r--nix/default.nix7
-rw-r--r--nix/sources.json26
-rw-r--r--nix/sources.nix89
3 files changed, 122 insertions, 0 deletions
diff --git a/nix/default.nix b/nix/default.nix
new file mode 100644
index 0000000..9c3da78
--- /dev/null
+++ b/nix/default.nix
@@ -0,0 +1,7 @@
+{}:
+
+let
+ sources = import ./sources.nix;
+ pkgs = import sources.nixpkgs {};
+in pkgs //
+ { niv = (import sources.niv { inherit pkgs; }).niv; }
diff --git a/nix/sources.json b/nix/sources.json
new file mode 100644
index 0000000..defe6b1
--- /dev/null
+++ b/nix/sources.json
@@ -0,0 +1,26 @@
+{
+ "niv": {
+ "branch": "master",
+ "description": "Easy dependency management for Nix projects",
+ "homepage": "https://github.com/nmattia/niv",
+ "owner": "nmattia",
+ "repo": "niv",
+ "rev": "f73bf8d584148677b01859677a63191c31911eae",
+ "sha256": "0jlmrx633jvqrqlyhlzpvdrnim128gc81q5psz2lpp2af8p8q9qs",
+ "type": "tarball",
+ "url": "https://github.com/nmattia/niv/archive/f73bf8d584148677b01859677a63191c31911eae.tar.gz",
+ "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
+ },
+ "nixpkgs": {
+ "branch": "release-19.03",
+ "description": "Nix Packages collection",
+ "homepage": null,
+ "owner": "NixOS",
+ "repo": "nixpkgs",
+ "rev": "27aaaa5ba6923104a23bae75d323dc975390195e",
+ "sha256": "1fdzc6psj369bi9bybgm9vwl5c7sa4z6k2sdz95ypcpgcg3s12ql",
+ "type": "tarball",
+ "url": "https://github.com/NixOS/nixpkgs/archive/27aaaa5ba6923104a23bae75d323dc975390195e.tar.gz",
+ "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
+ }
+}
diff --git a/nix/sources.nix b/nix/sources.nix
new file mode 100644
index 0000000..7a9a2ae
--- /dev/null
+++ b/nix/sources.nix
@@ -0,0 +1,89 @@
+# This file has been generated by Niv.
+
+# A record, from name to path, of the third-party packages
+with rec
+{
+ pkgs =
+ if hasNixpkgsPath
+ then
+ if hasThisAsNixpkgsPath
+ then import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {}
+ else import <nixpkgs> {}
+ else
+ import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {};
+
+ sources_nixpkgs =
+ if builtins.hasAttr "nixpkgs" sources
+ then sources.nixpkgs
+ else abort
+ ''
+ Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
+ add a package called "nixpkgs" to your sources.json.
+ '';
+
+ # 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;
+
+ # A wrapper around pkgs.fetchzip that has inspectable arguments,
+ # annoyingly this means we have to specify them
+ fetchzip = { url, sha256 }@attrs: pkgs.fetchzip attrs;
+
+ hasNixpkgsPath = (builtins.tryEval <nixpkgs>).success;
+ hasThisAsNixpkgsPath =
+ (builtins.tryEval <nixpkgs>).success && <nixpkgs> == ./.;
+
+ sources = builtins.fromJSON (builtins.readFile ./sources.json);
+
+ mapAttrs = builtins.mapAttrs or
+ (f: set: with builtins;
+ listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)));
+
+ # borrowed from nixpkgs
+ functionArgs = f: f.__functionArgs or (builtins.functionArgs f);
+ callFunctionWith = autoArgs: f: args:
+ let auto = builtins.intersectAttrs (functionArgs f) autoArgs;
+ in f (auto // args);
+
+ getFetcher = spec:
+ let fetcherName =
+ if builtins.hasAttr "type" spec
+ then builtins.getAttr "type" spec
+ else "builtin-tarball";
+ in builtins.getAttr fetcherName {
+ "tarball" = fetchzip;
+ "builtin-tarball" = builtins_fetchTarball;
+ "file" = pkgs.fetchurl;
+ "builtin-url" = builtins_fetchurl;
+ };
+};
+# NOTE: spec must _not_ have an "outPath" attribute
+mapAttrs (_: spec:
+ if builtins.hasAttr "outPath" spec
+ then abort
+ "The values in sources.json should not have an 'outPath' attribute"
+ else
+ if builtins.hasAttr "url" spec && builtins.hasAttr "sha256" spec
+ then
+ spec //
+ { outPath = callFunctionWith spec (getFetcher spec) { }; }
+ else spec
+ ) sources