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

Add nix support #31

Closed
wants to merge 5 commits into from
Closed

Add nix support #31

wants to merge 5 commits into from

Conversation

senseab
Copy link

@senseab senseab commented Nov 15, 2024

crproxy can used in nixos

releated issue #30

@senseab
Copy link
Author

senseab commented Nov 16, 2024

Just ignore all *.go file

crproxy.go Show resolved Hide resolved
sync.go Outdated Show resolved Hide resolved
@wzshiming wzshiming force-pushed the dev branch 4 times, most recently from f3e6a1f to c38770d Compare November 20, 2024 03:22
@wzshiming wzshiming force-pushed the dev branch 2 times, most recently from 33fe780 to ac5e1fd Compare November 22, 2024 10:14
Copy link
Member

@wzshiming wzshiming left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide a docs for how to use and update them?

@senseab
Copy link
Author

senseab commented Nov 26, 2024

更新 flake.nix 版本号

修改第 15 行 version 字段

...
      let
        pkgs = import nixpkgs { inherit system; };
        inherit (pkgs.lib) licenses;
        name = "crproxy"; 
        version = "v0.13.0";  # 修改这个地方为计划发布的版本
      in
...

更新 vendorHash

执行 nix build .

在执行过程中会有报错提示,内容大致如下

error: hash mismatch in fixed-output derivation '/nix/store/as4fgwpgi68mls7lqnpb6821swkzmj6s-crproxy-v0.13.0-go-modules.drv':
         specified: sha256-Oqaafxih9t9cggfa8PF5auMkrWq9oUDRxl8cdBLllhM=
            got:    sha256-4DlW0d6O0VSaR7lMefj/gChxvLD6JC2um1T6/qdAK2Q=

根据上述提示更新 vendorHash 字段,在 flake.nix 第 24 行

        crproxy = pkgs.buildGoModule {
          pname = name;
          inherit version;
          src = self;
          doCheck = false;
          proxyVendor = true;
          vendorHash = "sha256-4DlW0d6O0VSaR7lMefj/gChxvLD6JC2um1T6/qdAK2Q=";   # 更新这里

          CGO_ENABLED = 0;

          meta = {
            description = "CRProxy (Container Registry Proxy) is a generic image proxy";
            homepage = "https://github.com/DaoCloud/crproxy";
            license = licenses.mit;
          };
        };

其他内容暂不需要维护

@senseab
Copy link
Author

senseab commented Nov 26, 2024

nixos 使用方法

在 nixos 配置的 flake.nix 中加入

inputs = {
...
crproxy = {
  url = "github:DaoCloud/crproxy/v0.13.0"; # 这里版本号可改
  inputs.nixpkgs.follows = "nixpkgs";
};
...
};

outputs = {crproxy, ...}: {
  nixosConfigurations.gpd = nixpkgs.lib.nixosSystem {
    ...
    modules = [
      crproxy.nixosModules.crproxy
      {
         services.crproxy.enable = true;
      }
    ];
    ...
  };
};

@wzshiming
Copy link
Member

https://github.com/search?q=repo%3ANixOS%2Fnixpkgs%20buildGoModule%20AND%20fetchFromGitHub&type=code

我看 nixpkgs 里面, buildGoModule 都是配合 fetchFromGitHub 一起使用的是不是和其保持一致比较好

@wzshiming
Copy link
Member

我研究一下这个是不是分成两个 nix 文件比较好, 一个是安装的, 一个是提供服务的

@senseab
Copy link
Author

senseab commented Nov 26, 2024

https://github.com/search?q=repo%3ANixOS%2Fnixpkgs%20buildGoModule%20AND%20fetchFromGitHub&type=code

我看 nixpkgs 里面, buildGoModule 都是配合 fetchFromGitHub 一起使用的是不是和其保持一致比较好

可以考虑使用 fetchFromGithub,参考 https://github.com/NixOS/nixpkgs/blob/b61ee8759e6365240d902e2729fed98adaf92ef2/pkgs/by-name/cr/crproxy/package.nix

需要注意的是,未来 nixos 及 nix 包管理器会使用 flake 特性,flake 完全可以跟着对应版本的代码来配置,单独再 fetchFromGithub 的意义也不大了

nixpkg 我已经加入了 crproxy,等 merge NixOS/nixpkgs#356098

我研究一下这个是不是分成两个 nix 文件比较好, 一个是安装的, 一个是提供服务的

只要设置了 services.crproxy.enable = true; 就自动安装了,不需要另行安装,nixos 就是用它的配置文件封装了整个打包、安装、配置的过程

@wzshiming wzshiming force-pushed the dev branch 3 times, most recently from dc5d74f to 625acde Compare November 27, 2024 14:19
@senseab
Copy link
Author

senseab commented Dec 6, 2024

先不提交了,重点考虑官方 nixpkgs

@senseab senseab closed this Dec 6, 2024
@senseab senseab deleted the dev branch December 6, 2024 02:24
@senseab senseab restored the dev branch December 6, 2024 02:24
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

Successfully merging this pull request may close these issues.

2 participants