From 7539aabebadd4f9625e789f246e562f1ed5d128d Mon Sep 17 00:00:00 2001 From: Tobias Pflug Date: Mon, 17 May 2021 15:06:02 +0200 Subject: [PATCH] Add a Nix flake Add a basic nix flake that simply exports several packages from the toplevel default.nix --- flake.lock | 131 ++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 53 ++++++++++++++++++++ nix/default.nix | 31 ++++++------ 3 files changed, 200 insertions(+), 15 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000000..aa100064fa3 --- /dev/null +++ b/flake.lock @@ -0,0 +1,131 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1620759905, + "narHash": "sha256-WiyWawrgmyN0EdmiHyG2V+fqReiVi8bM9cRdMaKQOFg=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b543720b25df6ffdfcf9227afafc5b8c1fabfae8", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "rev": "b543720b25df6ffdfcf9227afafc5b8c1fabfae8", + "type": "github" + } + }, + "haskell-nix": { + "inputs": { + "nixpkgs": "nixpkgs", + "nixpkgs-2003": "nixpkgs-2003", + "nixpkgs-2009": "nixpkgs-2009", + "nixpkgs-unstable": "nixpkgs-unstable" + }, + "locked": { + "lastModified": 1618967660, + "narHash": "sha256-twtyuc0nn6W5+I0tqROMXwv6ACBZzzTu27tDrn+RG5k=", + "owner": "input-output-hk", + "repo": "haskell.nix", + "rev": "87084d65a476cc826a0e8c5d281d494254f5bc7a", + "type": "github" + }, + "original": { + "owner": "input-output-hk", + "repo": "haskell.nix", + "rev": "87084d65a476cc826a0e8c5d281d494254f5bc7a", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1608007629, + "narHash": "sha256-lipVFC/a2pzzA5X2ULj64je+fz1JIp2XRrB5qyoizpQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f02bf8ffb9a5ec5e8f6f66f1e5544fd2aa1a0693", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f02bf8ffb9a5ec5e8f6f66f1e5544fd2aa1a0693", + "type": "github" + } + }, + "nixpkgs-2003": { + "locked": { + "lastModified": 1607708579, + "narHash": "sha256-QyADEDydJJPa8n3xawnA82IJAcZHNNm6Pp5DU7exMr4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7f73e46625f508a793700f5110b86f1a53341d6e", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7f73e46625f508a793700f5110b86f1a53341d6e", + "type": "github" + } + }, + "nixpkgs-2009": { + "locked": { + "lastModified": 1608007629, + "narHash": "sha256-lipVFC/a2pzzA5X2ULj64je+fz1JIp2XRrB5qyoizpQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f02bf8ffb9a5ec5e8f6f66f1e5544fd2aa1a0693", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f02bf8ffb9a5ec5e8f6f66f1e5544fd2aa1a0693", + "type": "github" + } + }, + "nixpkgs-unstable": { + "locked": { + "lastModified": 1612284693, + "narHash": "sha256-efzJNF1jvjK3BMl0gZ0ZaUWcFMv0nLb9AHN/++5+u0U=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "410bbd828cdc6156aecd5bc91772ad3a6b1099c7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "410bbd828cdc6156aecd5bc91772ad3a6b1099c7", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1610942247, + "narHash": "sha256-PKo1ATAlC6BmfYSRmX0TVmNoFbrec+A5OKcabGEu2yU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7d71001b796340b219d1bfa8552c81995017544a", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7d71001b796340b219d1bfa8552c81995017544a", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "haskell-nix": "haskell-nix", + "nixpkgs": "nixpkgs_2" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000000..c06bd2c1df5 --- /dev/null +++ b/flake.nix @@ -0,0 +1,53 @@ +{ + description = "Flake for Plutus"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs?rev=7d71001b796340b219d1bfa8552c81995017544a"; + haskell-nix.url = "github:input-output-hk/haskell.nix?rev=87084d65a476cc826a0e8c5d281d494254f5bc7a"; + flake-utils.url = "github:numtide/flake-utils?rev=b543720b25df6ffdfcf9227afafc5b8c1fabfae8"; + }; + + outputs = { self, nixpkgs, haskell-nix, flake-utils, ... }: + (flake-utils.lib.eachSystem [ "x86_64-linux" ] (system: + let + # + # Obtain all niv sources extending it with the 'nixpkgs' flake input + # + sources = + let + sourcesInfo = builtins.fromJSON (builtins.readFile ./nix/sources.json); + fetch = sourceInfo: builtins.fetchTarball { inherit (sourceInfo) url sha256; }; + in + builtins.mapAttrs (name: info: fetch info) sourcesInfo // { inherit nixpkgs; }; + + # + # all packages from nix/default.nix + # + plutusPackages = import ./nix { + inherit system sources; + haskellNixOverlays = [ haskell-nix.overlay ]; + }; + + # + # all packages from ./default.nix + # + topLevel = import ./. { + inherit system; + packages = plutusPackages; + }; + + inherit (plutusPackages) pkgs plutus ownOverlays; + inherit (plutus) haskell iohkNix; + inherit (plutus.lib) buildPursPackage buildNodeModules filterNpm gitignore-nix; + in + rec { + packages = rec { + marlowe-playground-client = topLevel.marlowe-playground.client; + marlowe-playground-server = topLevel.marlowe-playground.server; + plutus-playground-client = topLevel.plutus-playground.client; + plutus-playground-server = topLevel.plutus-playground.server; + marlowe-website = topLevel.marlowe-web; + web-ghc-server = plutus.haskell.project.hsPkgs.web-ghc.components.exes.web-ghc-server; + }; + })); +} diff --git a/nix/default.nix b/nix/default.nix index cb1f0a49048..ff3d40fb575 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -3,30 +3,31 @@ , config ? { } , overlays ? [ ] , sourcesOverride ? { } -, checkMaterialization ? false -, enableHaskellProfiling ? false -}: -let - sources = import ./sources.nix { inherit pkgs; } - // sourcesOverride; - haskellNix = import sources."haskell.nix" { +, sources ? import ./sources.nix { } // sourcesOverride +, haskellNix ? import sources."haskell.nix" { sourcesOverride = { hackage = sources."hackage.nix"; stackage = sources."stackage.nix"; }; - }; - - extraOverlays = - # Haskell.nix (https://github.com/input-output-hk/haskell.nix) - haskellNix.overlays - # our own overlays: - ++ [ + } + # haskell-nix has to be used differently in flakes/no-flakes scenarios: + # - When imported from flakes, 'haskellNix.overlay' needs to be passed here. + # - When imported from default.nix without flakes, default to haskellNix.overlays +, haskellNixOverlays ? haskellNix.overlays +, checkMaterialization ? false +, enableHaskellProfiling ? false +}: +let + ownOverlays = + [ # Modifications to derivations from nixpkgs (import ./overlays/nixpkgs-overrides.nix) # fix r-modules (import ./overlays/r.nix) ]; + extraOverlays = haskellNixOverlays ++ ownOverlays; + pkgs = import sources.nixpkgs { inherit system crossSystem; overlays = extraOverlays ++ overlays; @@ -37,5 +38,5 @@ let in { - inherit pkgs plutus sources; + inherit pkgs plutus sources ownOverlays; }