From aa2a5ebae2f9170602755dfb0473d1f9e967f9dd Mon Sep 17 00:00:00 2001 From: Thorn Avery Date: Thu, 5 Nov 2020 20:23:51 +1300 Subject: [PATCH] initial --- .gitignore | 4 ++++ LICENSE | 2 ++ Main.hs | 4 ++++ README.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ Setup.hs | 2 ++ flake.lock | 43 +++++++++++++++++++++++++++++++++++++++++++ flake.nix | 19 +++++++++++++++++++ haskeleton.cabal | 27 +++++++++++++++++++++++++++ nix/haskeleton.nix | 11 +++++++++++ overlay.nix | 3 +++ release.nix | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 208 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 Main.hs create mode 100644 README.md create mode 100644 Setup.hs create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 haskeleton.cabal create mode 100644 nix/haskeleton.nix create mode 100644 overlay.nix create mode 100644 release.nix diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..580f715 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +result +result-doc +*.swp + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5531a16 --- /dev/null +++ b/LICENSE @@ -0,0 +1,2 @@ +if u use dis repo u agree to not be a chud. +military and corps get out. diff --git a/Main.hs b/Main.hs new file mode 100644 index 0000000..65ae4a0 --- /dev/null +++ b/Main.hs @@ -0,0 +1,4 @@ +module Main where + +main :: IO () +main = putStrLn "Hello, Haskell!" diff --git a/README.md b/README.md new file mode 100644 index 0000000..748bb23 --- /dev/null +++ b/README.md @@ -0,0 +1,46 @@ +# Skeleton Haskell Flake + +included is my attempt at a bare bones haskell project, implemented as a nix flake in order to allow reproducible builds. + +## building + +allows usage within `nix shell`, assuming a flakes system, with the followng: + +``` +nix shell github:techieAgnostic/haskeleton#haskeleton +``` + +otherwise it can be built normally with: + +``` +nix build. +``` + +or added to a system configuration by creating an input: + +``` +inputs.haskeleton.url = "github:techieAgnostic/haskeleton"; +``` + +and using the `haskeleton.overlay` attribute to import the program into your pkgset. + +## adding hackage dependencies + +dependencies can be added to the `haskeleton.cabal` file as normal. the `haskeleton.nix` file must be regenerated once this happens. + +> !!!important!!! + +in order for this to work without manual editing of `haskeleton.nix`, the command must be run from the `./nix` directory. + +``` +cd ./nix +cabal2nix ../ > haskeleton.nix +``` + +for packages not in the nixpkgs repository, or that you would like to have a different version of than appears in the repo, you can add them to the `./nix` directory manually like so: + +``` +cabal2nix cabal://name-version > ./nix/name.nix +``` + +and in order to disable building tests, documentation, or to jailbreak the dependencies of a package (should the build fail for those reasons), add the packages name to the lists defined in `./release.nix`. diff --git a/Setup.hs b/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..1b78a66 --- /dev/null +++ b/flake.lock @@ -0,0 +1,43 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1601282935, + "narHash": "sha256-WQAFV6sGGQxrRs3a+/Yj9xUYvhTpukQJIcMbIi7LCJ4=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "588973065fce51f4763287f0fda87a174d78bf48", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1604368813, + "narHash": "sha256-UOLaURSO448k+4bGJlaSMYeo2F5F6CuFo9VoYDkhmsk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "d105075a1fd870b1d1617a6008cb38b443e65433", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-20.09", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..8855fd9 --- /dev/null +++ b/flake.nix @@ -0,0 +1,19 @@ +{ + description = "a skeleton haskell flake"; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-20.09"; + flake-utils.url = "github:numtide/flake-utils"; + }; + outputs = { self, nixpkgs, flake-utils, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + overlays = [ (import ./overlay.nix) ]; + inherit system; + }; + in { + defaultPackage = pkgs.haskeleton; + }) // { + overlay = import ./overlay.nix; + }; +} diff --git a/haskeleton.cabal b/haskeleton.cabal new file mode 100644 index 0000000..04e55f4 --- /dev/null +++ b/haskeleton.cabal @@ -0,0 +1,27 @@ +cabal-version: >=1.10 +-- Initial package description 'haskeleton.cabal' generated by 'cabal +-- init'. For further documentation, see +-- http://haskell.org/cabal/users-guide/ + +name: haskeleton +version: 0.1.0.0 +-- synopsis: +-- description: +-- bug-reports: +-- license: +license-file: LICENSE +author: Thorn Avery +maintainer: s@p7.co.nz +-- copyright: +-- category: +build-type: Simple + +executable haskeleton + main-is: Main.hs + -- other-modules: + -- other-extensions: + build-depends: base >=4.13 && <4.14 + , text + , aeson + -- hs-source-dirs: + default-language: Haskell2010 diff --git a/nix/haskeleton.nix b/nix/haskeleton.nix new file mode 100644 index 0000000..d6286f6 --- /dev/null +++ b/nix/haskeleton.nix @@ -0,0 +1,11 @@ +{ mkDerivation, aeson, base, stdenv, text }: +mkDerivation { + pname = "haskeleton"; + version = "0.1.0.0"; + src = ./..; + isLibrary = false; + isExecutable = true; + executableHaskellDepends = [ aeson base text ]; + license = "unknown"; + hydraPlatforms = stdenv.lib.platforms.none; +} diff --git a/overlay.nix b/overlay.nix new file mode 100644 index 0000000..5dd8e5d --- /dev/null +++ b/overlay.nix @@ -0,0 +1,3 @@ +final: prev: { + haskeleton = (import ./release.nix) prev; +} diff --git a/release.nix b/release.nix new file mode 100644 index 0000000..169fc39 --- /dev/null +++ b/release.nix @@ -0,0 +1,47 @@ +bspkgs: +let + dontCheckPackages = [ ]; + doJailbreakPackages = [ ]; + dontHaddockPackages = [ ]; + config = { + packageOverrides = pkgs: rec { + haskellPackages = + let + generatedOverrides = haskellPackagesNew: haskellPackagesOld: + let + toPackage = file: _: { + name = builtins.replaceStrings [ ".nix" ] [ "" ] file; + value = haskellPackagesNew.callPackage + ( ./. + "/nix/${file}") { }; + }; + in + pkgs.lib.mapAttrs' toPackage + (builtins.readDir ./nix); + makeOverrides = + function: names: haskellPackagesNew: haskellPackagesOld: + let + toPackage = name: { + inherit name; + value = function haskellPackagesOld.${name}; + }; + in + builtins.listToAttrs (map toPackage names); + composeExtensionsList = + pkgs.lib.fold pkgs.lib.composeExtensions (_: _: {}); + manualOverrides = haskellPackagesNew: haskellPackagesOld: { + }; + in + pkgs.haskellPackages.override { + overrides = composeExtensionsList [ + generatedOverrides + (makeOverrides pkgs.haskell.lib.dontCheck dontCheckPackages) + (makeOverrides pkgs.haskell.lib.doJailbreak doJailbreakPackages) + (makeOverrides pkgs.haskell.lib.dontHaddock dontHaddockPackages) + manualOverrides + ]; + }; + }; + }; + pkgs = import bspkgs.path { inherit config; system = bspkgs.system; }; +in + pkgs.haskellPackages.haskeleton