Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Pin Version of Package #346

Closed
bdkiran opened this issue Oct 25, 2024 · 2 comments
Closed

How to Pin Version of Package #346

bdkiran opened this issue Oct 25, 2024 · 2 comments

Comments

@bdkiran
Copy link

bdkiran commented Oct 25, 2024

I have a pipeline that was running until a package that I use was updated and broke the package. In order to fix it short term, was hoping I could pin the version of the package in the nix shell action.

name: infra-deployment

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout Code
      uses: actions/checkout@v4
    
    - name: Install Nix On Runner
      uses: cachix/install-nix-action@v30
      with:
        nix_path: nixpkgs=channel:nixos-unstable

    - name: Deploy to Production
      uses: workflow/nix-shell-action@v3
      with:
        packages: morph:1.7 #<- This is where I would like to set the version of the package
        script: |
          morph deploy network.nix switch

Error Log from Github Actions when run like above:

nixpkgs.morph:1.7
error: unrecognised flag '-c'
Try 'nix --help' for more information.
unpacking 'github:NixOS/nixpkgs/062c4f59744fcffa2e5aa3ef443dc8b4d1674ed6' into the Git cache...
error: flake 'flake:nixpkgs' does not provide attribute 'packages.x86_64-linux.morph:1.7', 'legacyPackages.x86_64-linux.morph:1.7' or 'morph:1.7'
       Did you mean morph?

I have not seen any documentation of how to do this. Am I doing this correctly or is there a better way to do this?

@workflow
Copy link
Owner

Hi @bdkiran 👋,

Nix works a little differently than what you're used to with version pinning:

You'll want to

  1. first find a commit or branch of nixpkgs that provides the exact version you want
  2. and then simply install morph from that commit.

For finding the version you want, I recommend searching at either https://lazamar.co.uk/nix-versions or https://www.nixhub.io/ as a starting point, and if that doesn't cut it you can always explore the Source Repo of Nix directly to find the precise commit that has the version you need.

Once you have that, you can pass that to install-nix-action and morph will be pinned at the exact version you want.

Example for Morph 1.7.0

Let's say you want to pin to Morph 1.7.0.

https://www.nixhub.io/ lists d4f247e89f6e10120f911e2e2d2254a050d0f732 as a commit of nixpkgs referencing that version before the recent upgrade to 1.8.0.
You can verify that by checking the nixpkgs repo at that commit.

Now we need to Pin Nixpkgs to that commit:

name: infra-deployment

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout Code
      uses: actions/checkout@v4
    
    - name: Install Nix On Runner
      uses: cachix/install-nix-action@v30
      with:
        nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/d4f247e89f6e10120f911e2e2d2254a050d0f732.tar.gz

    - name: Deploy to Production
      uses: workflow/nix-shell-action@v3
      with:
        packages: morph # This will now use the exact morph version from the nixpkgs commit pinned above
        script: |
          morph deploy network.nix switch

... and you'll have Morph 1.7.0, pinned at that exact version, with all its build dependencies locked as well.

@bdkiran
Copy link
Author

bdkiran commented Oct 27, 2024

Thanks for getting back to me on this. I appreciate you taking the time to explain some of the concepts of nixpkgs. This is the exact solution I was looking for and fixed my issue.

@bdkiran bdkiran closed this as completed Oct 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants