From b8c33100286ab307f46d3dfe7adf44008cc59d3e Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Sat, 2 May 2020 15:39:07 -0700 Subject: Auto-overlay niv sources This is somewhat experimental, the idea is automatically set the sources from my niv pinned deps. It seems to work, so I'll keep at it and see if I can improve it as issues come up. --- .envrc | 1 + Biz/Cloud/hardware.nix | 1 - Hero/Prod.nix | 1 - Que/Prod.nix | 1 - default.nix | 2 +- nix/default.nix | 14 ++++++++++++++ nix/haskell-overlay.nix | 26 ++++++++++++++------------ nix/nixpkgs.nix | 12 ------------ nix/repl.nix | 1 + nix/sources-overlay.nix | 16 ++++++++++++++++ nix/wemux.nix | 2 +- 11 files changed, 48 insertions(+), 29 deletions(-) create mode 100644 nix/default.nix delete mode 100644 nix/nixpkgs.nix create mode 100644 nix/repl.nix create mode 100644 nix/sources-overlay.nix diff --git a/.envrc b/.envrc index 9950962..28b8bda 100644 --- a/.envrc +++ b/.envrc @@ -1,4 +1,5 @@ PATH_add $PWD +export NIX_PATH=$PWD/nix export BIZ_ROOT=$PWD export HERO_PORT=3000 export HERO_CLIENT=$BIZ_ROOT/_bild/Hero.Client/static diff --git a/Biz/Cloud/hardware.nix b/Biz/Cloud/hardware.nix index 458fd49..20eab30 100644 --- a/Biz/Cloud/hardware.nix +++ b/Biz/Cloud/hardware.nix @@ -1,6 +1,5 @@ { ... }: { - imports = [ ]; boot.loader.grub.device = "/dev/vda"; fileSystems."/" = { device = "/dev/vda1"; fsType = "ext4"; }; swapDevices = [ diff --git a/Hero/Prod.nix b/Hero/Prod.nix index 7da2f72..d7ab1fe 100644 --- a/Hero/Prod.nix +++ b/Hero/Prod.nix @@ -1,6 +1,5 @@ { config, pkgs, lib, ... }: { - imports = [ ]; boot.loader.grub.device = "/dev/vda"; fileSystems."/" = { device = "/dev/vda1"; fsType = "ext4"; }; networking = { diff --git a/Que/Prod.nix b/Que/Prod.nix index 138f582..23c6f0a 100644 --- a/Que/Prod.nix +++ b/Que/Prod.nix @@ -1,6 +1,5 @@ { config, pkgs, lib, ... }: { - imports = [ ]; boot.loader.grub.device = "/dev/vda"; fileSystems."/" = { device = "/dev/vda1"; fsType = "ext4"; }; swapDevices = [ diff --git a/default.nix b/default.nix index de30805..f274f81 100644 --- a/default.nix +++ b/default.nix @@ -1,5 +1,5 @@ let - nixpkgs = import ./nix/nixpkgs.nix; + nixpkgs = import ./nix; build = import ./nix/build.nix { inherit nixpkgs; }; nixos-mailserver = let ver = "v2.3.0"; in builtins.fetchTarball { url = "https://gitlab.com/simple-nixos-mailserver/nixos-mailserver/-/archive/${ver}/nixos-mailserver-${ver}.tar.gz"; diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 0000000..74917f8 --- /dev/null +++ b/nix/default.nix @@ -0,0 +1,14 @@ +let + sources = import ./sources.nix; + nixpkgs = import sources.nixpkgs { + system = "x86_64-linux"; + overlays = [ + (_: _: { inherit sources; }) + (_: _: { niv = import sources.niv {}; }) + (import ./sources-overlay.nix) + (_: pkgs: pkgs.overridePinnedDeps pkgs.overrideSource) + (import ./haskell-overlay.nix) + (_: pkgs: { wemux = pkgs.callPackage ./wemux.nix {}; }) + ]; + }; +in nixpkgs diff --git a/nix/haskell-overlay.nix b/nix/haskell-overlay.nix index e384b4f..1afea87 100644 --- a/nix/haskell-overlay.nix +++ b/nix/haskell-overlay.nix @@ -1,24 +1,26 @@ -_: nixpkgs: +_: pkgs: +let + cabalBuilder = self: name: self.callCabal2nix name pkgs.sources.${name} {}; +in { - haskell = nixpkgs.haskell // { - packages = nixpkgs.haskell.packages // { - ghc865 = nixpkgs.haskell.packages.ghc865.override (old: { - overrides = with nixpkgs.pkgs.haskell.lib; self: super: { - clay = self.callCabal2nix "clay" nixpkgs.sources.clay {}; - miso = self.callCabal2nix "miso" nixpkgs.sources.miso {}; + haskell = pkgs.haskell // { + packages = pkgs.haskell.packages // { + ghc865 = pkgs.haskell.packages.ghc865.override (old: { + overrides = with pkgs.pkgs.haskell.lib; self: super: + pkgs.overridePinnedDeps (cabalBuilder self) // { wai-middleware-metrics = dontCheck super.wai-middleware-metrics; }; }); - ghcjs = nixpkgs.haskell.packages.ghcjs.override (old: { - overrides = with nixpkgs.haskell.lib; self: super: { + ghcjs = pkgs.haskell.packages.ghcjs.override (old: { + overrides = with pkgs.haskell.lib; self: super: + pkgs.overridePinnedDeps (cabalBuilder self) // { QuickCheck = dontCheck super.QuickCheck; base-compat-batteries = dontCheck super.http-types; - clay = dontCheck (self.callCabal2nix "clay" claySrc {}); + clay = dontCheck super.clay; comonad = dontCheck super.comonad; - jsaddle-warp = dontCheck (self.callCabal2nix "jsaddle-warp" "${nixpkgs.sources.jsaddle}/jsaddle-warp" {}); + jsaddle-warp = dontCheck (self.callCabal2nix "jsaddle-warp" "${pkgs.sources.jsaddle}/jsaddle-warp" {}); http-types = dontCheck super.http-types; - miso = self.callCabal2nix "miso" nixpkgs.sources.miso {}; network-uri= dontCheck super.network-uri; scientific = dontCheck super.scientific; # takes forever servant = dontCheck super.servant; diff --git a/nix/nixpkgs.nix b/nix/nixpkgs.nix deleted file mode 100644 index 864511b..0000000 --- a/nix/nixpkgs.nix +++ /dev/null @@ -1,12 +0,0 @@ -let - sources = import ./sources.nix; - nixpkgs = import sources.nixpkgs { - system = "x86_64-linux"; - overlays = [ - (_: _: { inherit sources; }) - (_: _: { niv = import sources.niv {}; }) - (import ./haskell-overlay.nix) - (_: pkgs: { wemux = pkgs.callPackage ./wemux.nix {}; }) - ]; - }; -in nixpkgs diff --git a/nix/repl.nix b/nix/repl.nix new file mode 100644 index 0000000..94edf3a --- /dev/null +++ b/nix/repl.nix @@ -0,0 +1 @@ +{ nixpkgs = import ./.; } diff --git a/nix/sources-overlay.nix b/nix/sources-overlay.nix new file mode 100644 index 0000000..b19bb34 --- /dev/null +++ b/nix/sources-overlay.nix @@ -0,0 +1,16 @@ +_: pkgs: + +rec { + pinnedDeps = builtins.attrNames + (builtins.removeAttrs pkgs.sources ["__functor"]); + overridePinnedDeps = builder: pkgs.lib.genAttrs pinnedDeps builder; + + # Modifies a derivation with our source and version, keeping old build + # rules. This will fail if build steps have changed, or if no build + # rules are available upstream.. + overrideSource = name: pkgs.${name}.overrideAttrs (old: old // rec { + name = "${name}-${version}"; + version = pkgs.sources.${name}.version or pkgs.sources.${name}.rev; + src = pkgs.sources.${name}; + }); +} diff --git a/nix/wemux.nix b/nix/wemux.nix index 4972815..365853f 100644 --- a/nix/wemux.nix +++ b/nix/wemux.nix @@ -1,7 +1,7 @@ { sources, stdenv }: stdenv.mkDerivation rec { - name = "wemux"; + name = "wemux-${version}"; version = "2020.04.03"; src = sources.wemux; installPhase = '' -- cgit v1.2.3