From 35f0ade5ea77d17544d253f970ef94dd1c7cd9f0 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Sun, 19 Apr 2020 16:50:36 -0700 Subject: Switch to niv for managing third party sources --- .envrc | 2 + Biz/Dev/configuration.nix | 18 ++++-- Biz/buildOS.nix | 56 ------------------ Hero/App.hs | 2 +- Hero/Prod.nix | 8 --- Hero/Server.hs | 2 +- Que/Prod.nix | 10 ---- README.md | 3 +- biz.nix | 98 ------------------------------- default.nix | 143 +++++++++++++++++++++------------------------- deps.nix | 53 ----------------- nix/build.nix | 121 +++++++++++++++++++++++++++++++++++++++ nix/deps.nix | 53 +++++++++++++++++ nix/nixpkgs.nix | 10 ++++ nix/overlay.nix | 65 +++++++++++++++++++++ nix/sources.json | 26 +++++++++ nix/sources.nix | 134 +++++++++++++++++++++++++++++++++++++++++++ nixpkgs.nix | 5 -- overlay.nix | 65 --------------------- shell.nix | 9 +-- 20 files changed, 494 insertions(+), 389 deletions(-) delete mode 100644 Biz/buildOS.nix delete mode 100644 biz.nix delete mode 100644 deps.nix create mode 100644 nix/build.nix create mode 100644 nix/deps.nix create mode 100644 nix/nixpkgs.nix create mode 100644 nix/overlay.nix create mode 100644 nix/sources.json create mode 100644 nix/sources.nix delete mode 100644 nixpkgs.nix delete mode 100644 overlay.nix diff --git a/.envrc b/.envrc index 6934f24..718fff6 100644 --- a/.envrc +++ b/.envrc @@ -1,5 +1,7 @@ PATH_add $PWD export BIZ_ROOT=$PWD +export HERO_PORT=3000 +export HERO_CLIENT=$BIZ_ROOT/_bild/Hero.Client/static if type lorri &>/dev/null then eval "$(lorri direnv)" diff --git a/Biz/Dev/configuration.nix b/Biz/Dev/configuration.nix index 4a8839e..e822837 100644 --- a/Biz/Dev/configuration.nix +++ b/Biz/Dev/configuration.nix @@ -190,12 +190,18 @@ in { nixos.enable = true; }; - # Since this is the dev machine, we can turn these on at the expense of extra - # disk space. - nix.extraOptions = '' - keep-outputs = true - keep-derivations = true - ''; + + nix = { + # 1 job * 2 cores = 2 maximum cores used at any one time + maxJobs = 1; + buildCores = 2; + # Since this is the dev machine, we can turn these on at the expense + # of extra disk space. + extraOptions = '' + keep-outputs = true + keep-derivations = true + ''; + }; # This value determines the NixOS release with which your system is to be # compatible, in order to avoid breaking some software such as database diff --git a/Biz/buildOS.nix b/Biz/buildOS.nix deleted file mode 100644 index 9e6c2f2..0000000 --- a/Biz/buildOS.nix +++ /dev/null @@ -1,56 +0,0 @@ -nixos: -{ ipAddress ? null -, enableVpn ? false -, vpnConnectTo ? "" -, vpnRsaPrivateKeyFile ? null -, vpnEd25519PrivateKeyFile ? null -, deps ? {} # an attrset overlayed to pkgs -, configuration # see: configuration.nix(5) -}: -# assert enableVpn -> builtins.isString ipAddress; -# assert enableVpn -> builtins.isString vpnRsaPrivateKeyFile; -# assert enableVpn -> builtins.isString vpnEd25519PrivateKeyFile; -let - vpnExtraConfig = if enableVpn then '' - ConnectTo = ${vpnConnectTo} - Ed25519PrivateKeyFile = "${vpnEd25519PrivateKeyFile}" - PrivateKeyFile = "${vpnRsaPrivateKeyFile}" - '' else ""; - overlay = self: super: deps; - defaults = { - boot.cleanTmpDir = true; - #networking.interfaces.simatime-vpn = [{ ipv4.address = ipAddress; }]; - networking.firewall.allowPing = true; - nix.binaryCaches = [ "https://cache.nixos.org" ]; - nix.gc.automatic = true; - nix.gc.dates = "Sunday 02:15"; - nix.maxJobs = 1; # "auto"; - nix.optimise.automatic = true; - nix.optimise.dates = [ "Sunday 02:30" ]; - nixpkgs.overlays = [ overlay ]; - programs.mosh.enable = true; - programs.mosh.withUtempter = true; - security.acme.email = "ben@bsima.me"; - security.acme.acceptTerms = true; - security.sudo.wheelNeedsPassword = false; - services.clamav.daemon.enable = true; # security - services.clamav.updater.enable = true; # security - services.fail2ban.enable = true; # security - services.openssh.enable = true; - services.openssh.openFirewall = true; - services.openssh.forwardX11 = true; - services.openssh.passwordAuthentication = false; - #services.tinc.networks.simatime-vpn.extraConfig = vpnExtraConfig; - #services.tinc.networks.simatime-vpn.debugLevel = 3; - #services.tinc.networks.simatime-vpn.interfaceType = "tap"; - #services.tinc.networks.simatime-vpn.hosts = import ./vpnHosts.nix; - system.autoUpgrade.enable = false; # 'true' breaks our nixpkgs pin - }; - os = nixos { - system = "x86_64-linux"; - configuration = (defaults // configuration); - }; -in { - system = os.system; - vm = os.vm; -} diff --git a/Hero/App.hs b/Hero/App.hs index 39cfa03..a254d80 100644 --- a/Hero/App.hs +++ b/Hero/App.hs @@ -284,7 +284,7 @@ data ComicReaderState deriving (Show, Eq) findComic :: ComicId -> [Comic] -> Maybe Comic -findComic id = List.find . \c -> comicId c == id +findComic id = List.find (\c -> comicId c == id) -- | Main model for the app. -- diff --git a/Hero/Prod.nix b/Hero/Prod.nix index 10650ee..7da2f72 100644 --- a/Hero/Prod.nix +++ b/Hero/Prod.nix @@ -3,14 +3,6 @@ imports = [ ]; boot.loader.grub.device = "/dev/vda"; fileSystems."/" = { device = "/dev/vda1"; fsType = "ext4"; }; - - services.herocomics = { - enable = true; - port = 3000; - server = pkgs.herocomics-server; - client = pkgs.herocomics-client; - }; - networking = { firewall.allowedTCPPorts = [ 22 80 443 ]; nameservers = [ diff --git a/Hero/Server.hs b/Hero/Server.hs index bf92f88..4dc80f5 100644 --- a/Hero/Server.hs +++ b/Hero/Server.hs @@ -77,7 +77,7 @@ main = bracket startup shutdown $ uncurry Warp.run Right c -> do db <- Database.dummy say "hero" - say $ "port: " ++ show $ heroPort c + say $ "port: " ++ show (heroPort c) say $ "client: " ++ heroClient c let waiapp = app db c return (heroPort c, waiapp) diff --git a/Que/Prod.nix b/Que/Prod.nix index 97749c8..57a386a 100644 --- a/Que/Prod.nix +++ b/Que/Prod.nix @@ -4,16 +4,6 @@ boot.loader.grub.device = "/dev/vda"; fileSystems."/" = { device = "/dev/vda1"; fsType = "ext4"; }; networking.firewall.allowedTCPPorts = [ 22 80 443 ]; - services.que-server = { - enable = true; - port = 80; - package = pkgs.que-server; - }; - services.que-website = { - enable = true; - namespace = "_"; - package = pkgs.que-website; - }; networking = { nameservers = [ "67.207.67.2" diff --git a/README.md b/README.md index ea5469c..35084a1 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,8 @@ application. Development aspects should be localized to their sub-namespaces as much as possible. Only after sufficient iteration such that interfaces are solidified and functionality is well-established should some code be -promoted up the namespace hierarchy. +promoted up the namespace hierarchy. The one special namespace/directory +is `nix` which has all of our build rules. Boundaries and interfaces between namespaces should be small and well-defined. Likewise, the functionality and purpose of a particular diff --git a/biz.nix b/biz.nix deleted file mode 100644 index 6caadfd..0000000 --- a/biz.nix +++ /dev/null @@ -1,98 +0,0 @@ -{ nixpkgs }: - -with nixpkgs; -with nixpkgs.lib; - -let - # provided by .envrc - root = builtins.getEnv "BIZ_ROOT"; - - # general functions to put in a lib - lines = s: strings.splitString "\n" s; - removeNull = ls: builtins.filter (x: x != null) ls; - - depsToPackageSet = packageSet: deps: - attrsets.attrVals deps packageSet; - - # returns true if a is a subset of b, where a and b are attrsets - subset = a: b: builtins.all - (x: builtins.elem x b) a; - - allDeps = import ./deps.nix; - - # gather data needed for compiling by analyzing the main module - analyze = main: rec { - # path to the module relative to the git root - relpath = builtins.replaceStrings ["${root}/"] [""] - (builtins.toString main); - # Haskell-appropriate name of the module - module = builtins.replaceStrings ["/" ".hs"] ["." ""] relpath; - # file contents - content = builtins.readFile main; - # search for the ': exe' declaration - exe = builtins.head (lists.flatten (removeNull - (map (builtins.match "^-- : exe ([[:alnum:]._-]*)$") - (lines content)))); - # collect all of the ': dep' declarations - deps = lists.flatten (removeNull - (map (builtins.match "^-- : dep ([[:alnum:]._-]*)$") - (lines content))); - }; - - mkGhc = compiler: (deps: compiler (hp: - if (subset deps allDeps) - then depsToPackageSet hp deps - else throw '' - missing from deps.nix: - ${toString (lib.lists.subtractLists allDeps deps)} - '')); - - ghc_ = mkGhc pkgs.haskell.packages.ghc865.ghcWithHoogle; - ghcjs_ = mkGhc pkgs.haskell.packages.ghcjs.ghcWithPackages; -in { - buildGhc = main: - let - data = analyze main; - ghc = ghc_ data.deps; - in stdenv.mkDerivation { - name = data.module; - src = ./.; - nativeBuildInputs = [ ghc ]; - strictDeps = true; - buildPhase = '' - mkdir -p $out/bin - # compile with ghc - ${ghc}/bin/ghc -Werror -i. \ - --make ${main} \ - -main-is ${data.module} \ - -o $out/bin/${data.exe} - ''; - # the install process was handled above - installPhase = "exit 0"; - } // { env = ghc; }; - - buildGhcjs = main: - let - data = analyze main; - ghcjs = ghcjs_ data.deps; - in stdenv.mkDerivation { - name = data.module; - src = ./.; - nativeBuildInputs = [ ghcjs ]; - strictDeps = true; - buildPhase = '' - mkdir -p $out/static - # compile with ghcjs - ${ghcjs}/bin/ghcjs -Werror -i. \ - --make ${main} \ - -main-is ${data.module} \ - -o ${data.exe} - # optimize js output - ${pkgs.closurecompiler}/bin/closure-compiler \ - ${data.exe}/all.js > $out/static/${data.exe} - ''; - installPhase = "exit 0"; - } // { env = ghcjs; }; - - globalGhc = ghc_ allDeps; -} diff --git a/default.nix b/default.nix index 2d7fb8f..de30805 100644 --- a/default.nix +++ b/default.nix @@ -1,10 +1,6 @@ let - nixpkgs-tar = builtins.fetchTarball (import ./nixpkgs.nix); - overlay = import ./overlay.nix; - bizpkgs = import "${nixpkgs-tar}" { overlays = [ overlay ]; }; - nixos = import "${nixpkgs-tar}/nixos"; - biz = import ./biz.nix { nixpkgs = bizpkgs; }; - buildOS = import ./Biz/buildOS.nix nixos; + nixpkgs = import ./nix/nixpkgs.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"; sha256 = "0lpz08qviccvpfws2nm83n7m2r8add2wvfg9bljx9yxx8107r919"; @@ -13,91 +9,84 @@ in rec { # Cloud infrastructure, always online. Mostly for messaging-related # stuff. # - Biz.Cloud = buildOS { - enableVpn = true; - ipAddress = "159.89.128.69"; - configuration = { - imports = [ - ./Biz/packages.nix - ./Biz/users.nix - ./Biz/Cloud/chat.nix - ./Biz/Cloud/git.nix - ./Biz/Cloud/hardware.nix - ./Biz/Cloud/mail.nix - ./Biz/Cloud/networking.nix - ./Biz/Cloud/web.nix - ./Biz/Cloud/znc.nix - nixos-mailserver - ]; - networking.hostName = "simatime"; - networking.domain = "simatime.com"; - }; + Biz.Cloud = build.os { + imports = [ + ./Biz/packages.nix + ./Biz/users.nix + ./Biz/Cloud/chat.nix + ./Biz/Cloud/git.nix + ./Biz/Cloud/hardware.nix + ./Biz/Cloud/mail.nix + ./Biz/Cloud/networking.nix + ./Biz/Cloud/web.nix + ./Biz/Cloud/znc.nix + nixos-mailserver + ]; + networking.hostName = "simatime"; + networking.domain = "simatime.com"; }; # Dev machine for work and building stuff. # - Biz.Dev = buildOS { - enableVpn = true; - ipAddress = "73.222.221.63"; - deps = { - wemux = bizpkgs.wemux; - }; - configuration = { - imports = [ - ./Biz/packages.nix - ./Biz/users.nix - ./Biz/Dev/configuration.nix - ./Biz/Dev/hardware.nix - ]; - networking.hostName = "lithium"; - networking.domain = "dev.simatime.com"; - }; + Biz.Dev = build.os { + imports = [ + ./Biz/packages.nix + ./Biz/users.nix + ./Biz/Dev/configuration.nix + ./Biz/Dev/hardware.nix + ]; + networking.hostName = "lithium"; + networking.domain = "dev.simatime.com"; }; # The production server for que.run # - Que.Prod = buildOS { - deps = { - que-server = Que.Server; - que-website = Que.Website; + Que.Prod = build.os { + imports = [ + ./Biz/packages.nix + ./Biz/users.nix + ./Que/Server.nix + ./Que/Website.nix + ./Que/Prod.nix + ]; + networking.hostName = "prod-que"; + networking.domain = "que.run"; + services.que-server = { + enable = true; + port = 80; + package = Que.Server; }; - configuration = { - imports = [ - ./Biz/packages.nix - ./Biz/users.nix - ./Que/Server.nix - ./Que/Website.nix - ./Que/Prod.nix - ]; - networking.hostName = "prod-que"; - networking.domain = "que.run"; + services.que-website = { + enable = true; + namespace = "_"; + package = Que.Website; }; }; # Production server for herocomics.app - Hero.Prod = buildOS { - deps = { - herocomics-server = Hero.Server; - herocomics-client = Hero.Client; - }; - configuration = { - imports = [ - ./Biz/packages.nix - ./Biz/users.nix - ./Hero/Service.nix - ./Hero/Prod.nix - ]; - networking.hostName = "prod-herocomics"; - networking.domain = "herocomcis.app"; + Hero.Prod = build.os { + imports = [ + ./Biz/packages.nix + ./Biz/users.nix + ./Hero/Service.nix + ./Hero/Prod.nix + ]; + networking.hostName = "prod-herocomics"; + networking.domain = "herocomcis.app"; + services.herocomics = { + enable = true; + port = 3000; + server = Hero.Server; + client = Hero.Client; }; }; # Haskell targets # - Biz.Ibb.Server = biz.buildGhc Biz/Ibb/Server.hs; - Biz.Ibb.Client = biz.buildGhcjs Biz/Ibb/Client.hs; - Hero.Server = biz.buildGhc Hero/Server.hs; - Hero.Client = biz.buildGhcjs Hero/Client.hs; - Que.Server = biz.buildGhc ./Que/Server.hs; - Que.Website = biz.buildGhc ./Que/Website.hs; + Biz.Ibb.Server = build.ghc Biz/Ibb/Server.hs; + Biz.Ibb.Client = build.ghcjs Biz/Ibb/Client.hs; + Hero.Server = build.ghc Hero/Server.hs; + Hero.Client = build.ghcjs Hero/Client.hs; + Que.Server = build.ghc ./Que/Server.hs; + Que.Website = build.ghc ./Que/Website.hs; # Development environment - repl = biz.globalGhc; + repl = build.env; # Fall through to any of our overlay packages - inherit bizpkgs; + inherit nixpkgs; } diff --git a/deps.nix b/deps.nix deleted file mode 100644 index 44c2050..0000000 --- a/deps.nix +++ /dev/null @@ -1,53 +0,0 @@ -[ - "MonadRandom" - "QuickCheck" - "acid-state" - "aeson" - "async" - "bytestring" - "capability" - "clay" - "config-ini" - "containers" - "dhall" - "directory" - "ekg" - "envy" - "fast-logger" - "filepath" - "ghcjs-base" - "http-types" - "ixset" - "katip" - "lucid" - "miso" - "monad-logger" - "monad-metrics" - "mtl" - "network-uri" - "process" - "protolude" - "quickcheck-instances" - "random" - "req" - "safecopy" - "scotty" - "servant" - "servant-lucid" - "servant-server" - "split" - "stm" - "string-quote" - "tasty" - "text" - "transformers" - "unagi-chan" - "unix" - "unordered-containers" - "vector" - "wai" - "wai-app-static" - "wai-extra" - "wai-middleware-metrics" - "warp" -] diff --git a/nix/build.nix b/nix/build.nix new file mode 100644 index 0000000..6f979d7 --- /dev/null +++ b/nix/build.nix @@ -0,0 +1,121 @@ +{ nixpkgs }: + +with nixpkgs; + +let + # provided by .envrc + root = builtins.getEnv "BIZ_ROOT"; + + # general functions to put in a lib + lines = s: lib.strings.splitString "\n" s; + removeNull = ls: builtins.filter (x: x != null) ls; + + depsToPackageSet = packageSet: deps: + lib.attrsets.attrVals deps packageSet; + + # returns true if a is a subset of b, where a and b are attrsets + subset = a: b: builtins.all + (x: builtins.elem x b) a; + + allDeps = import ./deps.nix; + + # gather data needed for compiling by analyzing the main module + analyze = main: rec { + # path to the module relative to the git root + relpath = builtins.replaceStrings ["${root}/"] [""] + (builtins.toString main); + # Haskell-appropriate name of the module + module = builtins.replaceStrings ["/" ".hs"] ["." ""] relpath; + # file contents + content = builtins.readFile main; + # search for the ': exe' declaration + exe = builtins.head (lib.lists.flatten (removeNull + (map (builtins.match "^-- : exe ([[:alnum:]._-]*)$") + (lines content)))); + # collect all of the ': dep' declarations + deps = lib.lists.flatten (removeNull + (map (builtins.match "^-- : dep ([[:alnum:]._-]*)$") + (lines content))); + }; + + mkGhc = compiler: (deps: compiler (hp: + if (subset deps allDeps) + then depsToPackageSet hp deps + else throw '' + missing from deps.nix: + ${toString (lib.lists.subtractLists allDeps deps)} + '')); + + ghc_ = mkGhc pkgs.haskell.packages.ghc865.ghcWithHoogle; + ghcjs_ = mkGhc pkgs.haskell.packages.ghcjs.ghcWithPackages; +in { + ghc = main: + let + data = analyze main; + ghc = ghc_ data.deps; + in stdenv.mkDerivation { + name = data.module; + src = ../.; + nativeBuildInputs = [ ghc ]; + strictDeps = true; + buildPhase = '' + mkdir -p $out/bin + # compile with ghc + ${ghc}/bin/ghc -Werror -i. \ + --make ${main} \ + -main-is ${data.module} \ + -o $out/bin/${data.exe} + ''; + # the install process was handled above + installPhase = "exit 0"; + } // { env = ghc; }; + + ghcjs = main: + let + data = analyze main; + ghcjs = ghcjs_ data.deps; + in stdenv.mkDerivation { + name = data.module; + src = ../.; + nativeBuildInputs = [ ghcjs ]; + strictDeps = true; + buildPhase = '' + mkdir -p $out/static + # compile with ghcjs + ${ghcjs}/bin/ghcjs -Werror -i. \ + --make ${main} \ + -main-is ${data.module} \ + -o ${data.exe} + # optimize js output + ${pkgs.closurecompiler}/bin/closure-compiler \ + ${data.exe}/all.js > $out/static/${data.exe} + ''; + installPhase = "exit 0"; + } // { env = ghcjs; }; + + env = ghc_ allDeps; + + os = cfg: (nixos (args: lib.attrsets.recursiveUpdate cfg { + boot.cleanTmpDir = true; + networking.firewall.allowPing = true; + nix.binaryCaches = [ "https://cache.nixos.org" ]; + nix.gc.automatic = true; + nix.gc.dates = "Sunday 02:15"; + nix.optimise.automatic = true; + nix.optimise.dates = [ "Sunday 02:30" ]; + nixpkgs.overlays = overlays; + programs.mosh.enable = true; + programs.mosh.withUtempter = true; + security.acme.email = "ben@bsima.me"; + security.acme.acceptTerms = true; + security.sudo.wheelNeedsPassword = false; + services.clamav.daemon.enable = true; # security + services.clamav.updater.enable = true; # security + services.fail2ban.enable = true; # security + services.openssh.enable = true; + services.openssh.openFirewall = true; + services.openssh.forwardX11 = true; + services.openssh.passwordAuthentication = false; + system.autoUpgrade.enable = false; # 'true' breaks our nixpkgs pin + })).toplevel; +} diff --git a/nix/deps.nix b/nix/deps.nix new file mode 100644 index 0000000..44c2050 --- /dev/null +++ b/nix/deps.nix @@ -0,0 +1,53 @@ +[ + "MonadRandom" + "QuickCheck" + "acid-state" + "aeson" + "async" + "bytestring" + "capability" + "clay" + "config-ini" + "containers" + "dhall" + "directory" + "ekg" + "envy" + "fast-logger" + "filepath" + "ghcjs-base" + "http-types" + "ixset" + "katip" + "lucid" + "miso" + "monad-logger" + "monad-metrics" + "mtl" + "network-uri" + "process" + "protolude" + "quickcheck-instances" + "random" + "req" + "safecopy" + "scotty" + "servant" + "servant-lucid" + "servant-server" + "split" + "stm" + "string-quote" + "tasty" + "text" + "transformers" + "unagi-chan" + "unix" + "unordered-containers" + "vector" + "wai" + "wai-app-static" + "wai-extra" + "wai-middleware-metrics" + "warp" +] diff --git a/nix/nixpkgs.nix b/nix/nixpkgs.nix new file mode 100644 index 0000000..246b8a8 --- /dev/null +++ b/nix/nixpkgs.nix @@ -0,0 +1,10 @@ +let + sources = import ./sources.nix; + nixpkgs = import sources.nixpkgs { + system = "x86_64-linux"; + overlays = [ + (_: _: { niv = import sources.niv {}; }) + (import ./overlay.nix) + ]; + }; +in nixpkgs diff --git a/nix/overlay.nix b/nix/overlay.nix new file mode 100644 index 0000000..dcadf34 --- /dev/null +++ b/nix/overlay.nix @@ -0,0 +1,65 @@ +self: super: + +let + claySrc = super.pkgs.fetchFromGitHub { + owner = "sebastiaanvisser"; + repo = "clay"; + rev = "cc7729b1b42a79e261091ff7835f7fc2a7ae3cee"; + sha256 = "1vd67976lvi5l4qq18zy6j44apynkl44ps04p8vwfx4gzr895dyp"; + }; + jsaddleSrc = super.pkgs.fetchFromGitHub { + owner = "ghcjs"; + repo = "jsaddle"; + rev = "1e39844"; + sha256 = "1qrjrjagmrrlcalys33636w5cb67db52i183masb7xd93wir8963"; + }; + misoSrc = super.pkgs.fetchFromGitHub { + owner = "dmjio"; + repo = "miso"; + rev = "1.5"; + sha256 = "00al7gw760vzzlqpf035k4n4li0rdymcjpxn184z9nc4m92cjv9z"; + }; +in { + haskell = super.haskell // { + packages = super.haskell.packages // { + ghc865 = super.haskell.packages.ghc865.override (old: { + overrides = with super.pkgs.haskell.lib; self: super: { + clay = self.callCabal2nix "clay" claySrc {}; + miso = self.callCabal2nix "miso" misoSrc {}; + wai-middleware-metrics = dontCheck super.wai-middleware-metrics; + }; + }); + ghcjs = super.haskell.packages.ghcjs.override (old: { + overrides = with super.haskell.lib; self: super: { + QuickCheck = dontCheck super.QuickCheck; + base-compat-batteries = dontCheck super.http-types; + clay = dontCheck (self.callCabal2nix "clay" claySrc {}); + comonad = dontCheck super.comonad; + jsaddle-warp = dontCheck (self.callCabal2nix "jsaddle-warp" "${jsaddleSrc}/jsaddle-warp" {}); + http-types = dontCheck super.http-types; + miso = self.callCabal2nix "miso" misoSrc {}; + network-uri= dontCheck super.network-uri; + scientific = dontCheck super.scientific; # takes forever + servant = dontCheck super.servant; + tasty-quickcheck = dontCheck super.tasty-quickcheck; + time-compat = dontCheck super.time-compat; + }; + }); + }; + }; + wemux = super.stdenv.mkDerivation rec { + name = "wemux"; + version = "2020.04.03"; + src = super.pkgs.fetchFromGitHub { + owner = "zolrath"; + repo = "wemux"; + rev = "01c6541f8deceff372711241db2a13f21c4b210c"; + sha256 = "1y962nzvs7sf720pl3wa582l6irxc8vavd0gp4ag4243b2gs4qvm"; + }; + installPhase = '' + mkdir -p $out/bin + cp ${src}/wemux $out/bin + chmod +x $out/bin/wemux + ''; + }; +} diff --git a/nix/sources.json b/nix/sources.json new file mode 100644 index 0000000..841f308 --- /dev/null +++ b/nix/sources.json @@ -0,0 +1,26 @@ +{ + "niv": { + "branch": "master", + "description": "Easy dependency management for Nix projects", + "homepage": "https://github.com/nmattia/niv", + "owner": "nmattia", + "repo": "niv", + "rev": "f73bf8d584148677b01859677a63191c31911eae", + "sha256": "0jlmrx633jvqrqlyhlzpvdrnim128gc81q5psz2lpp2af8p8q9qs", + "type": "tarball", + "url": "https://github.com/nmattia/niv/archive/f73bf8d584148677b01859677a63191c31911eae.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, + "nixpkgs": { + "branch": "nixos-19.09", + "description": "Nix Packages collection", + "homepage": "https://github.com/NixOS/nixpkgs", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b0c285807d6a9f1b7562ec417c24fa1a30ecc31a", + "sha256": "0waapr7aqz0h1fy1fqlx981ygllh91qx9sz1l2j2h59s46cdircl", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/b0c285807d6a9f1b7562ec417c24fa1a30ecc31a.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..8a725cb --- /dev/null +++ b/nix/sources.nix @@ -0,0 +1,134 @@ +# This file has been generated by Niv. + +let + + # + # The fetchers. fetch_ fetches specs of type . + # + + fetch_file = pkgs: spec: + if spec.builtin or true then + builtins_fetchurl { inherit (spec) url sha256; } + else + pkgs.fetchurl { inherit (spec) url sha256; }; + + fetch_tarball = pkgs: spec: + if spec.builtin or true then + builtins_fetchTarball { inherit (spec) url sha256; } + else + pkgs.fetchzip { inherit (spec) url sha256; }; + + fetch_git = spec: + builtins.fetchGit { url = spec.repo; inherit (spec) rev ref; }; + + fetch_builtin-tarball = spec: + builtins.trace + '' + WARNING: + The niv type "builtin-tarball" will soon be deprecated. You should + instead use `builtin = true`. + + $ niv modify -a type=tarball -a builtin=true + '' + builtins_fetchTarball { inherit (spec) url sha256; }; + + fetch_builtin-url = spec: + builtins.trace + '' + WARNING: + The niv type "builtin-url" will soon be deprecated. You should + instead use `builtin = true`. + + $ niv modify -a type=file -a builtin=true + '' + (builtins_fetchurl { inherit (spec) url sha256; }); + + # + # Various helpers + # + + # The set of packages used when specs are fetched using non-builtins. + mkPkgs = sources: + let + sourcesNixpkgs = + import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) {}; + hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; + hasThisAsNixpkgsPath = == ./.; + in + if builtins.hasAttr "nixpkgs" sources + then sourcesNixpkgs + else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then + import {} + else + abort + '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; + + # The actual fetching function. + fetch = pkgs: name: spec: + + if ! builtins.hasAttr "type" spec then + abort "ERROR: niv spec ${name} does not have a 'type' attribute" + else if spec.type == "file" then fetch_file pkgs spec + else if spec.type == "tarball" then fetch_tarball pkgs spec + else if spec.type == "git" then fetch_git spec + else if spec.type == "builtin-tarball" then fetch_builtin-tarball spec + else if spec.type == "builtin-url" then fetch_builtin-url spec + else + abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; + + # Ports of functions for older nix versions + + # a Nix version of mapAttrs if the built-in doesn't exist + mapAttrs = builtins.mapAttrs or ( + f: set: with builtins; + listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) + ); + + # 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; + + # Create the final "sources" from the config + mkSources = config: + mapAttrs ( + name: spec: + if builtins.hasAttr "outPath" spec + then abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = fetch config.pkgs name spec; } + ) config.sources; + + # The "config" used by the fetchers + mkConfig = + { sourcesFile ? ./sources.json + , sources ? builtins.fromJSON (builtins.readFile sourcesFile) + , pkgs ? mkPkgs sources + }: rec { + # The sources, i.e. the attribute set of spec name to spec + inherit sources; + + # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers + inherit pkgs; + }; +in +mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/nixpkgs.nix b/nixpkgs.nix deleted file mode 100644 index fbf8257..0000000 --- a/nixpkgs.nix +++ /dev/null @@ -1,5 +0,0 @@ -# generated with ~/bin/nixos-pin -{ - url = "https://github.com/NixOS/nixpkgs/archive/b0c285807d6a9f1b7562ec417c24fa1a30ecc31a.tar.gz"; - sha256 = "0waapr7aqz0h1fy1fqlx981ygllh91qx9sz1l2j2h59s46cdircl"; -} diff --git a/overlay.nix b/overlay.nix deleted file mode 100644 index dcadf34..0000000 --- a/overlay.nix +++ /dev/null @@ -1,65 +0,0 @@ -self: super: - -let - claySrc = super.pkgs.fetchFromGitHub { - owner = "sebastiaanvisser"; - repo = "clay"; - rev = "cc7729b1b42a79e261091ff7835f7fc2a7ae3cee"; - sha256 = "1vd67976lvi5l4qq18zy6j44apynkl44ps04p8vwfx4gzr895dyp"; - }; - jsaddleSrc = super.pkgs.fetchFromGitHub { - owner = "ghcjs"; - repo = "jsaddle"; - rev = "1e39844"; - sha256 = "1qrjrjagmrrlcalys33636w5cb67db52i183masb7xd93wir8963"; - }; - misoSrc = super.pkgs.fetchFromGitHub { - owner = "dmjio"; - repo = "miso"; - rev = "1.5"; - sha256 = "00al7gw760vzzlqpf035k4n4li0rdymcjpxn184z9nc4m92cjv9z"; - }; -in { - haskell = super.haskell // { - packages = super.haskell.packages // { - ghc865 = super.haskell.packages.ghc865.override (old: { - overrides = with super.pkgs.haskell.lib; self: super: { - clay = self.callCabal2nix "clay" claySrc {}; - miso = self.callCabal2nix "miso" misoSrc {}; - wai-middleware-metrics = dontCheck super.wai-middleware-metrics; - }; - }); - ghcjs = super.haskell.packages.ghcjs.override (old: { - overrides = with super.haskell.lib; self: super: { - QuickCheck = dontCheck super.QuickCheck; - base-compat-batteries = dontCheck super.http-types; - clay = dontCheck (self.callCabal2nix "clay" claySrc {}); - comonad = dontCheck super.comonad; - jsaddle-warp = dontCheck (self.callCabal2nix "jsaddle-warp" "${jsaddleSrc}/jsaddle-warp" {}); - http-types = dontCheck super.http-types; - miso = self.callCabal2nix "miso" misoSrc {}; - network-uri= dontCheck super.network-uri; - scientific = dontCheck super.scientific; # takes forever - servant = dontCheck super.servant; - tasty-quickcheck = dontCheck super.tasty-quickcheck; - time-compat = dontCheck super.time-compat; - }; - }); - }; - }; - wemux = super.stdenv.mkDerivation rec { - name = "wemux"; - version = "2020.04.03"; - src = super.pkgs.fetchFromGitHub { - owner = "zolrath"; - repo = "wemux"; - rev = "01c6541f8deceff372711241db2a13f21c4b210c"; - sha256 = "1y962nzvs7sf720pl3wa582l6irxc8vavd0gp4ag4243b2gs4qvm"; - }; - installPhase = '' - mkdir -p $out/bin - cp ${src}/wemux $out/bin - chmod +x $out/bin/wemux - ''; - }; -} diff --git a/shell.nix b/shell.nix index 8fe59f8..c0d1e6a 100644 --- a/shell.nix +++ b/shell.nix @@ -3,10 +3,7 @@ }: let - nixpkgs-tar = builtins.fetchTarball (import ./nixpkgs.nix); - nixpkgs = import "${nixpkgs-tar}" { overlays = [ (import ./overlay.nix) ]; }; - nixos = import "${nixpkgs-tar}/nixos"; - biz = import ./biz.nix { inherit nixpkgs; }; + nixpkgs = import ./nix/nixpkgs.nix; in nixpkgs.mkShell ({ name = "bizdev"; buildInputs = [ @@ -19,10 +16,6 @@ in nixpkgs.mkShell ({ nixpkgs.wemux ]; shellHook = '' - export HERO_PORT=3000 - # TODO: figure out another way to do this - #export HERO_CLIENT=$PWD/_bild/Com.MusicMeetsComics.Client/static - echo "biz" | ${nixpkgs.figlet}/bin/figlet | ${nixpkgs.lolcat}/bin/lolcat ''; }) -- cgit v1.2.3