diff --git a/.gitignore b/.gitignore index 02d0da7e1b..c7f9c8b3aa 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ /public/guides/nix-pills/ /public/demos/*.cast /public/demos/*.svg + +.pre-commit-config.yaml \ No newline at end of file diff --git a/flake.lock b/flake.lock index 53e0e0a3ac..d327e21fad 100644 --- a/flake.lock +++ b/flake.lock @@ -32,7 +32,41 @@ "type": "github" } }, + "flake-compat_3": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1733312601, + "narHash": "sha256-4pDvzqnegAfRkPwO3wmwBhVi/Sye1mzps0zHWYnP88c=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "205b12d8b7cd4802fbcb8e8ef6a0f1408781a4f9", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-parts_2": { "inputs": { "nixpkgs-lib": [ "released-nix-stable", @@ -53,7 +87,7 @@ "type": "github" } }, - "flake-parts_2": { + "flake-parts_3": { "inputs": { "nixpkgs-lib": [ "released-nix-unstable", @@ -74,25 +108,28 @@ "type": "github" } }, - "flake-utils": { + "git-hooks-nix": { "inputs": { - "systems": "systems" + "flake-compat": "flake-compat", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs", + "nixpkgs-stable": "nixpkgs-stable" }, "locked": { - "lastModified": 1731533236, - "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "lastModified": 1733665616, + "narHash": "sha256-+XTFXYlFJBxohhMGLDpYdEnhUNdxN8dyTA8WAd+lh2A=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "d8c02f0ffef0ef39f6063731fc539d8c71eb463a", "type": "github" }, "original": { - "owner": "numtide", - "repo": "flake-utils", + "owner": "cachix", + "repo": "git-hooks.nix", "type": "github" } }, - "git-hooks-nix": { + "git-hooks-nix_2": { "inputs": { "flake-compat": [ "released-nix-stable" @@ -123,7 +160,7 @@ "type": "github" } }, - "git-hooks-nix_2": { + "git-hooks-nix_3": { "inputs": { "flake-compat": [ "released-nix-unstable" @@ -154,6 +191,27 @@ "type": "github" } }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "git-hooks-nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, "libgit2": { "flake": false, "locked": { @@ -206,17 +264,18 @@ }, "nixpkgs": { "locked": { - "lastModified": 1733392399, - "narHash": "sha256-kEsTJTUQfQFIJOcLYFt/RvNxIK653ZkTBIs4DG+cBns=", + "lastModified": 1730768919, + "narHash": "sha256-8AKquNnnSaJRXZxc5YmF/WfmxiHX6MMZZasRP6RRQkE=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "d0797a04b81caeae77bcff10a9dde78bc17f5661", + "rev": "a04d33c0c3f1a59a2c1cb0c6e34cd24500e5a1dc", "type": "github" }, "original": { - "id": "nixpkgs", - "ref": "nixos-unstable", - "type": "indirect" + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" } }, "nixpkgs-23-11": { @@ -251,6 +310,18 @@ "type": "github" } }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1733096140, + "narHash": "sha256-1qRH7uAUsyQI7R1Uwl4T+XvdNv778H0Nb5njNrqvylY=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/5487e69da40cbd611ab2cadee0b4637225f7cfae.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/5487e69da40cbd611ab2cadee0b4637225f7cfae.tar.gz" + } + }, "nixpkgs-regression": { "locked": { "lastModified": 1643052045, @@ -283,7 +354,38 @@ "type": "github" } }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1730741070, + "narHash": "sha256-edm8WG19kWozJ/GqyYx2VjW99EdhjKwbY3ZwdlPAAlo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "d063c1dd113c91ab27959ba540c0d9753409edf3", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, "nixpkgs_2": { + "locked": { + "lastModified": 1733759999, + "narHash": "sha256-463SNPWmz46iLzJKRzO3Q2b0Aurff3U1n0nYItxq7jU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a73246e2eef4c6ed172979932bc80e1404ba2d56", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" + } + }, + "nixpkgs_3": { "locked": { "lastModified": 1723688146, "narHash": "sha256-sqLwJcHYeWLOeP/XoLwAtYjr01TISlkOfz+NG82pbdg=", @@ -299,7 +401,7 @@ "type": "github" } }, - "nixpkgs_3": { + "nixpkgs_4": { "locked": { "lastModified": 1723688146, "narHash": "sha256-sqLwJcHYeWLOeP/XoLwAtYjr01TISlkOfz+NG82pbdg=", @@ -317,11 +419,11 @@ }, "released-nix-stable": { "inputs": { - "flake-compat": "flake-compat", - "flake-parts": "flake-parts", - "git-hooks-nix": "git-hooks-nix", + "flake-compat": "flake-compat_2", + "flake-parts": "flake-parts_2", + "git-hooks-nix": "git-hooks-nix_2", "libgit2": "libgit2", - "nixpkgs": "nixpkgs_2", + "nixpkgs": "nixpkgs_3", "nixpkgs-23-11": "nixpkgs-23-11", "nixpkgs-regression": "nixpkgs-regression" }, @@ -342,20 +444,20 @@ }, "released-nix-unstable": { "inputs": { - "flake-compat": "flake-compat_2", - "flake-parts": "flake-parts_2", - "git-hooks-nix": "git-hooks-nix_2", + "flake-compat": "flake-compat_3", + "flake-parts": "flake-parts_3", + "git-hooks-nix": "git-hooks-nix_3", "libgit2": "libgit2_2", - "nixpkgs": "nixpkgs_3", + "nixpkgs": "nixpkgs_4", "nixpkgs-23-11": "nixpkgs-23-11_2", "nixpkgs-regression": "nixpkgs-regression_2" }, "locked": { - "lastModified": 1733445459, - "narHash": "sha256-9eBrtoAl0zS7KuMfVkQvDnjnd4HdKKQ+PpT3d5WECQs=", + "lastModified": 1733942771, + "narHash": "sha256-jf/spBGNd11tnS7rQimgDuQmAHDzLUK3evUm1n3VD1Y=", "owner": "nixos", "repo": "nix", - "rev": "ab5a9cf2db31d3840a801385349b9d23deb29ecc", + "rev": "be04e68b3472f188ddd56f99fbdac0f04ce914e8", "type": "github" }, "original": { @@ -367,11 +469,11 @@ }, "released-nixpkgs-stable": { "locked": { - "lastModified": 1733412085, - "narHash": "sha256-FillH0qdWDt/nlO6ED7h4cmN+G9uXwGjwmCnHs0QVYM=", + "lastModified": 1733808091, + "narHash": "sha256-KWwINTQelKOoQgrXftxoqxmKFZb9pLVfnRvK270nkVk=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "4dc2fc4e62dbf62b84132fe526356fbac7b03541", + "rev": "a0f3e10d94359665dba45b71b4227b0aeb851f8e", "type": "github" }, "original": { @@ -382,11 +484,11 @@ }, "released-nixpkgs-unstable": { "locked": { - "lastModified": 1733392399, - "narHash": "sha256-kEsTJTUQfQFIJOcLYFt/RvNxIK653ZkTBIs4DG+cBns=", + "lastModified": 1733759999, + "narHash": "sha256-463SNPWmz46iLzJKRzO3Q2b0Aurff3U1n0nYItxq7jU=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "d0797a04b81caeae77bcff10a9dde78bc17f5661", + "rev": "a73246e2eef4c6ed172979932bc80e1404ba2d56", "type": "github" }, "original": { @@ -397,13 +499,15 @@ }, "root": { "inputs": { - "flake-utils": "flake-utils", + "flake-parts": "flake-parts", + "git-hooks-nix": "git-hooks-nix", "nix-pills": "nix-pills", - "nixpkgs": "nixpkgs", + "nixpkgs": "nixpkgs_2", "released-nix-stable": "released-nix-stable", "released-nix-unstable": "released-nix-unstable", "released-nixpkgs-stable": "released-nixpkgs-stable", - "released-nixpkgs-unstable": "released-nixpkgs-unstable" + "released-nixpkgs-unstable": "released-nixpkgs-unstable", + "systems": "systems" } }, "systems": { @@ -416,9 +520,8 @@ "type": "github" }, "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" + "id": "systems", + "type": "indirect" } } }, diff --git a/flake.nix b/flake.nix index f13c583f7b..c72ca2b3e9 100644 --- a/flake.nix +++ b/flake.nix @@ -4,7 +4,8 @@ rec { inputs = { # This is used to build the site. nixpkgs.url = "nixpkgs/nixos-unstable"; - flake-utils.url = "github:numtide/flake-utils"; + flake-parts.url = "github:hercules-ci/flake-parts"; + git-hooks-nix.url = "github:cachix/git-hooks.nix"; # These inputs are used for the manuals and release artifacts released-nixpkgs-unstable.url = "nixpkgs/nixos-unstable"; @@ -27,206 +28,267 @@ rec { }; outputs = - { self - , nixpkgs - , flake-utils - , released-nixpkgs-unstable - , released-nixpkgs-stable - , released-nix-unstable - , released-nix-stable - , nix-pills + inputs@{ + self, + flake-parts, + git-hooks-nix, + nixpkgs, + released-nixpkgs-unstable, + released-nixpkgs-stable, + released-nix-unstable, + released-nix-stable, + nix-pills, + systems, }: - flake-utils.lib.eachDefaultSystem (system: - let - overlay = final: prev: { - asciinema-scenario = final.rustPlatform.buildRustPackage rec { - pname = "asciinema-scenario"; - version = "0.2.0"; - src = final.fetchCrate { - inherit pname version; - sha256 = "sha256-qMGi+myppWBapM7TkPeXC2g/M1FA1YGwESNrx8LVXkw="; + flake-parts.lib.mkFlake { inherit inputs; } { + imports = [ + inputs.git-hooks-nix.flakeModule + ]; + systems = import systems; + perSystem = + { config, system, ... }: + let + overlay = final: prev: { + asciinema-scenario = final.rustPlatform.buildRustPackage rec { + pname = "asciinema-scenario"; + version = "0.2.0"; + src = final.fetchCrate { + inherit pname version; + sha256 = "sha256-qMGi+myppWBapM7TkPeXC2g/M1FA1YGwESNrx8LVXkw="; + }; + cargoSha256 = "0z4iwjm38xfgipl1pcrkl8277p627pls565k7cclrhxfcx3f513p"; }; - cargoSha256 = "0z4iwjm38xfgipl1pcrkl8277p627pls565k7cclrhxfcx3f513p"; }; - }; - pkgs = import nixpkgs { inherit system; overlays = [ overlay ]; }; - inherit (pkgs.lib) getVersion; + pkgs = import nixpkgs { + inherit system; + overlays = [ overlay ]; + }; + inherit (pkgs.lib) getVersion; - pkgs-unstable = import released-nixpkgs-unstable { inherit system; }; - pkgs-stable = import released-nixpkgs-stable { inherit system; }; + pkgs-unstable = import released-nixpkgs-unstable { inherit system; }; + pkgs-stable = import released-nixpkgs-stable { inherit system; }; - nix_stable = released-nix-stable.packages."${system}".nix; - nix_unstable = released-nix-unstable.packages."${system}".nix; + nix_stable = released-nix-stable.packages."${system}".nix; + nix_unstable = released-nix-unstable.packages."${system}".nix; - nixPills = import nix-pills { - inherit pkgs; - }; + nodejs_current = pkgs.nodejs_20; + + nixPills = import nix-pills { + inherit pkgs; + }; + + # TODO: change structure to conform to ./src/content/download/aws-ec2.yaml but in json + NIXOS_AMIS = pkgs.writeText "ec2-amis.json" ( + builtins.toJSON (import (released-nixpkgs-stable + "/nixos/modules/virtualisation/ec2-amis.nix")) + ); + + NIX_STABLE_VERSION = getVersion nix_stable.name; + NIX_UNSTABLE_VERSION = getVersion nix_unstable.name; + NIXOS_STABLE_SERIES = pkgs-stable.lib.trivial.release; + NIXOS_UNSTABLE_SERIES = pkgs-unstable.lib.trivial.release; + + redirectManualHTML = redirectURL: out: '' + cat < ${out} + + + + + + +

Redirecting...

+

Please follow this link.

+ + + EOT + ''; + manualVersionSwitch = + dir: canonical: + let + baseUrl = "https://nixos.org/${dir}/${canonical}"; + in + '' + project=$(basename ${dir}) + # loop over each channel/version + for path in ${dir}/*; do + # loop over each html file + (cd $path && find -type f -print) | while read htmlFile; do + if [[ "$htmlFile" == *.html ]]; then + fileName=''${htmlFile#"./"} + filePath="$path/$fileName" + echo "Patching $fileName" + echo "Patching $filePath" - # TODO: change structure to conform to ./src/content/download/aws-ec2.yaml but in json - NIXOS_AMIS = pkgs.writeText "ec2-amis.json" - (builtins.toJSON ( - import (released-nixpkgs-stable + "/nixos/modules/virtualisation/ec2-amis.nix"))); - - NIX_STABLE_VERSION = getVersion nix_stable.name; - NIX_UNSTABLE_VERSION = getVersion nix_unstable.name; - NIXOS_STABLE_SERIES = pkgs-stable.lib.trivial.release; - NIXOS_UNSTABLE_SERIES = pkgs-unstable.lib.trivial.release; - - redirectManualHTML = redirectURL: out: '' - cat < ${out} - - - - - - -

Redirecting...

-

Please follow this link.

- - - EOT - ''; - - manualVersionSwitch = dir: canonical: - let - baseUrl = "https://nixos.org/${dir}/${canonical}"; - in '' - project=$(basename ${dir}) - # loop over each channel/version - for path in ${dir}/*; do - # loop over each html file - (cd $path && find -type f -print) | while read htmlFile; do - if [[ "$htmlFile" == *.html ]]; then - fileName=''${htmlFile#"./"} - filePath="$path/$fileName" - echo "Patching $fileName" - echo "Patching $filePath" - - canonicalFileName="${dir}/${canonical}/$fileName" - canonicalUrl=$baseUrl - if [ -e $canonicalFileName ]; then - if [ "$fileName" != "index.html" ]; then - canonicalUrl="$baseUrl/$fileName" + canonicalFileName="${dir}/${canonical}/$fileName" + canonicalUrl=$baseUrl + if [ -e $canonicalFileName ]; then + if [ "$fileName" != "index.html" ]; then + canonicalUrl="$baseUrl/$fileName" + fi + fi + canonicalTag="" + if ! grep -Fq "$canonicalTag" $filePath; then + sed -i -e "s|| $canonicalTag\n|" $filePath + echo "Patched of $filePath." + fi + + injectedTag="" + if ! grep -Fq "$injectedTag" $filePath; then + sed -i -e "s||\n $injectedTag\n|" $filePath + echo "Injected channel switcher for $filePath." + fi + + injectedTag="data-$project-channels='[" + if [[ "$project" == "nix" ]]; then + injectedTag+="{\"channel\":\"unstable\",\"version\":\"${NIX_UNSTABLE_VERSION}\"}," + injectedTag+="{\"channel\":\"stable\",\"version\":\"${NIX_STABLE_VERSION}\"}" + else + injectedTag+="{\"channel\":\"unstable\",\"version\":\"${NIXOS_UNSTABLE_SERIES}\"}," + injectedTag+="{\"channel\":\"stable\",\"version\":\"${NIXOS_STABLE_SERIES}\"}" + fi + injectedTag+="]'" + if ! grep -Fq "$injectedTag" $filePath; then + sed -i -e "s|" - if ! grep -Fq "$canonicalTag" $filePath; then - sed -i -e "s|| $canonicalTag\n|" $filePath - echo "Patched of $filePath." - fi - - injectedTag="" - if ! grep -Fq "$injectedTag" $filePath; then - sed -i -e "s||\n $injectedTag\n|" $filePath - echo "Injected channel switcher for $filePath." - fi - - injectedTag="data-$project-channels='[" - if [[ "$project" == "nix" ]]; then - injectedTag+="{\"channel\":\"unstable\",\"version\":\"${NIX_UNSTABLE_VERSION}\"}," - injectedTag+="{\"channel\":\"stable\",\"version\":\"${NIX_STABLE_VERSION}\"}" - else - injectedTag+="{\"channel\":\"unstable\",\"version\":\"${NIXOS_UNSTABLE_SERIES}\"}," - injectedTag+="{\"channel\":\"stable\",\"version\":\"${NIXOS_STABLE_SERIES}\"}" - fi - injectedTag+="]'" - if ! grep -Fq "$injectedTag" $filePath; then - sed -i -e "s| $scenarioFileName.cast - # XXX: this in until asciinema-scenario is fixed - # https://github.com/garbas/asciinema-scenario/issues/3 - sed -i -e "s|&2 << EOF - To fetch all dependencies: - npm install - - Afterwards, to start a local development server: - npm run dev - - Then go to the following URL in your browser: - http://localhost:4321 - - It will rebuild the website on each change. - - To test redirects: - npm run build - cd dist - netlify dev - - To re-format the source code: - npm run format - EOF + done + done + ''; + + manuals = + pkgs.runCommand "manuals" + { + nativeBuildInputs = with pkgs; [ + gnused + gnugrep + ]; + } + '' + mkdir -p $out + ${redirectManualHTML "/learn" "$out/index.html"} + + nix_dir=$PWD/nix && mkdir -p $nix_dir + cp -R --no-preserve=mode,ownership ${nix_stable.doc}/share/doc/nix/manual $nix_dir/stable + cp -R --no-preserve=mode,ownership ${nix_unstable.doc}/share/doc/nix/manual $nix_dir/unstable + ${manualVersionSwitch "$nix_dir" "stable"} + ${redirectManualHTML "/manual/nix/stable" "$nix_dir/index.html"} + mv $nix_dir $out + + nixpkgs_dir=$PWD/nixpkgs && mkdir -p $nixpkgs_dir + cp -R --no-preserve=mode,ownership ${ + released-nixpkgs-stable.htmlDocs.nixpkgsManual.${system} + }/share/doc/nixpkgs $nixpkgs_dir/stable + cp -R --no-preserve=mode,ownership ${ + released-nixpkgs-unstable.htmlDocs.nixpkgsManual.${system} + }/share/doc/nixpkgs $nixpkgs_dir/unstable + mv $nixpkgs_dir/stable/manual.html $nixpkgs_dir/stable/index.html + mv $nixpkgs_dir/unstable/manual.html $nixpkgs_dir/unstable/index.html + ${manualVersionSwitch "$nixpkgs_dir" "stable"} + ${redirectManualHTML "/manual/nixpkgs/stable" "$nixpkgs_dir/index.html"} + mv $nixpkgs_dir $out + + nixos_dir=$PWD/nixos && mkdir -p $nixos_dir + cp -R --no-preserve=mode,ownership ${ + released-nixpkgs-stable.htmlDocs.nixosManual.${system} + }/share/doc/nixos $nixos_dir/stable + cp -R --no-preserve=mode,ownership ${ + released-nixpkgs-unstable.htmlDocs.nixosManual.${system} + }/share/doc/nixos $nixos_dir/unstable + ${manualVersionSwitch "$nixos_dir" "stable"} + ${redirectManualHTML "/manual/nixos/stable" "$nixos_dir/index.html"} + mv $nixos_dir $out + ''; + + pills = pkgs.runCommand "pills" { } '' + mkdir -p $out + cp -R ${nixPills.html-split}/share/doc/nix-pills/* $out + cp ${nixPills.epub}/share/doc/nix-pills/nix-pills.epub $out/nix-pills.epub ''; + + demos = + pkgs.runCommand "demos" + { + nativeBuildInputs = with pkgs; [ + asciinema-scenario + gnused + ]; + } + '' + mkdir -p $out + for scenario in ${./public/demos}/*.scenario; do + scenarioFileName=$out/$(basename $scenario .scenario) + echo "Generating $scenarioFileName.cast and $scenarioFileName.svg ..." + asciinema-scenario --preview-file $scenarioFileName.svg $scenario > $scenarioFileName.cast + # XXX: this in until asciinema-scenario is fixed + # https://github.com/garbas/asciinema-scenario/issues/3 + sed -i -e "s|&2 << EOF + To fetch all dependencies: + npm install + + Afterwards, to start a local development server: + npm run dev + + Then go to the following URL in your browser: + http://localhost:4321 + + It will rebuild the website on each change. + + To test redirects: + npm run build + cd dist + netlify dev + + To re-format the source code: + npm run format + EOF + ''; + }; }; - }); + }; }