From d45b6e7369ea82e8d9327d51e7d737cb800e5d5e Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sun, 12 May 2019 16:34:40 +0200 Subject: [PATCH] Pin nixpkgs and add CI --- ci.nix | 2 +- nix/default.nix | 9 +++++++ nix/sources.json | 25 ++++++++++++++++++ nix/sources.nix | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ shell.nix | 5 ++++ 5 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 nix/default.nix create mode 100644 nix/sources.json create mode 100644 nix/sources.nix create mode 100644 shell.nix diff --git a/ci.nix b/ci.nix index 0bd4ef0..dfd2bd1 100644 --- a/ci.nix +++ b/ci.nix @@ -1 +1 @@ -import ./tests/default.nix \ No newline at end of file +import ./tests/default.nix { pkgs = import ./nix {}; } diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 0000000..193ac49 --- /dev/null +++ b/nix/default.nix @@ -0,0 +1,9 @@ +{ sources ? import ./sources.nix }: +let + config = {}; + overlays = [(super: self: { + inherit (import sources.niv {}) niv; + })]; + pkgs = import sources.nixpkgs { inherit overlays config; }; +in + pkgs diff --git a/nix/sources.json b/nix/sources.json new file mode 100644 index 0000000..979fb04 --- /dev/null +++ b/nix/sources.json @@ -0,0 +1,25 @@ +{ + "nixpkgs": { + "url": "https://github.com/NixOS/nixpkgs-channels/archive/312a059bef8b29b4db4e73dc02ff441cab7bb26d.tar.gz", + "owner": "NixOS", + "branch": "nixos-19.03", + "url_template": "https://github.com///archive/.tar.gz", + "repo": "nixpkgs-channels", + "type": "tarball", + "sha256": "1j52yvkhw1inp6ilpqy81xv1bbwgwqjn0v9647whampkqgn6dxhk", + "description": "Nixpkgs/NixOS branches that track the Nixpkgs/NixOS channels", + "rev": "312a059bef8b29b4db4e73dc02ff441cab7bb26d" + }, + "niv": { + "homepage": "https://github.com/nmattia/niv", + "url": "https://github.com/nmattia/niv/archive/5d9e3a5f7d51765f0369a4682770ec57d863f19f.tar.gz", + "owner": "nmattia", + "branch": "master", + "url_template": "https://github.com///archive/.tar.gz", + "repo": "niv", + "type": "tarball", + "sha256": "0x7d2rb89h0h7g8sjsgax6ncvf2wwbmxkgvlfi53d00kxj6kfzba", + "description": "Easy dependency management for Nix projects", + "rev": "5d9e3a5f7d51765f0369a4682770ec57d863f19f" + } +} diff --git a/nix/sources.nix b/nix/sources.nix new file mode 100644 index 0000000..dc040f8 --- /dev/null +++ b/nix/sources.nix @@ -0,0 +1,67 @@ +# 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 {} + else + import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {}; + + sources_nixpkgs = + 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. + ''; + + builtins_fetchTarball = + # fetchTarball version that is compatible between all the versions of + # Nix + { url, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchTarball; + in + if lessThan nixVersion "1.12" then + fetchTarball { inherit url; } + else + fetchTarball attrs; + + hasNixpkgsPath = (builtins.tryEval ).success; + hasThisAsNixpkgsPath = + (builtins.tryEval ).success && == ./.; + + 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))); + + getFetcher = spec: + let fetcherName = + if builtins.hasAttr "type" spec + then builtins.getAttr "type" spec + else "tarball"; + in builtins.getAttr fetcherName { + "tarball" = pkgs.fetchzip; + "file" = pkgs.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 = getFetcher spec { inherit (spec) url sha256; } ; } + else spec + ) sources diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..2c174d3 --- /dev/null +++ b/shell.nix @@ -0,0 +1,5 @@ +{ pkgs ? import ./nix {}}: +pkgs.mkShell { + name = "dev-shell"; + buildInputs = [ pkgs.niv ]; +}