-
Notifications
You must be signed in to change notification settings - Fork 98
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
Open
senseab
wants to merge
2
commits into
DaoCloud:dev
Choose a base branch
from
senseab:dev
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+295
−33
Open
Add nix support #31
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
use flake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,7 @@ | |
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
# Nix support | ||
.direnv | ||
result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ignore this file when merging |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
{ | ||
description = "CRProxy (Container Registry Proxy) is a generic image proxy"; | ||
|
||
inputs = { | ||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; | ||
utils.url = "github:numtide/flake-utils"; | ||
}; | ||
|
||
outputs = { self, nixpkgs, utils }: | ||
utils.lib.eachDefaultSystem (system: | ||
let | ||
pkgs = import nixpkgs { inherit system; }; | ||
inherit (pkgs.lib) licenses; | ||
name = "crproxy"; | ||
version = "v0.13.0"; | ||
in | ||
rec { | ||
crproxy = pkgs.buildGoModule { | ||
pname = name; | ||
inherit version; | ||
src = self; | ||
doCheck = false; | ||
proxyVendor = true; | ||
vendorHash = "sha256-Oqaafxih9t9cggfa8PF5auMkrWq9oUDRxl8cdBLllhM="; | ||
|
||
CGO_ENABLED = 0; | ||
|
||
meta = { | ||
description = "CRProxy (Container Registry Proxy) is a generic image proxy"; | ||
homepage = "https://github.com/DaoCloud/crproxy"; | ||
license = licenses.mit; | ||
}; | ||
}; | ||
|
||
defaultPackage = crproxy; | ||
|
||
devShell = with pkgs; mkShell { | ||
buildInputs = [ | ||
go | ||
]; | ||
}; | ||
|
||
nixosModule = { config, pkgs, lib, ... }: | ||
let | ||
cfg = config.service.crproxy; | ||
allowImageListFile = | ||
pkgs.writeTextFile { | ||
name = "crproxy-allow-image-list"; | ||
text = lib.strings.concatLines cfg.allowImageList; | ||
}; | ||
useAllowImageList = (lib.length cfg.allowImageList) != 0; | ||
blockIPListFile = pkgs.writeTextFile { | ||
name = "crproxy-block-ip-list"; | ||
text = lib.strings.concatLines cfg.blockIPList; | ||
}; | ||
useBlockIPList = (lib.length cfg.blockIPList) != 0; | ||
inherit (lib) mkIf mkEnableOption mkOption types concatStringsSep concatLists optionals literalExpression; | ||
in | ||
{ | ||
options = { | ||
services.crproxy = { | ||
enable = mkEnableOption "CRProxy (Container Registry Proxy) is a generic image proxy"; | ||
|
||
listenAddress = mkOption { | ||
default = ":8080"; | ||
type = types.str; | ||
description = "listen on the address (default \":8080\")"; | ||
}; | ||
|
||
behindProxy = mkOption { | ||
default = false; | ||
type = types.bool; | ||
description = "Behind the reverse proxy"; | ||
}; | ||
|
||
userpass = mkOption { | ||
default = [ ]; | ||
example = literalExpression '' | ||
[ "user@pwd@host" ] | ||
''; | ||
type = types.listOf types.str; | ||
description = "host and username and password -u user:pwd@host"; | ||
}; | ||
|
||
allowHostList = mkOption { | ||
default = [ ]; | ||
type = types.listOf types.str; | ||
description = "allow host list"; | ||
}; | ||
|
||
allowImageList = mkOption { | ||
default = [ ]; | ||
type = types.listOf types.str; | ||
description = "allow image list"; | ||
}; | ||
|
||
blockMessage = mkOption { | ||
type = types.str; | ||
default = "This image is not allowed for my proxy!"; | ||
description = "block message"; | ||
}; | ||
|
||
blockIPList = mkOption { | ||
type = types.listOf types.str; | ||
default = [ ]; | ||
description = "block ip list"; | ||
}; | ||
|
||
defaultRegistry = mkOption { | ||
type = types.str; | ||
default = "docker.io"; | ||
description = "default registry used for non full-path docker pull, like:docker.io"; | ||
}; | ||
|
||
simpleAuth = mkOption { | ||
type = types.bool; | ||
default = false; | ||
description = "enable simple auth"; | ||
}; | ||
|
||
simpleAuthUser = mkOption { | ||
type = types.listOf types.str; | ||
default = [ ]; | ||
description = "simple auth user and password (default [])"; | ||
}; | ||
|
||
privilegedIPList = mkOption { | ||
default = [ ]; | ||
type = types.listOf types.str; | ||
description = "privileged IP list"; | ||
}; | ||
|
||
extraOptions = mkOption { | ||
default = [ ]; | ||
type = types.listOf types.str; | ||
description = '' | ||
see https://github.com/DaoCloud/crproxy/blob/master/cmd/crproxy/main.go for more. | ||
''; | ||
}; | ||
}; | ||
}; | ||
|
||
config = mkIf cfg.enable { | ||
systemd.services.crproxy = { | ||
wantedBy = [ | ||
"network-online.target" | ||
]; | ||
serviceConfig = { | ||
RestartSec = 5; | ||
ExecStart = concatStringsSep " " concatLists [ | ||
[ | ||
"${crproxy}/bin/crproxy" | ||
"--default-registry=${cfg.defaultRegistry}" | ||
"--address=${cfg.listenAddress}" | ||
] | ||
(optionals cfg.behindProxy [ "--behind" ]) | ||
(optionals useAllowImageList [ "--allow-image-list-from-file=${allowImageListFile}" ]) | ||
(optionals useAllowImageList [ "--block-message=${cfg.blockMessage}" ]) | ||
(optionals useBlockIPList [ "--block-ip-list-from-file=${blockIPListFile}" ]) | ||
(optionals cfg.simpleAuth [ "--simple-auth" ]) | ||
(map (e: "--simple-auth-user=${e}") cfg.simpleAuthUser) | ||
(map (e: "--allow-host-list=${e}") cfg.allowHostList) | ||
(map (e: "--privileged-ip-list=${e}") cfg.privilegedIPList) | ||
(map (e: "--user=${e}") cfg.userpass) | ||
|
||
cfg.extraOptions | ||
]; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ignore this file when merging