From b347865025fe256a81d36b3faa1f3d651d4c36f5 Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Mon, 17 Jun 2024 13:09:57 -0400 Subject: [PATCH 1/6] Run niv init With niv-0.2.22 --- nix/sources.nix | 118 +++++++++++++++++++++++++++++------------------- 1 file changed, 71 insertions(+), 47 deletions(-) diff --git a/nix/sources.nix b/nix/sources.nix index 1938409..fe3dadf 100644 --- a/nix/sources.nix +++ b/nix/sources.nix @@ -10,29 +10,50 @@ let let name' = sanitizeName name + "-src"; in - if spec.builtin or true then - builtins_fetchurl { inherit (spec) url sha256; name = name'; } - else - pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; + if spec.builtin or true then + builtins_fetchurl { inherit (spec) url sha256; name = name'; } + else + pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; fetch_tarball = pkgs: name: spec: let name' = sanitizeName name + "-src"; in - if spec.builtin or true then - builtins_fetchTarball { name = name'; inherit (spec) url sha256; } - else - pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; + if spec.builtin or true then + builtins_fetchTarball { name = name'; inherit (spec) url sha256; } + else + pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; fetch_git = name: spec: let ref = - if spec ? ref then spec.ref else + spec.ref or ( if spec ? branch then "refs/heads/${spec.branch}" else - if spec ? tag then "refs/tags/${spec.tag}" else - abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"; + if spec ? tag then "refs/tags/${spec.tag}" else + abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!" + ); + submodules = spec.submodules or false; + submoduleArg = + let + nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; + emptyArgWithWarning = + if submodules + then + builtins.trace + ( + "The niv input \"${name}\" uses submodules " + + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " + + "does not support them" + ) + { } + else { }; + in + if nixSupportsSubmodules + then { inherit submodules; } + else emptyArgWithWarning; in - builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; }; + builtins.fetchGit + ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); fetch_local = spec: spec.path; @@ -66,16 +87,16 @@ let hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; hasThisAsNixpkgsPath = == ./.; in - if builtins.hasAttr "nixpkgs" sources - then sourcesNixpkgs - else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then - import {} - else - abort - '' - Please specify either (through -I or NIX_PATH=nixpkgs=...) or - add a package called "nixpkgs" to your sources.json. - ''; + if builtins.hasAttr "nixpkgs" sources + then sourcesNixpkgs + else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then + import { } + else + abort + '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; # The actual fetching function. fetch = pkgs: name: spec: @@ -95,13 +116,13 @@ let # the path directly as opposed to the fetched source. replace = name: drv: let - saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name; + saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; in - if ersatz == "" then drv else - # this turns the string into an actual Nix path (for both absolute and - # relative paths) - if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; + if ersatz == "" then drv else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; # Ports of functions for older nix versions @@ -112,7 +133,7 @@ let ); # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 - range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1); + range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); @@ -123,43 +144,46 @@ let concatStrings = builtins.concatStringsSep ""; # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 - optionalAttrs = cond: as: if cond then as else {}; + optionalAttrs = cond: as: if cond then as else { }; # fetchTarball version that is compatible between all the versions of Nix builtins_fetchTarball = { url, name ? null, sha256 }@attrs: let inherit (builtins) lessThan nixVersion fetchTarball; in - if lessThan nixVersion "1.12" then - fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - else - fetchTarball attrs; + if lessThan nixVersion "1.12" then + fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchTarball attrs; # fetchurl version that is compatible between all the versions of Nix builtins_fetchurl = { url, name ? null, sha256 }@attrs: let inherit (builtins) lessThan nixVersion fetchurl; in - if lessThan nixVersion "1.12" then - fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - else - fetchurl attrs; + if lessThan nixVersion "1.12" then + fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchurl attrs; # Create the final "sources" from the config mkSources = config: - mapAttrs ( - name: spec: - if builtins.hasAttr "outPath" spec - then abort - "The values in sources.json should not have an 'outPath' attribute" - else - spec // { outPath = replace name (fetch config.pkgs name spec); } - ) config.sources; + mapAttrs + ( + name: spec: + if builtins.hasAttr "outPath" spec + then + abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = replace name (fetch config.pkgs name spec); } + ) + config.sources; # The "config" used by the fetchers mkConfig = { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null - , sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile) + , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile) , system ? builtins.currentSystem , pkgs ? mkPkgs sources system }: rec { @@ -171,4 +195,4 @@ let }; in -mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); } +mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } From 2cb54bdc508f0b43cebc4df7764c8dabc7467bcb Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Mon, 17 Jun 2024 13:10:52 -0400 Subject: [PATCH 2/6] Bump to nixpkgs-24.05-darwin niv update nixpkgs --branch nixpkgs-24.05-darwin --- nix/sources.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nix/sources.json b/nix/sources.json index de78a73..7a5c4e8 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -12,15 +12,15 @@ "url_template": "https://github.com///archive/.tar.gz" }, "nixpkgs": { - "branch": "nixpkgs-20.09-darwin", + "branch": "nixpkgs-24.05-darwin", "description": "Nix Packages collection", "homepage": "", "owner": "NixOS", "repo": "nixpkgs", - "rev": "05f3800b80f159ee5ef0eccd8e31a645e6723feb", - "sha256": "0zx8xaa58ldvw1vw2gslnj0zldjvm2kryk3jdzv1j32m29v6302v", + "rev": "ecbc30d5ed9f75449233b17d4a4cdeab53af793f", + "sha256": "1541f6zlihqrzi3arw7r4vhmwcca1vig7v2nwpsyj4mcv6dzzdw6", "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/05f3800b80f159ee5ef0eccd8e31a645e6723feb.tar.gz", + "url": "https://github.com/NixOS/nixpkgs/archive/ecbc30d5ed9f75449233b17d4a4cdeab53af793f.tar.gz", "url_template": "https://github.com///archive/.tar.gz" } } From 9731072a3b6f5102d8e472d3c3d7374cdc631bb3 Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Mon, 17 Jun 2024 13:11:14 -0400 Subject: [PATCH 3/6] Bump niv --- nix/sources.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nix/sources.json b/nix/sources.json index 7a5c4e8..5def5ae 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -5,10 +5,10 @@ "homepage": "https://github.com/nmattia/niv", "owner": "nmattia", "repo": "niv", - "rev": "94080ae8286024820c570a2a24ed7c36d7ad04a9", - "sha256": "0wlk52zwlrq727x3z1vg9d9qq4zw62ab5jzg4068iqb6hyb0cr0w", + "rev": "f7c538837892dd2eb83567c9f380a11efb59b53f", + "sha256": "0xl33k24vfc29cg9lnp95kvcq69qbq5fzb7jk9ig4lgrhaarh651", "type": "tarball", - "url": "https://github.com/nmattia/niv/archive/94080ae8286024820c570a2a24ed7c36d7ad04a9.tar.gz", + "url": "https://github.com/nmattia/niv/archive/f7c538837892dd2eb83567c9f380a11efb59b53f.tar.gz", "url_template": "https://github.com///archive/.tar.gz" }, "nixpkgs": { From 043e2c82564f608d05ade51b48c1a470472bc48f Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Mon, 17 Jun 2024 13:13:53 -0400 Subject: [PATCH 4/6] Bump the upper bound on hakyll --- builder/haskell-org.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/haskell-org.cabal b/builder/haskell-org.cabal index 0077bf6..c288fdd 100644 --- a/builder/haskell-org.cabal +++ b/builder/haskell-org.cabal @@ -9,7 +9,7 @@ executable haskell-org-site main-is: site.hs other-modules: Testimonial build-depends: base == 4.* - , hakyll >=4.12 && <4.16 + , hakyll >=4.12 && <4.17 , aeson , binary , bytestring From 0b3266db0de766ba104a2ae865f8ef8c17c1d55d Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Mon, 17 Jun 2024 13:16:32 -0400 Subject: [PATCH 5/6] Add a cabal project --- cabal.project | 1 + 1 file changed, 1 insertion(+) create mode 100644 cabal.project diff --git a/cabal.project b/cabal.project new file mode 100644 index 0000000..7b08746 --- /dev/null +++ b/cabal.project @@ -0,0 +1 @@ +packages: builder From 9b78d27bc39c7de53fc87fdfd5845c57bad66fbf Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Mon, 17 Jun 2024 13:57:48 -0400 Subject: [PATCH 6/6] Update cabal build instructions using project - Add a note on builder package - Also mention cabal run as an option --- README.md | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 6babae7..4ccfa94 100644 --- a/README.md +++ b/README.md @@ -53,9 +53,20 @@ to review it as soon as we can. ### Working On The Builder The `builder` is the static site generator that turns the markdown files, CSS, -images, and scripts into a website. It lives in the `builder`. Most of the time, -you won't need to make changes to the builder and you can follow the -instructions in the _Contributing Changes_ section above. +images, and scripts into a website. + +> [!NOTE] +> The package in the builder folder has the `haskell-org-site` executable: +> ``` +> $ cat cabal.project +> packages: builder +> +> $ cat builder/haskell-org.cabal | grep executable +> executable haskell-org-site +> ``` + +Most of the time, you won't need to make changes to the builder and you can +follow the instructions in the _Contributing Changes_ section above. If you want to make a quick change or two, you can continue to use the `buildAndWatch` script to rebuild changes, but for more substantial changes this @@ -66,24 +77,20 @@ builder using either nix or cabal. Directions for both are given below: ### Manually Building the Site With Cabal If you don't have nix installed, or if you are inside of the project's nix -shell, you will want to use cabal to compile the builder. To do so, enter the -`builder` directory and compile the program with: +shell, use cabal to build and execute the builder, the only package in +the project. -```shell -cabal v2-build +``` +$ cabal build all +$ cabal exec haskell-org-site build ``` -Once compiled, the builder must be run from the project root directory so that -it can find all of the content. To run the builder, you need to first find the -name of the executable. From the builder directory, you can find the executable -path by running: +With `cabal run` we can do this in one command. ``` -cabal v2-exec -- which haskell-org-site +$ cabal run haskell-org-site -- build ``` -Using that path, you can run the builder from the project root directory. - ### Manually Building the Site With Nix If you have nix installed, you can have nix build the builder by running: