From b3b4af6c9b0ffefc95f51da73252132ce89d5752 Mon Sep 17 00:00:00 2001 From: Daniel Kahlenberg <573@users.noreply.github.com> Date: Sat, 28 Sep 2024 00:03:46 +0200 Subject: [PATCH] Reorganize config --- .github/workflows/ci_shells.yaml | 137 ++++++++++++++++++++++++ flake.nix | 12 +-- flake/builders/mkDevShellAgda.nix | 3 +- flake/builders/mkDevShellCommonLisp.nix | 5 +- flake/builders/mkDevShellGhcwasm.nix | 6 +- flake/default.nix | 5 +- flake/nixpkgs.nix | 24 +---- 7 files changed, 160 insertions(+), 32 deletions(-) create mode 100644 .github/workflows/ci_shells.yaml diff --git a/.github/workflows/ci_shells.yaml b/.github/workflows/ci_shells.yaml new file mode 100644 index 00000000..059f4242 --- /dev/null +++ b/.github/workflows/ci_shells.yaml @@ -0,0 +1,137 @@ +name: Build and test flake devshells (using gh caches) + +on: + push: + workflow_dispatch: + workflow_call: + inputs: + branch: + description: Branch name to build on + default: "" + required: false + type: string + secrets: + CACHIX_ACTIVATE_TOKEN: + CACHIX_AUTH_TOKEN: + required: true + +jobs: + nix: + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + yamlbasename: + - ci_shells.yml + os: + - ubuntu-latest + system: + - aarch64 + - x86_64 + include: + shell: devShells.$_system.ghcwasm + command: ghc --version + shell: devShells.$_system.commonlisp + command: sbcl --version + shell: devShells.$_system.rustwasm32 + command: rustc --version + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + ref: ${{ inputs.branch }} + + - name: Free Disk Space (Ubuntu) + if: contains(matrix.shell, 'ruby') + env: + _system: ${{ matrix.system }}-linux + uses: jlumbroso/free-disk-space@main + continue-on-error: true + with: + tool-cache: true + + - name: Set Swap Space + uses: actionhippie/swap-space@master + with: + size: 20G + + - name: Install qemu-user-static (aarch64) + if: matrix.system == 'aarch64' + env: + _system: ${{ matrix.system }}-linux + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + sudo apt-get update --allow-releaseinfo-change + sudo apt-get update + sudo apt-get install -y qemu-user-static + + - name: Quick install + env: + _system: ${{ matrix.system }}-linux + uses: cachix/install-nix-action@v29 + with: + install_url: 'https://releases.nixos.org/nix/nix-2.24.8/install' + extra_nix_config: | + substituters = https://cache.nixos.org/ https://nix-community.cachix.org + trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs= + keep-going = true + show-trace = true + access-tokens = github.com=${{ secrets.GITHUB_TOKEN }} + keep-outputs = true + ${{ matrix.system == 'aarch64' && 'system = aarch64-linux # enables binfmt on that machine, see https://nixos.wiki/wiki/NixOS_on_ARM#Compiling_through_binfmt_QEMU' || '' }} + + - name: Restore and cache Nix store + env: + _system: ${{ matrix.system }}-linux + uses: nix-community/cache-nix-action@v5 + with: + # save a new cache every time ci file changes + primary-key: cache-${{ matrix.os }}-${{ hashFiles('.github/workflows/ci.yaml') }} + restore-prefixes-first-match: cache-${{ matrix.os }}- + # do purge caches + purge: true + # purge all versions of the cache + purge-prefixes: cache-${{ matrix.os }}- + # created more than 0 seconds ago relative to the start of the `Post Restore` phase + purge-created: 0 + # except the version with the `primary-key`, if it exists + purge-primary-key: never + # and collect garbage in the Nix store until it reaches this size in bytes + gc-max-store-size: 8000000000 + + - name: Setup cachix + env: + _system: ${{ matrix.system }}-linux + uses: cachix/cachix-action@v15 + with: + name: 573-bc + authToken: ${{ secrets.CACHIX_AUTH_TOKEN }} + + - name: My shells + env: + _system: ${{ matrix.system }}-linux + uses: nicknovitski/nix-develop@v1.1.0 + with: + arguments: .#${{ (matrix.shell == '') && format('formatter.{0}', env._system) || matrix.shell }} --impure + - run: | + echo "::group::Development shells command" + cachix use 573-bc + cachix use nix-on-droid + ${{ (matrix.system == 'aarch64' || contains(matrix.shell, 'ruby')) && 'cachix watch-exec 573-bc -- \' || '' }} + ${{ matrix.command }} + + - name: Deploy cachix-agent spec + if: github.ref == 'refs/heads/wsl2' && matrix.deploy-agent + env: + CACHIX_ACTIVATE_TOKEN: ${{ secrets.CACHIX_ACTIVATE_TOKEN }} + TEST: ${{ matrix.system == 'aarch64' && '--impure' || '' }} + run: | + echo "::group::Build spec" + spec="$(nix build --print-out-paths ".#cachix-deploy-spec-${{ matrix.deploy-agent }}" ${{ (matrix.system == 'aarch64' || contains(matrix.nix-command, 'develop')) && '--impure' || '' }})" + + echo "::group::Upload spec" + cachix push 573-bc "$spec" + +# vim: set sw=2: diff --git a/flake.nix b/flake.nix index 6d80a78e..199adfb2 100644 --- a/flake.nix +++ b/flake.nix @@ -668,12 +668,12 @@ poetry2nix.inputs.nixpkgs.follows = "unstable"; # also: https://wiki.nixos.org/wiki/CUDA #(mkDevShellCudaWsl system "cudawsl" { }) #(mkDevenvJulia system "julia" { }) - (mkDevShellAgda system "agda" { inherit ghc-nixpkgs-unstable haskellPackages; }) - #(mkDevShellCommonLisp system "commonlisp" { inherit unstable; }) - #(mkDevenvPlaywright "playwright" { inherit nixpkgs mkShell; }) - #(mkDevenvPlaywright2 "playwright2" { inherit unstable mkShell; }) - #(mkDevShellGhcwasm "ghcwasm" { inherit ghc-wasm-meta unstable; }) -# (mkDevenvHaskell2 "haskell2" { inherit nixpkgs ghciwatch haskellPackages unstable mkShell; }) + (mkDevShellAgda system "agda" { inherit haskellPackages; }) + (mkDevShellCommonLisp system "commonlisp" { }) + #(mkDevenvPlaywright system "playwright" { inherit nixpkgs mkShell; }) + #(mkDevenvPlaywright2 system "playwright2" { inherit unstable mkShell; }) + (mkDevShellGhcwasm system "ghcwasm" { inherit ghc-wasm-meta; }) +# (mkDevenvHaskell2 system "haskell2" { inherit nixpkgs ghciwatch haskellPackages unstable mkShell; }) ] /*// { #template = (nixpkgs.mkShell.override { stdenv = nixpkgs.stdenvAdapters.useMoldLinker nixpkgs.stdenv; }); # https://github.com/NixOS/nixpkgs/blob/9e860e4/pkgs/development/lisp-modules/shell.nix diff --git a/flake/builders/mkDevShellAgda.nix b/flake/builders/mkDevShellAgda.nix index 19a302b6..15b9c31c 100644 --- a/flake/builders/mkDevShellAgda.nix +++ b/flake/builders/mkDevShellAgda.nix @@ -1,4 +1,4 @@ -{ system, ghcpkgsFor, inputs, name, args, ... }: +{ system, ghcpkgsFor, name, args, ... }: let pkgs = ghcpkgsFor.${system}; myagda = (pkgs.agdaPackages.override { @@ -11,5 +11,6 @@ let }); in pkgs.mkShell { + inherit name; packages = [ myagda ]; } diff --git a/flake/builders/mkDevShellCommonLisp.nix b/flake/builders/mkDevShellCommonLisp.nix index d12c425d..898e12b9 100644 --- a/flake/builders/mkDevShellCommonLisp.nix +++ b/flake/builders/mkDevShellCommonLisp.nix @@ -1,9 +1,10 @@ { system, pkgsFor, name, args, ... }: # https://github.com/NixOS/nixpkgs/blob/9e860e4/pkgs/development/lisp-modules/shell.nix let - pkgs = unstable; + pkgs = pkgsFor.${system}; in pkgs.mkShell { + inherit name; nativeBuildInputs = [ (pkgs.sbcl.withPackages (sbclPackageSet: builtins.attrValues { @@ -19,4 +20,4 @@ pkgs.mkShell { ; })) ]; -}; +} diff --git a/flake/builders/mkDevShellGhcwasm.nix b/flake/builders/mkDevShellGhcwasm.nix index 43b8424f..6abe6573 100644 --- a/flake/builders/mkDevShellGhcwasm.nix +++ b/flake/builders/mkDevShellGhcwasm.nix @@ -1,9 +1,9 @@ { system, pkgsFor, name, args, ... }: # https://github.com/tweag/ormolu/blob/74887f00137d6cd91811440325c3ac330a371b2c/ormolu-live/default.nix let - inherit (args) unstable ghc-wasm-meta; - pkgs = unstable; + pkgs = pkgsFor.${system}; in pkgs.mkShell { - packages = [ ghc-wasm-meta ]; + inherit name; + packages = [ args.ghc-wasm-meta ]; } diff --git a/flake/default.nix b/flake/default.nix index 7fdbba9b..5ed9da84 100644 --- a/flake/default.nix +++ b/flake/default.nix @@ -11,7 +11,10 @@ let pkgsCudaFor = forEachSystem (system: import ./nixpkgs.nix { inherit inputs rootPath system; config = { - #allowUnfree = true; + cudnnSupport = true; + cudaVersion = "12"; + # https://discourse.nixos.org/t/laggy-mouse-when-use-nvidia-driver/38410 + nvidia.acceptLicense = true; cudaSupport = true; # https://discourse.nixos.org/t/too-dumb-to-use-allowunfreepredicate/39956/17 allowUnfreePredicate = pkg: builtins.elem (inputs.nixpkgs.lib.getName pkg) [ diff --git a/flake/nixpkgs.nix b/flake/nixpkgs.nix index 0d32f136..733ebb43 100644 --- a/flake/nixpkgs.nix +++ b/flake/nixpkgs.nix @@ -4,21 +4,15 @@ , pkgsSet ? inputs.nixpkgs , nixOnDroid ? false , config ? { - # FIXME https://discourse.nixos.org/t/unexpected-11h-build-after-auto-update/39907/9 - #allowAliases = false; - #allowUnfree = true; - #cudaSupport = true; - #cudnnSupport = true; - #cudaVersion = "12"; - # https://discourse.nixos.org/t/laggy-mouse-when-use-nvidia-driver/38410 - nvidia.acceptLicense = true; + # FIXME https://discourse.nixos.org/t/unexpected-11h-build-after-auto-update/39907/9 + allowAliases = false; + allowUnfreePredicate = pkg: builtins.elem (inputs.nixpkgs.lib.getName pkg) [ + "google-chrome" + ]; } }: import pkgsSet { inherit config system rootPath; - #config = { - # permittedInsecurePackages = [ "openssl-1.1.1w" ]; - # }; overlays = [ #inputs.rust-overlay.overlays.default # now commented out due to: error: attribute 'rust-analyzer' missing https://github.com/573/nix-config-1/actions/runs/4923802480/jobs/8796067915#step:6:826 # rustc still 1.64 when building as opposed to nix shell 1.67 @@ -123,13 +117,5 @@ import pkgsSet { inputs.nix-on-droid.overlays.default # prevent uploads to remote builder, https://ryantm.github.io/nixpkgs/functions/prefer-remote-fetch (final: prev: prev.prefer-remote-fetch final prev) - (final: prev: { - # https://discourse.nixos.org/t/overriding-torch-with-torch-bin-for-all-packages/37086/2 - pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [ - (py-final: py-prev: { - torch = py-final.torch-bin; - }) - ]; - }) ]; }