From 1eb18000cbee44ba807d39589667e47ba549c37c Mon Sep 17 00:00:00 2001 From: Stefan Junker Date: Wed, 30 Oct 2019 21:28:22 +0100 Subject: [PATCH] WIP: use niv for source management --- nix/overlay.nix | 4 +- nix/package-set.nix | 8 ++++ nix/sources.json | 38 +++++++++++++++++++ nix/sources.nix | 89 +++++++++++++++++++++++++++++++++++++++++++++ shell.nix | 7 ++++ 5 files changed, 144 insertions(+), 2 deletions(-) create mode 100644 nix/package-set.nix create mode 100644 nix/sources.json create mode 100644 nix/sources.nix diff --git a/nix/overlay.nix b/nix/overlay.nix index 886dfa8..972fe45 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -2,6 +2,8 @@ self: super: let nixpkgs-master = import {}; + # sources = import ./sources.nix; + # nixpkgs-master = sources.nixpkgs-master; # one application requires php5 nixpkgsWithPhp5 = super.fetchFromGitHub { @@ -23,8 +25,6 @@ in { ''; }; - - podman = nixpkgs-master.podman; conmon = nixpkgs-master.conmon; diff --git a/nix/package-set.nix b/nix/package-set.nix new file mode 100644 index 0000000..0b58b67 --- /dev/null +++ b/nix/package-set.nix @@ -0,0 +1,8 @@ +{ pkgs }: + +with pkgs.lib; +let + self = foldl' + (prev: overlay: prev // (overlay (pkgs // self) (pkgs // prev))) + {} (map import (import ./overlays.nix)); +in self diff --git a/nix/sources.json b/nix/sources.json new file mode 100644 index 0000000..ac0a9be --- /dev/null +++ b/nix/sources.json @@ -0,0 +1,38 @@ +{ + "niv": { + "branch": "master", + "description": "Easy dependency management for Nix projects", + "homepage": "https://github.com/nmattia/niv", + "owner": "nmattia", + "repo": "niv", + "rev": "5e9671a9a87c240b1c6ce981d04ad23ba4291451", + "sha256": "08j7msxkv452pyxnh0sgn6h9930i5mk9mszba49bj5401gzmfb8a", + "type": "tarball", + "url": "https://github.com/nmattia/niv/archive/5e9671a9a87c240b1c6ce981d04ad23ba4291451.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, + "nixpkgs": { + "branch": "nixos-19.03", + "description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to", + "homepage": "https://github.com/NixOS/nixpkgs", + "owner": "NixOS", + "repo": "nixpkgs-channels", + "rev": "7339bd47600f687dac692fea897bbf58c55631c4", + "sha256": "12nxr39pjhd8n0l91wsv1kvzdsa5zhhc5a0hndbi1zyxjdrlqsxa", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs-channels/archive/7339bd47600f687dac692fea897bbf58c55631c4.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, + "nixpkgs-master": { + "branch": "master", + "description": "Nix Packages collection", + "homepage": null, + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "92e653b19b613bba25cdd7367fe039697d70ecdf", + "sha256": "0aiq94nsyxwcal2f7kclb70fggzmw39gkz3l2cs384sv1kw4dmck", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/92e653b19b613bba25cdd7367fe039697d70ecdf.tar.gz", + "url_template": "https://github.com///archive/.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 {} + 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. + ''; + + # 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 ).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))); + + # 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 diff --git a/shell.nix b/shell.nix index ed7bde4..bf1767c 100644 --- a/shell.nix +++ b/shell.nix @@ -4,6 +4,12 @@ let channels-nixos-stable-path = (builtins.fetchTarball https://github.com/NixOS/nixpkgs-channels/archive/7e88992a8c7b2de0bcb89182d8686b27bd93e46a.tar.gz); channels-nixos-stable = import channels-nixos-stable-path { overlays = [ (import ./nix/overlay.nix) ]; }; + niv = (import (channels-nixos-stable.fetchFromGitHub { + owner = "nmattia"; + repo = "niv"; + rev = "5e9671a9a87c240b1c6ce981d04ad23ba4291451"; + sha256 = "08j7msxkv452pyxnh0sgn6h9930i5mk9mszba49bj5401gzmfb8a"; + }) {}).niv; in with channels-nixos-stable; stdenv.mkDerivation { @@ -26,6 +32,7 @@ stdenv.mkDerivation { # testing alacritty + niv ]; # Set Environment Variables -- 2.49.0