Simplify nix setup

This commit is contained in:
Paul Brinkmeier 2025-02-22 11:44:49 +01:00
parent 61355405d5
commit a37643b5cd
6 changed files with 19 additions and 161 deletions

View File

@ -32,3 +32,7 @@ $ nix develop
$ nix run .#stack $ nix run .#stack
$ nix run .#ghc $ nix run .#ghc
``` ```
## TODO
- [ ] Benchmark, profile and optimize search

View File

@ -5,85 +5,32 @@
outputs = { self, nixpkgs }: outputs = { self, nixpkgs }:
let let
settings = import ./nix/settings.nix;
haskellDeps = import ./nix/haskell-deps.nix;
pkgs = nixpkgs.legacyPackages.x86_64-linux; pkgs = nixpkgs.legacyPackages.x86_64-linux;
haskellPackages = pkgs.haskell.packages."${settings.ghc}";
ghc = haskellPackages.ghcWithPackages haskellDeps; utoy = pkgs.haskellPackages.developPackage {
root = ./.;
# Wrap stack to disable its slow Nix integration.
# Instead, make it use the GHC defined above.
stack = pkgs.stdenv.mkDerivation {
name = "stack";
# The build is simply a call to makeWrapper, so we don't have to
# do any of the typical build steps.
phases = [ "installPhase" ];
nativeBuildInputs = [ pkgs.makeWrapper ];
# makeBinaryWrapper creates a stack executable for us that uses
# the GHC defined in this file.
installPhase = ''
makeWrapper ${pkgs.stack}/bin/stack $out/bin/stack \
--prefix PATH : ${ghc}/bin \
--add-flags '--no-nix --system-ghc --no-install-ghc'
'';
}; };
utoy = pkgs.haskell.lib.justStaticExecutables (haskellPackages.callPackage
({ mkDerivation }:
mkDerivation {
# Keep this in sync with package.yaml
version = "0.6.1";
pname = "utoy";
license = pkgs.lib.licenses.mit;
src =
# We only need these files for building:
let
whitelist = [
./LICENSE
./utoy.cabal
./Setup.hs
./app
./src
./static
./test
];
in
pkgs.lib.sources.cleanSourceWith {
src = ./.;
filter = path: _type: pkgs.lib.any (prefix: pkgs.lib.hasPrefix (toString prefix) path) whitelist;
};
libraryHaskellDepends = haskellDeps haskellPackages;
}) {});
in { in {
packages.x86_64-linux = { packages.x86_64-linux = rec {
inherit ghc;
inherit stack;
docker = docker =
pkgs.dockerTools.buildImage { pkgs.dockerTools.buildImage {
name = "git.pbrinkmeier.de/paul/utoy"; name = "git.pbrinkmeier.de/paul/utoy";
tag = utoy.version; tag = utoy.version;
config.Cmd = [ "${utoy}/bin/utoy" ]; config.Cmd = [ "${pkgs.haskell.lib.justStaticExecutables utoy}/bin/utoy" ];
}; };
default = utoy; default = utoy;
}; };
devShells.x86_64-linux.default = pkgs.mkShell { devShells.x86_64-linux.default =
packages = [ (pkgs.haskellPackages.developPackage {
stack root = ./.;
ghc modifier = drv:
pkgs.haskell.lib.addBuildTools drv [
haskellPackages.haskell-language-server pkgs.cabal-install
haskellPackages.implicit-hie pkgs.haskellPackages.implicit-hie
pkgs.haskell-language-server
]; ];
shellHook = '' }).env;
PS1+="(utoy) ";
'';
};
}; };
} }

View File

@ -1,13 +0,0 @@
haskellPackages: with haskellPackages; [
attoparsec
blaze-html
bytestring
file-embed
http-media
servant-server
text
unicode-data
unicode-data-names
wai
warp
]

View File

@ -1,5 +0,0 @@
{
# GHC version to use with Nix.
# Should match the one in stack.yaml.
ghc = "ghc944";
}

View File

@ -1,70 +0,0 @@
# Adapted from new-template.hsfiles
name: utoy
# Keep this in sync with the version in flake.nix.
version: 0.6.1
git: "https://git.pbrinkmeier.de/paul/utoy"
license: MIT
author: "Paul Brinkmeier"
maintainer: "hallo@pbrinkmeier.de"
copyright: "2023 Paul Brinkmeier"
extra-source-files:
- README.md
- static/utoy.css
dependencies:
- base >= 4.7 && < 5
- attoparsec
- text
ghc-options:
- -Wall
- -Wcompat
- -Widentities
- -Wincomplete-record-updates
- -Wincomplete-uni-patterns
- -Wmissing-export-lists
- -Wmissing-home-modules
- -Wpartial-fields
- -Wredundant-constraints
library:
source-dirs: src
executables:
utoy:
main: Main.hs
source-dirs: app
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- utoy
- blaze-html
- bytestring
- file-embed
- http-media
- servant-server
- text
- unicode-data
- unicode-data-names
- wai
- warp
# Fix "Multiple files use the same module name", see
# https://stackoverflow.com/questions/67519851/multiple-files-use-the-same-module-name
when:
- condition: false
other-modules: Paths_utoy
tests:
utoy-test:
main: Spec.hs
source-dirs: test
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- utoy

View File

@ -1,5 +0,0 @@
# You can get a working environment using nix develop.
# Keep this in sync with nix/settings.nix
resolver: ghc-9.4.4
packages:
- .