fufexan / dotfiles

NixOS system config & Home-Manager user config
MIT License
744 stars 45 forks source link

Ask about flake + cachix #21

Closed hmanhng closed 10 months ago

hmanhng commented 10 months ago

I want to build a package in flake like anyrun and upload it to cachix with github action before building it on the local machine. As I know I can build all flake with

nix build -L '.#nixosConfigurations.laptop.config.system.build.toplevel'

Doing so takes up too much space and errors occur. Is there a way to build only 1 packags in my flake? Here is my github action file

name: build-and-cache
"on":
  - push
  - workflow_dispatch
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: "Create Dir for Mounting moar Disk Space ❄️ "
        run: |
          sudo mkdir /nix
      - name: "Maximize Disk Space"
        uses: easimon/maximize-build-space@v8
        with:
          build-mount-path: /nix
          remove-android: true
          remove-codeql: true
          remove-docker-images: true
          remove-dotnet: true
          remove-haskell: true

      - uses: actions/checkout@v4

      - uses: DeterminateSystems/nix-installer-action@main
      - uses: DeterminateSystems/magic-nix-cache-action@main

      - name: "Install Cachix ❄️ "
        uses: cachix/cachix-action@v12
        with:
          name: hmanhng
          authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
          extraPullNames: nix-community, hyprland, hmanhng, anyrun

      - name: Set default git branch (to reduce log spam)
        run: git config --global init.defaultBranch tmpfs

      - name: Validate Flakes
        run: nix flake check --print-build-logs --accept-flake-config

      - name: "Build NixOS config ❄️ "
        run: |
          nix build -L '.#nixosConfigurations.laptop.config.system.build.toplevel'
fufexan commented 10 months ago

You can build one package with nix build <flake>#<package>. Anyrun however has a cachix already https://app.cachix.org/cache/anyrun.

hmanhng commented 10 months ago

I added the cachix of AnyRun to my flake, but it seems that it's not working when I include it as a plugin. Here is my anyrun.nix

{
  inputs,
  inputs',
  pkgs,
  osConfig,
  ...
}: {
  imports = [inputs.anyrun.homeManagerModules.default];
  programs.anyrun = {
    enable = true;

    config = {
      plugins = with inputs'.anyrun.packages; [
        applications
        rink
        shell
        translate
      ];

      width.fraction = 0.3;
      y.absolute = 15;
      hidePluginInfo = true;
      closeOnClick = true;
    };

    extraCss = ''
      * {
        transition: 200ms ease;
        font-family: Lexend;
        font-size: 1.3rem;
      }

      #window,
      #match,
      #entry,
      #plugin,
      #main { background: transparent; }

      #match.activatable {
        border-radius: 16px;
        padding: .3rem .9rem;
        margin-top: .01rem;
      }
      #match.activatable:first-child { margin-top: .7rem; }
      #match.activatable:last-child { margin-bottom: .6rem; }

      #plugin:hover #match.activatable {
        border-radius: 10px;
        padding: .3rem;
        margin-top: .01rem;
        margin-bottom: 0;
      }

      #match:selected, #match:hover, #plugin:hover {
        background: rgba(255, 255, 255, .1);
      }

      #entry {
        background: rgba(255,255,255,.05);
        border: 1px solid rgba(255,255,255,.1);
        border-radius: 16px;
        margin: .3rem;
        padding: .3rem 1rem;
      }

      list > #plugin {
        border-radius: 16px;
        margin: 0 .3rem;
      }
      list > #plugin:first-child { margin-top: .3rem; }
      list > #plugin:last-child { margin-bottom: .3rem; }
      list > #plugin:hover { padding: .6rem; }

      box#main {
        background: rgba(31, 31, 40, .5);
        box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .1), 0 0 0 1px rgba(0, 0, 0, .5);
        border-radius: 24px;
        padding: .3rem;
      }
    '';
    extraConfigFiles."nixos-options.ron".text = ''
      Config(
        options_path: "${osConfig.system.build.manual.optionsJSON}/share/doc/nixos/options.json",
        max_entries: 5,
      )
    '';
  };
}
hmanhng commented 10 months ago

You can build one package with nix build <flake>#<package>. Anyrun however has a cachix already https://app.cachix.org/cache/anyrun.

Looks like anyrun cachix has a problem, I added substitutes, no inputs.nixpkgs.follows but it still builds on the local machine, my laptop is full cpu and freezes for 10 minutes and logout

fufexan commented 10 months ago

Do you override anyrun's nixpkgs input? If not, you can use something like this script to build it in CI and push to your own Cachix:

#!/usr/bin/env -S nix shell nixpkgs#jq -c bash

ANYRUN_REV=$(jq <flake.lock -r '.nodes.anyrun.locked.rev')

nix build github:KitottuM/anyrun/$ANYRUN_REV#{anyrun,applications,rink,shell,translate}
hmanhng commented 10 months ago

Do you override anyrun's nixpkgs input? If not, you can use something like this script to build it in CI and push to your own Cachix:

#!/usr/bin/env -S nix shell nixpkgs#jq -c bash

ANYRUN_REV=$(jq <flake.lock -r '.nodes.anyrun.locked.rev')

nix build github:KitottuM/anyrun/$ANYRUN_REV#{anyrun,applications,rink,shell,translate}

Thanks for your help I will try