diff --git a/.envrc b/.envrc index b670d04fc..d9af6eae4 100644 --- a/.envrc +++ b/.envrc @@ -1,3 +1,5 @@ source_url https://raw.githubusercontent.com/juspay/omnix/22442f4c3907eae53f0fa0289d31fa359a2073c8/omnixrc 'sha256-wg6irSI4yxSJGheCNXVu7e2odD8myDqlVmpGnx+JYaM=' +watch_file nix/modules/flake-parts/*.nix + use omnix . diff --git a/flake.lock b/flake.lock index 0b334dfa5..ccaab83ec 100644 --- a/flake.lock +++ b/flake.lock @@ -223,11 +223,11 @@ "nixpkgs-lib": "nixpkgs-lib_2" }, "locked": { - "lastModified": 1725234343, - "narHash": "sha256-+ebgonl3NbiKD2UD0x4BszCZQ6sTfL4xioaM49o5B3Y=", + "lastModified": 1727826117, + "narHash": "sha256-K5ZLCyfO/Zj9mPFldf3iwS6oZStJcU4tSpiXTMYaaL0=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "567b938d64d4b4112ee253b9274472dc3a346eb6", + "rev": "3d04084d54bedc3d6b8b736c70ef449225c361b1", "type": "github" }, "original": { @@ -328,6 +328,21 @@ "type": "github" } }, + "nixos-unified": { + "locked": { + "lastModified": 1729549045, + "narHash": "sha256-W0VyC1MueUy6zMzcKZ9Ofnz/03da+SPFCYdbQ3MugfM=", + "owner": "srid", + "repo": "nixos-unified", + "rev": "09752a3c33541b7342416fb968c299c03c3e7e39", + "type": "github" + }, + "original": { + "owner": "srid", + "repo": "nixos-unified", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1704842529, @@ -364,14 +379,14 @@ }, "nixpkgs-lib_2": { "locked": { - "lastModified": 1725233747, - "narHash": "sha256-Ss8QWLXdr2JCBPcYChJhz4xJm+h/xjl4G0c0XlP6a74=", + "lastModified": 1727825735, + "narHash": "sha256-0xHYkMkeLVQAMa7gvkddbPqpxph+hDzdu1XdGPJR+Os=", "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/356624c12086a18f2ea2825fed34523d60ccc4e3.tar.gz" + "url": "https://github.com/NixOS/nixpkgs/archive/fb192fec7cc7a4c26d51779e9bab07ce6fa5597a.tar.gz" }, "original": { "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/356624c12086a18f2ea2825fed34523d60ccc4e3.tar.gz" + "url": "https://github.com/NixOS/nixpkgs/archive/fb192fec7cc7a4c26d51779e9bab07ce6fa5597a.tar.gz" } }, "nixpkgs_2": { @@ -400,6 +415,7 @@ "flake-root": "flake-root_2", "haskell-flake": "haskell-flake_2", "heist-extra": "heist-extra_2", + "nixos-unified": "nixos-unified", "nixpkgs": "nixpkgs_2", "systems": "systems_2", "treefmt-nix": "treefmt-nix_2", diff --git a/flake.nix b/flake.nix index 798cabb41..538e2af61 100644 --- a/flake.nix +++ b/flake.nix @@ -12,6 +12,7 @@ treefmt-nix.url = "github:numtide/treefmt-nix"; treefmt-nix.inputs.nixpkgs.follows = "nixpkgs"; flake-root.url = "github:srid/flake-root"; + nixos-unified.url = "github:srid/nixos-unified"; ema.url = "github:srid/ema"; ema.inputs.nixpkgs.follows = "nixpkgs"; @@ -35,174 +36,5 @@ emanote-template.flake = false; }; outputs = inputs: - inputs.flake-parts.lib.mkFlake { inherit inputs; } { - systems = import inputs.systems; - imports = [ - inputs.haskell-flake.flakeModule - inputs.flake-root.flakeModule - inputs.treefmt-nix.flakeModule - ./nix/flake-module.nix - ]; - - perSystem = { pkgs, lib, config, system, ... }: { - _module.args = import inputs.nixpkgs { - inherit system; - overlays = [ - (self: super: { - # Stork is marked as broken on intel mac, but it does work. - # Unfortunately we cannot test this code PATH due to lack of CI for intel mac (#335). - stork = if system == "x86_64-darwin" then super.stork.overrideAttrs (_oa: { meta.broken = false; }) else super.stork; - }) - ]; - }; - - # haskell-flake configuration - haskellProjects.default = { - projectFlakeName = "emanote"; - imports = [ - inputs.ema.haskellFlakeProjectModules.output - ]; - devShell.tools = hp: { - inherit (pkgs) - stork; - }; - autoWire = [ "packages" "apps" "checks" ]; - - packages = { - unionmount.source = inputs.unionmount; - commonmark-simple.source = inputs.commonmark-simple; - commonmark-wikilink.source = inputs.commonmark-wikilink; - fsnotify.source = "0.4.1.0"; # Not in nixpkgs, yet. - ghcid.source = "0.8.8"; - heist-extra.source = inputs.heist-extra; - }; - - settings = { - # Haskell packages in nixpkgs are often broken in many ways; ergo, - # it is our responsibility to fix them here. - fsnotify.check = false; - heist.broken = false; - ixset-typed.broken = false; - ixset-typed.jailbreak = true; - pandoc-link-context.broken = false; - pandoc-link-context.jailbreak = true; - tagtree.broken = false; - tagtree.jailbreak = true; - tailwind.broken = false; - tailwind.jailbreak = true; - unionmount.check = !pkgs.stdenv.isDarwin; # garnix: Slow M1 builder - emanote = { name, pkgs, self, super, ... }: { - check = false; - extraBuildDepends = [ pkgs.stork ]; - separateBinOutput = false; # removeReferencesTo.nix doesn't work otherwise - justStaticExecutables = true; - removeReferencesTo = [ - self.pandoc - self.pandoc-types - self.warp - ]; - custom = pkg: pkg.overrideAttrs (lib.addMetaAttrs { - # https://github.com/NixOS/cabal2nix/issues/608 - longDescription = '' - Emanote is a tool for generating a structured view of your - plain-text notes on the web, as a statically generated - website as well as a local live server. - - For editing notes, you can use any text editor of your - choice including the likes of Obsidian. - ''; - }); - }; - }; - }; - - # Autoformatter configuration: https://nixos.asia/en/treefmt - treefmt.config = { - inherit (config.flake-root) projectRootFile; - package = pkgs.treefmt; - - programs.ormolu.enable = true; - programs.nixpkgs-fmt.enable = true; - programs.cabal-fmt.enable = true; - programs.hlint.enable = true; - - # We use fourmolu - programs.ormolu.package = pkgs.haskellPackages.fourmolu; - settings.formatter.ormolu = { - options = [ - "--ghc-opt" - "-XImportQualifiedPost" - "--ghc-opt" - "-XTypeApplications" - ]; - }; - }; - - packages.default = config.packages.emanote; - apps.default = config.apps.emanote; - devShells.default = - lib.addMetaAttrs { description = "Emanote development environment"; } - (pkgs.mkShell { - name = "emanote-dev"; - inputsFrom = [ - config.haskellProjects.default.outputs.devShell - config.treefmt.build.devShell - ]; - packages = with pkgs; [ - just - ]; - }); - - apps.check-closure-size = rec { - inherit (program) meta; - program = pkgs.writeShellApplication { - name = "emanote-check-closure-size"; - runtimeInputs = [ pkgs.jq pkgs.bc pkgs.nix ]; - meta.description = "Check that emanote's nix closure size remains reasonably small"; - text = '' - MAX_CLOSURE_SIZE=$(echo "600 * 1000000" | bc) - CLOSURE_SIZE=$(nix path-info --json -S .#default | jq '.[0]'.closureSize) - echo "Emanote closure size: $CLOSURE_SIZE" - echo " Max closure size: $MAX_CLOSURE_SIZE" - if [ "$CLOSURE_SIZE" -gt "$MAX_CLOSURE_SIZE" ]; then - echo "ERROR: Emanote's nix closure size has increased" - exit 3 - else - echo "OK: Emanote's nix closure size is within limits" - fi - ''; - }; - }; - - emanote = { - package = config.packages.default; - sites = { - "docs" = { - layers = [{ path = ./docs; pathString = "./docs"; }]; - allowBrokenLinks = true; # A couple, by design, in markdown.md - prettyUrls = true; - }; - }; - }; - }; - flake = { - homeManagerModule = import ./nix/home-manager-module.nix; - flakeModule = ./nix/flake-module.nix; - templates.default = { - description = "A simple flake.nix template for emanote notebooks"; - path = builtins.path { path = inputs.emanote-template; filter = path: _: baseNameOf path == "flake.nix"; }; - }; - om.ci.default = { - emanote = { - dir = "."; - steps.custom = { - closure-size = { - type = "app"; - name = "check-closure-size"; - }; - }; - }; - }; - }; - }; + inputs.nixos-unified.lib.mkFlake { inherit inputs; root = ./.; }; } diff --git a/nix/flake-module.nix b/nix/modules/flake-parts/flake-module.nix similarity index 99% rename from nix/flake-module.nix rename to nix/modules/flake-parts/flake-module.nix index 1d360b0f2..fa6192610 100644 --- a/nix/flake-module.nix +++ b/nix/modules/flake-parts/flake-module.nix @@ -1,5 +1,5 @@ # A flake-parts module for building and running Emanote sites -{ self, config, lib, flake-parts-lib, ... }: +{ lib, flake-parts-lib, ... }: let inherit (flake-parts-lib) diff --git a/nix/modules/flake-parts/haskell.nix b/nix/modules/flake-parts/haskell.nix new file mode 100644 index 000000000..72a57cb09 --- /dev/null +++ b/nix/modules/flake-parts/haskell.nix @@ -0,0 +1,171 @@ +{ root, inputs, ... }: +{ + imports = [ + inputs.haskell-flake.flakeModule + inputs.flake-root.flakeModule + inputs.treefmt-nix.flakeModule + ]; + + perSystem = { pkgs, lib, config, system, ... }: { + _module.args = import inputs.nixpkgs { + inherit system; + overlays = [ + (self: super: { + # Stork is marked as broken on intel mac, but it does work. + # Unfortunately we cannot test this code PATH due to lack of CI for intel mac (#335). + stork = if system == "x86_64-darwin" then super.stork.overrideAttrs (_oa: { meta.broken = false; }) else super.stork; + }) + ]; + }; + + # haskell-flake configuration + haskellProjects.default = { + projectFlakeName = "emanote"; + projectRoot = root; + imports = [ + inputs.ema.haskellFlakeProjectModules.output + ]; + devShell.tools = hp: { + inherit (pkgs) + stork; + }; + autoWire = [ "packages" "apps" "checks" ]; + packages = { + unionmount.source = inputs.unionmount; + commonmark-simple.source = inputs.commonmark-simple; + commonmark-wikilink.source = inputs.commonmark-wikilink; + fsnotify.source = "0.4.1.0"; # Not in nixpkgs, yet. + ghcid.source = "0.8.8"; + heist-extra.source = inputs.heist-extra; + }; + + settings = { + # Haskell packages in nixpkgs are often broken in many ways; ergo, + # it is our responsibility to fix them here. + fsnotify.check = false; + heist.broken = false; + ixset-typed.broken = false; + ixset-typed.jailbreak = true; + pandoc-link-context.broken = false; + pandoc-link-context.jailbreak = true; + tagtree.broken = false; + tagtree.jailbreak = true; + tailwind.broken = false; + tailwind.jailbreak = true; + unionmount.check = !pkgs.stdenv.isDarwin; # garnix: Slow M1 builder + emanote = { name, pkgs, self, super, ... }: { + check = false; + extraBuildDepends = [ pkgs.stork ]; + separateBinOutput = false; # removeReferencesTo.nix doesn't work otherwise + justStaticExecutables = true; + removeReferencesTo = [ + self.pandoc + self.pandoc-types + self.warp + ]; + custom = pkg: pkg.overrideAttrs (lib.addMetaAttrs { + # https://github.com/NixOS/cabal2nix/issues/608 + longDescription = '' + Emanote is a tool for generating a structured view of your + plain-text notes on the web, as a statically generated + website as well as a local live server. + + For editing notes, you can use any text editor of your + choice including the likes of Obsidian. + ''; + }); + }; + }; + }; + + # Autoformatter configuration: https://nixos.asia/en/treefmt + treefmt.config = { + inherit (config.flake-root) projectRootFile; + package = pkgs.treefmt; + + programs.ormolu.enable = true; + programs.nixpkgs-fmt.enable = true; + programs.cabal-fmt.enable = true; + programs.hlint.enable = true; + + # We use fourmolu + programs.ormolu.package = pkgs.haskellPackages.fourmolu; + settings.formatter.ormolu = { + options = [ + "--ghc-opt" + "-XImportQualifiedPost" + "--ghc-opt" + "-XTypeApplications" + ]; + }; + }; + + packages.default = config.packages.emanote; + apps.default = config.apps.emanote; + devShells.default = + lib.addMetaAttrs { description = "Emanote development environment"; } + (pkgs.mkShell { + name = "emanote-dev"; + inputsFrom = [ + config.haskellProjects.default.outputs.devShell + config.treefmt.build.devShell + ]; + packages = with pkgs; [ + just + ]; + }); + + apps.check-closure-size = rec { + inherit (program) meta; + program = pkgs.writeShellApplication { + name = "emanote-check-closure-size"; + runtimeInputs = [ pkgs.jq pkgs.bc pkgs.nix ]; + meta.description = "Check that emanote's nix closure size remains reasonably small"; + text = '' + MAX_CLOSURE_SIZE=$(echo "600 * 1000000" | bc) + CLOSURE_SIZE=$(nix path-info --json -S .#default | jq '.[0]'.closureSize) + echo "Emanote closure size: $CLOSURE_SIZE" + echo " Max closure size: $MAX_CLOSURE_SIZE" + if [ "$CLOSURE_SIZE" -gt "$MAX_CLOSURE_SIZE" ]; then + echo "ERROR: Emanote's nix closure size has increased" + exit 3 + else + echo "OK: Emanote's nix closure size is within limits" + fi + ''; + }; + }; + + emanote = { + package = config.packages.default; + sites = { + "docs" = { + layers = [{ path = ./docs; pathString = "./docs"; }]; + allowBrokenLinks = true; # A couple, by design, in markdown.md + prettyUrls = true; + }; + }; + }; + + }; + + flake = { + homeManagerModule = import (root + /nix/home-manager-module.nix); + flakeModule = (root + /nix/flake-module.nix); + templates.default = { + description = "A simple flake.nix template for emanote notebooks"; + path = builtins.path { path = inputs.emanote-template; filter = path: _: baseNameOf path == "flake.nix"; }; + }; + om.ci.default = { + emanote = { + dir = "."; + steps.custom = { + closure-size = { + type = "app"; + name = "check-closure-size"; + }; + }; + }; + }; + }; +}