Browse Source

Added nix flake

completed
Craige McWhirter 7 months ago
parent
commit
f989a8c370
Signed by: craige GPG Key ID: 7DBA9F5689EFB6AA
  1. 4
      .envrc
  2. 116
      flake.lock
  3. 35
      flake.nix
  4. 12
      rndSelect.hs

4
.envrc

@ -0,0 +1,4 @@
watch_file flake.nix
watch_file flake.lock
mkdir -p "$(direnv_layout_dir)"
eval "$(nix print-dev-env --profile "$(direnv_layout_dir)/flake-profile")"

116
flake.lock

@ -0,0 +1,116 @@
{
"nodes": {
"haskellNix": {
"inputs": {
"nixpkgs": "nixpkgs",
"nixpkgs-2003": "nixpkgs-2003",
"nixpkgs-2009": "nixpkgs-2009",
"nixpkgs-unstable": "nixpkgs-unstable"
},
"locked": {
"lastModified": 1620090849,
"narHash": "sha256-SnFZs9RGaZeR3JhSloBnM0mTUDRyF71vjEgOysyQZtg=",
"owner": "input-output-hk",
"repo": "haskell.nix",
"rev": "278216c1445c147258ffd88ae5fe0f898830bde9",
"type": "github"
},
"original": {
"owner": "input-output-hk",
"repo": "haskell.nix",
"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"
}
},
"root": {
"inputs": {
"haskellNix": "haskellNix",
"nixpkgs": [
"haskellNix",
"nixpkgs-unstable"
],
"utils": "utils"
}
},
"utils": {
"locked": {
"lastModified": 1619345332,
"narHash": "sha256-qHnQkEp1uklKTpx3MvKtY6xzgcqXDsz5nLilbbuL+3A=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "2ebf2558e5bf978c7fb8ea927dfaed8fefab2e28",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

35
flake.nix

@ -0,0 +1,35 @@
{
description = "99 Haskell Problems";
inputs = {
haskellNix.url = "github:input-output-hk/haskell.nix";
nixpkgs.follows = "haskellNix/nixpkgs-unstable";
utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, utils, haskellNix }:
utils.lib.eachSystem [ "x86_64-linux" ] (system:
let
overlays = [ haskellNix.overlay
(final: prev: {
# This overlay adds our project to pkgs
"99haskellProblems" =
final.haskell-nix.project' {
src = ./.;
compiler-nix-name = "ghc8104";
};
})
];
pkgs = import nixpkgs { inherit system overlays; };
flake = pkgs."99haskellProblems".flake {};
in flake // {
# This is used by `nix develop .` to open a shell for use with
# `cabal`, `hlint` and `haskell-language-server`
devShell = pkgs."99haskellProject".shellFor {
tools = {
cabal = "latest";
hlint = "latest";
haskell-language-server = "latest";
};
};
});
}

12
rndSelect.hs

@ -0,0 +1,12 @@
{-# LANGUAGE StandaloneDeriving #-}
{-# OPTIONS_GHC -Wno-orphans #-}
-- Extract a given number of randomly selected elements from a list.
import Data.List (nub)
import System.Random
rnd_select :: [a] -> Int -> IO [a]
rnd_select lst n = map (lst !!) <$> indices
where indices = take n . nub . randomRs (0, length lst - 1) <$> getStdGen
Loading…
Cancel
Save