Skip to content

Instantly share code, notes, and snippets.

@aveltras
Created January 4, 2020 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aveltras/faaa4f464c69929af0d8a62132e02e01 to your computer and use it in GitHub Desktop.
Save aveltras/faaa4f464c69929af0d8a62132e02e01 to your computer and use it in GitHub Desktop.
nix library
{ lib ? import ./nix/lib.nix { depsPath = ./nix/deps; } }:
let
pkgs = lib.fetchDep "nixpkgs";
shell = pkgs.mkShell {
buildInputs = [
pkgs.haskellPackages.ghc
(lib.addDep pkgs)
];
};
in {
inherit pkgs shell;
}
{ depsPath }:
rec {
githubTarball = {owner, repo, rev, sha256}:
builtins.fetchTarball { url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz"; inherit sha256; };
fetchDep = dep: import (githubTarball (builtins.fromJSON (builtins.readFile (depsPath + "/${dep}.json")))) {};
addDep = nixpkgs: (nixpkgs.writeScriptBin "add-dep" ''
${nixpkgs.nix-prefetch-github}/bin/nix-prefetch-github --no-prefetch $@ > ${depsPath}/$2.json
'');
}
[user@laptop:~/Code/skeleton-nix]$ nix-shell
these derivations will be built:
/nix/store/vyv3iznl81zcqkl68gp133smvi3jmnpz-add-dep.drv
building '/nix/store/vyv3iznl81zcqkl68gp133smvi3jmnpz-add-dep.drv'...
[nix-shell:~/Code/skeleton-nix]$ add-dep nikita-volkov hasql
/nix/store/8c7azl6f1fxgh6g2p8nxmfv2jm8j84m3-add-dep/bin/add-dep: ligne 1: /nix/store/xr9xwwz6b1zqihci28g02qghp3vvwqan-deps/hasql.json: Read-only file system
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment