Last active
August 21, 2021 06:01
-
-
Save parsonsmatt/0e16ed74c00595d4c4cd1cffcdb65a31 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# language OverloadedLists #-} | |
{-# OPTIONS_GHC -Wall #-} | |
module Overlays where | |
import Prelude hiding ((.)) | |
import GHC.Stack | |
import Debug.Trace | |
import Data.Map (Map) | |
import qualified Data.Map.Lazy as Map | |
type PkgSet = | |
Map String Derivation | |
type Derivation = | |
Int | |
nixpkgs :: PkgSet | |
nixpkgs = | |
[ "gcc" =: 1 | |
, "ghc" =: 2 | |
] | |
(=:) :: a -> b -> (a, b) | |
a =: b = (a, b) | |
infixr 0 =: | |
type Overlay = | |
PkgSet -> PkgSet -> PkgSet | |
mkPkgSet :: PkgSet -> [Overlay] -> PkgSet | |
mkPkgSet prev [] = | |
prev | |
mkPkgSet prev (fn : fns) = | |
let | |
this = | |
fn final prev | |
rest = | |
mkPkgSet this fns | |
final = | |
rest <> prev | |
in | |
final | |
-- $> myPackage | |
myPackage :: HasCallStack => PkgSet | |
myPackage = | |
mkPkgSet nixpkgs | |
[ \self super -> | |
[ "hello" =: self."gcc" + 1 | |
] | |
, \self super -> | |
[ "hello" =: (super."hello" + 4) | |
, "helloOld" =: super."hello" | |
, "helloSelf" =: self."hello" | |
, "dang" =: self."hello" + 1 | |
, "second" =: self."third" - 1 | |
] | |
, \self super -> | |
[ "hello" =: 1234 | |
, "finalHello" =: self."hello" | |
, "helloFrom3Super" =: super."hello" | |
, "third" =: 3 | |
] | |
] | |
infixr 9 . | |
(.) :: PkgSet -> String -> Derivation | |
pkgSet . attr = | |
case Map.lookup attr pkgSet of | |
Nothing -> | |
error $ mconcat ( | |
[ "The attribute " | |
, attr | |
, " was not found in the package set." | |
] :: [String]) | |
Just a -> | |
a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment