{ description = "sourcephile.fr website"; inputs = { nixpkgs.url = "flake:nixpkgs"; #ema.url = "path:/home/julm/src/haskell/ema/ema"; ema.url = "github:srid/ema/89c9f9234c47437513774efa7e24ef0bdd6427bb"; ema.inputs.nixpkgs.follows = "nixpkgs"; ema.inputs.pre-commit-hooks.follows = "pre-commit-hooks"; ema.inputs.url-slug.follows = "url-slug"; url-slug.url = "github:srid/url-slug"; url-slug.inputs.nixpkgs.follows = "nixpkgs"; commonmark-simple.url = "github:srid/commonmark-simple"; commonmark-simple.inputs.nixpkgs.follows = "nixpkgs"; unionmount.url = "github:srid/unionmount"; unionmount.inputs.nixpkgs.follows = "nixpkgs"; pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs"; pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix"; PyF.url = "github:guibou/PyF/main"; PyF.inputs.nixpkgs.follows = "nixpkgs"; open-iconic.url = "github:iconic/open-iconic"; open-iconic.flake = false; windiCSS = { url = "github:srid/windicss-nix"; flake = false; }; # .git/ is needed by the generator to use git log selfGit.url = "path:/home/julm/work/sourcephile/haskell/sourcephile-web/.git"; selfGit.flake = false; tailwind-haskell.url = "github:srid/tailwind-haskell/master"; tailwind-haskell.inputs.nixpkgs.follows = "nixpkgs"; tailwind-haskell.inputs.flake-utils.follows = "ema/flake-utils"; tailwind-haskell.inputs.flake-compat.follows = "ema/flake-compat"; }; outputs = inputs: let lib = inputs.nixpkgs.lib; forAllSystems = f: lib.genAttrs lib.systems.flakeExposed (system: f rec { inherit system; pkgs = inputs.nixpkgs.legacyPackages.${system}; haskellPackages = pkgs.haskellPackages/*.packages.ghc901*/.extend (with pkgs.haskell.lib; hfinal: hprev: { # ${pkg} = buildFromSdist (hprev.callCabal2nix pkg ./. {}); generator = hprev.callCabal2nix "generator" ./generator { }; ema = disableCabalFlag inputs.ema.defaultPackage.${system} "with-examples"; tailwind = inputs.tailwind-haskell.defaultPackage.${system}; url-slug = inputs.url-slug.defaultPackage.${system}; commonmark-simple = inputs.commonmark-simple.defaultPackage.${system}; unionmount = inputs.unionmount.defaultPackage.${system}; PyF = inputs.PyF.defaultPackage.${system}; #thumbnail-plus = doJailbreak (unmarkBroken hprev.thumbnail-plus); thumbnail-plus = buildFromSdist (hprev.callCabal2nix "thumbnail-plus" (pkgs.fetchFromGitHub { owner = "abhin4v"; repo = "thumbnail-plus"; rev = "fc10600d3af19ccce7c69416e2ec33143faa4d37"; sha256 = "sha256-lhkhd7pSDq1AhF6jAnWl0at7s4RQvuW+nDjboA3W0D4="; }) { }); }); windiCSS = (import inputs.windiCSS { inherit pkgs; }).shell.nodeDependencies; tailwindCSS = pkgs.fetchurl { url = "https://unpkg.com/tailwindcss@2/dist/tailwind.css"; sha256 = "sha256-3jBdkj3eH4VZ53NLsfAZcK86du/IRLlMo8hIj+qNo/c="; #url = "https://unpkg.com/tailwindcss@2/dist/tailwind.min.css"; #sha256 = "sha256-tq2XQC7duQPnpdenPuR6Z5IE773aRSGjkcutnfUJuTI="; }; windiCSS-extras = pkgs.runCommand "windi-extras.css" { } '' ${windiCSS}/bin/windicss ${generator/css/windi-extras.html} -o $out ''; watch-site = pkgs.writeShellScriptBin "watch-site" '' set -eux mkdir -p content/static/icons # FIXME: unfortunately browsers may not invalidate their caching for those .css ln -fns ${tailwindCSS} content/static/css/windi.css ln -fns ${windiCSS-extras} content/static/css/windi-extras.css ln -fns ${inputs.open-iconic} content/static/icons/open-iconic exec ${pkgs.ghcid}/bin/ghcid --no-height-limit --reverse-errors -C generator --warnings \ -T "System.Directory.withCurrentDirectory \"../content\" Main.main" ''; }); in rec { # nix -L build defaultPackage = forAllSystems (args: with args; packages.${system}.website); packages = forAllSystems (args: with args; rec { inherit (haskellPackages) generator; generated = pkgs.runCommand "generated" { LOCALE_ARCHIVE = "${pkgs.glibcLocales}/lib/locale/locale-archive"; LC_ALL = "fr_FR.UTF-8"; } '' set -eux PATH="${lib.makeBinPath [pkgs.git]}:$PATH" echo >.git "gitdir: ${inputs.selfGit}" cp -r --no-preserve=mode -s ${./content}/* . ln -fns ${windiCSS-extras} static/css/windi-extras.css rm -rf static/icons/open-iconic echo >lastModified ${toString inputs.self.lastModified} mkdir $out ${generator}/bin/generator gen $out mkdir -p $out/static/icons ln -s ${inputs.open-iconic} $out/static/icons/open-iconic ''; # Produce a CSS file that contains only the WindiCSS styles # in use by the generated HTML files. windicss = pkgs.runCommand "windi.css" { } '' ${windiCSS}/bin/windicss '${generated}/**/*.html' -o $out --preflight --minify ''; website = pkgs.runCommand "website" { } '' set -eux # Copy because HTML files will be modified cp -r --no-preserve=mode ${generated} $out # Name with a hash to invalidate browser's cache if the CSS has changed cssHash=$(md5sum ${windicss} | cut -f 1 -d ' ') mkdir -p $out/static/css ln -s ${windicss} $out/static/css/windi.$cssHash.css # Retroactively replace the CSS with the minified CSS find $out -iname "*.html" -exec \ sed -i "s|/static/css/windi.css|/static/css/windi.$cssHash.css|" {} + ''; }); # direnv allow devShell = forAllSystems (args: with args; haskellPackages.shellFor { packages = ps: [ ps.generator ]; nativeBuildInputs = with haskellPackages; [ cabal-fmt cabal-install fourmolu ghcid haskell-language-server pkgs.git-chglog pkgs.reuse windiCSS watch-site ]; inherit (checks.${system}.pre-commit-check) shellHook; #withHoogle = true; }); # nix flake check checks = forAllSystems (args: with args; { pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run { src = ./.; settings.ormolu.defaultExtensions = [ "ImportQualifiedPost" "TypeApplications" ]; hooks = { hlint.enable = true; nixpkgs-fmt.enable = true; fourmolu.enable = true; cabal-fmt.enable = true; }; }; }); # nix run .#watch defaultApp = apps.watch; apps = forAllSystems (args: with args; { watch = { type = "app"; program = watch-site + "/bin/watch-site"; }; hoogle = { type = "app"; program = (pkgs.writeShellScript "hoogle-server" ''exec hoogle server --local --links -p 8080'').outPath; }; }); }; }