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

fetchs3: allow to name the derivation output #39823

Merged
merged 4 commits into from May 3, 2018
Merged

Conversation

zimbatm
Copy link
Member

@zimbatm zimbatm commented May 1, 2018

Motivation for this change

The default output name is "foo" which is not very descriptive. To avoid
rebuilds this is kept as the default but one can now pass an optional
name attribute to change it.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

@copumpkin
Copy link
Member

Wow, I'm the worst. I doubt anyone wants it to be foo. I don't rely on it, and if nobody else is using it in nixpkgs, it seems like a safe bet to just take out the default. I feel bad for leaving that in by accident!

@zimbatm
Copy link
Member Author

zimbatm commented May 1, 2018

@copumpkin what do you think of using baseNameOf s3url as the default instead? I want to keep a default to avoid breaking back-compat. IMO it's being used outside of nixpkgs in private repositories.

@copumpkin
Copy link
Member

copumpkin commented May 1, 2018

Sure, baseNameOf sounds good. If you do think it's being used widely though, changing the default is pretty awkward. Not really sure what to do about it though...

@dtzWill
Copy link
Member

dtzWill commented May 1, 2018

lmao. It happens! No worries :). But LOL 😁

@basvandijk
Copy link
Member

Nice! TIL that fetchs3 is in nixpkgs. At LumiGuide I've been using the following for some time:

{
  fetchS3 = {path, sha256, accessKeyId, secretAccessKey, region}:
    previous.runCommand (baseNameOf path) {
      inherit path;
      AWS_ACCESS_KEY_ID     = accessKeyId;
      AWS_SECRET_ACCESS_KEY = secretAccessKey;
      AWS_DEFAULT_REGION    = region;
      outputHashMode = "flat";
      outputHashAlgo = "sha256";
      outputHash     = sha256;
    } ''${final.awscli}/bin/aws s3 cp "s3://$path" "$out"'';
}

I'll be replacing that with fetchs3. But first a few issues need to be fixed:

  • If I specify credentials but don't specify session_token I get the following error:
error: attribute 'session_token' missing, at 
nixpkgs/pkgs/build-support/fetchs3/default.nix:16:25

we should probably define credentialAttrs as follows:

let
  credentialAttrs = stdenvNoCC.lib.optionalAttrs (credentials != null) (with credentials; {
    AWS_ACCESS_KEY_ID = access_key_id;
    AWS_SECRET_ACCESS_KEY = secret_access_key;
    AWS_SESSION_TOKEN = session_token ? null;
  });
in 
  • I see that the region argument is not used. Shouldn't the following environment variable be set: AWS_DEFAULT_REGION = region;?

@zimbatm
Copy link
Member Author

zimbatm commented May 2, 2018

@basvandijk thanks, integrated your feedback. Wanna try it out?

Change the default from "foo" to the basename of the s3 URL and make it
configurable.
The session token should default to null instead of failing
Set it to null if you don't want to use it
@basvandijk
Copy link
Member

Thanks. I successfully executed a command like:

$ nix-build -E 'let pkgs = import ./. {}; in pkgs.fetchs3 {s3url = "s3://xxx"; sha256="xxx"; region = "eu-central-1"; credentials = {access_key_id=xxx; secret_access_key=xxx;};}'  

@copumpkin
Copy link
Member

Nice, thanks! I only use temporary credentials which is how I missed the accidentally required session token 😄

@copumpkin
Copy link
Member

Also, I think the region argument here just dictates which regional endpoint you hit with GetBucketLocation, right? After it knows what region your bucket is in, it'll just use that regardless of what you specify.

Copy link
Member

@copumpkin copumpkin left a comment

Choose a reason for hiding this comment

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

Anyway, this all looks great, thanks!

@copumpkin
Copy link
Member

One last thing though: in my use case, I don't have a multi-user store so I don't care about the .drvs containing my credentials (and as I said, they're temporary, so it doesn't even matter), but some might find it unexpected that their credentials are in the .drv. Some might prefer impureEnvVars for that reason. Do any of you care or shall we just put this in like this for now?

@basvandijk
Copy link
Member

I don't know about impureEnvVars or how it works but it sounds like a good idea to avoid storing credentials in .drvs.

@zimbatm
Copy link
Member Author

zimbatm commented May 2, 2018

sounds good, threw in a preferLocalBuild for the good form as well

@zimbatm
Copy link
Member Author

zimbatm commented May 2, 2018

hmm, getting "fatal error: An error occurred (400) when calling the HeadObject operation: Bad Request" when using the impureEnvVars

@zimbatm
Copy link
Member Author

zimbatm commented May 2, 2018

I will just get rid of it for now. If you pass them as attributes then it's already in the nix store as build inputs anyways.

Fetcher-types spend more time on network than CPU
@copumpkin
Copy link
Member

Oh, one thing I noticed with impureEnvVars in the past is that they always set an env var even if it's unset in the parent context (in which case it's set to empty). An empty session token will probably screw you up. In the past I've had to explicitly unset empty variables. Should probably be fixed in Nix 😄

@zimbatm
Copy link
Member Author

zimbatm commented May 2, 2018

yeah that's a weird design decision, I don't expect impureEnvVars to touch the environment :)

@zimbatm zimbatm merged commit f7abcb0 into NixOS:master May 3, 2018
@zimbatm zimbatm deleted the fetchs3-foo branch May 3, 2018 10:08
zimbatm added a commit that referenced this pull request May 3, 2018
* fetchs3: add configurable name

Change the default from "foo" to the basename of the s3 URL and make it
configurable.

* fetchs3: fix error on missing credentials.session_token

The session token should default to null instead of failing

* fetchs3: make use of the region argument

Set it to null if you don't want to use it

* fetchs3: prefer local build

Fetcher-types spend more time on network than CPU

(cherry picked from commit f7abcb0)
@zimbatm
Copy link
Member Author

zimbatm commented May 3, 2018

also pushed as 7a37ed5 in release-18.03

Synthetica9 pushed a commit to Synthetica9/nixpkgs that referenced this pull request May 3, 2018
* fetchs3: add configurable name

Change the default from "foo" to the basename of the s3 URL and make it
configurable.

* fetchs3: fix error on missing credentials.session_token

The session token should default to null instead of failing

* fetchs3: make use of the region argument

Set it to null if you don't want to use it

* fetchs3: prefer local build

Fetcher-types spend more time on network than CPU
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants