diff --git a/dist/index.js b/dist/index.js index 4b4efef..7be78c4 100644 --- a/dist/index.js +++ b/dist/index.js @@ -24,7 +24,7 @@ echo "Uploading paths: $OUT_PATHS" 1>&2 --extra-experimental-features nix-command \\ copy --to '${p[0]}' 1>&2 `);let w=ne.join(m,"post-build-hook");await(0,I1.writeFile)(w,c,{mode:493}),(0,y1.debug)("Wrote "+w),l+="post-build-hook = "+w+` -`}}return{config:l,tempDir:m,credsPath:s,nixcachedExe:n,nixcachedPipe:o}}catch(u){throw m&&await(0,I1.rm)(m,{recursive:!0,force:!0}).catch(f=>{(0,y1.warning)(f)}),u}}async function z3(e,p){let a=(0,j6.createHash)("sha256"),d=(0,M6.createWriteStream)(e),i=await(0,$6.default)(p);if(!i.ok)throw new Error(`GET ${p} ${i.status}`);return i.body?(i.body.pipe(a),i.body.pipe(d),new Promise((t,r)=>{d.on("error",s=>{d.close(()=>{r(s)})}),i.body.on("error",s=>{d.close(()=>{r(s)})});let l=0,m=()=>{l++,l===2&&t(a.digest("hex"))};d.on("finish",m),a.on("finish",m)})):(await new Promise((t,r)=>{d.close(l=>{l?r(l):t()})}),a.digest("hex"))}async function H6(e,p,a){let d=a?.append?["--non-interactive","tee","-a",e]:["--non-interactive","tee",e],i=(0,K6.spawn)("sudo",d,{stdio:["pipe","ignore","inherit"]}),t=new Promise((r,l)=>{i.on("close",m=>{m===0?r():l(new Error("tee exited with "+m))})});try{await new Promise((r,l)=>{i.stdin.write(p,m=>{m?l(m):r()})}),await new Promise(r=>{i.stdin.end(r)})}catch(r){throw i.kill(),r}finally{await t}}async function G3(){if(F1.platform==="linux"){if(!await E1(["systemctl","cat","nix-daemon.service"],{ignoreStderr:!0}).then(()=>!0,()=>!1))return;(0,E.info)("Restarting Nix daemon..."),await E1(["systemctl","daemon-reload"]),await E1(["systemctl","restart","nix-daemon.service"])}else if(F1.platform==="darwin"){if(!await(0,J6.stat)("/Library/LaunchDaemons/org.nixos.nix-daemon.plist").then(()=>!0,()=>!1))return;(0,E.info)("Restarting Nix daemon..."),await E1(["launchctl","kickstart","-k","system/org.nixos.nix-daemon"])}else throw new Error("cannot restart Nix daemon on unknown platform "+F1.platform)}function O2(e){return e=e.trim(),e?e.split(/\s+/):[]}var W6=38380;(async()=>{try{(0,E.info)("Generating configuration...");let e=(0,E.getBooleanInput)("use_nixcached");if(e&&F1.platform!=="linux")throw new Error("nixcached not supported on "+F1.platform);let p=O2((0,E.getInput)("substituters",{required:!0}));if(e&&p.length!==1)throw new Error("Must have exactly 1 substituter for nixcached");let{config:a,tempDir:d,credsPath:i,nixcachedExe:t,nixcachedPipe:r}=await G6({useNixcached:e,substituters:e?p:[`http://localhost:${W6}`],trustedPublicKeys:O2((0,E.getInput)("trusted_public_keys")),secretKeys:O2((0,E.getInput)("secret_keys")),awsAccessKeyId:(0,E.getInput)("aws_access_key_id"),awsSecretAccessKey:(0,E.getInput)("aws_secret_access_key")});if(d&&(e||E1(["chown","-R","root:root",d]),(0,E.saveState)(La,d)),t){let l=[];if(process.env.GOOGLE_APPLICATION_CREDENTIALS){let n=`GOOGLE_APPLICATION_CREDENTIALS=${process.env.GOOGLE_APPLICATION_CREDENTIALS}`;(0,E.debug)(`Using ${n} for nixcached`),l.push(`--setenv=${n}`)}if(i||process.env.AWS_SHARED_CREDENTIALS_FILE){let n=`AWS_SHARED_CREDENTIALS_FILE=${i||process.env.AWS_SHARED_CREDENTIALS_FILE}`;(0,E.debug)(`Using ${n} for nixcached`),l.push(`--setenv=${n}`)}(0,E.debug)("Starting nixcached serve...");let m="nixcached-serve.service",s=[m];if(await he(["systemd-run","--user",`--unit=${m}`,...l,t,"serve",`--port=${W6}`,"--",p[0]]),r){(0,E.debug)("Starting nixcached upload...");let n="nixcached-upload.service";s.push(n),await he(["systemd-run","--user",`--unit=${n}`,"--property=KillMode=mixed","--property=KillSignal=SIGHUP",...l,t,"upload","--keep-alive",`--input=${r}`,"--",p[0]])}(0,E.saveState)(Fa,s)}if((0,E.info)("Saving configuration..."),await E1(["mkdir","-p","/etc/nix"]),await H6("/etc/nix/nix.conf",a,{append:!0}),i&&!e){if(F1.platform!=="linux")throw new Error("Private substituters not supported on "+F1.platform);await E1(["mkdir","-p","/etc/systemd/system/nix-daemon.service.d"]);let l="/etc/systemd/system/nix-daemon.service.d/aws-credentials.conf";await H6(l,`[Service] +`}}return{config:l,tempDir:m,credsPath:s,nixcachedExe:n,nixcachedPipe:o}}catch(u){throw m&&await(0,I1.rm)(m,{recursive:!0,force:!0}).catch(f=>{(0,y1.warning)(f)}),u}}async function z3(e,p){let a=(0,j6.createHash)("sha256"),d=(0,M6.createWriteStream)(e),i=await(0,$6.default)(p);if(!i.ok)throw new Error(`GET ${p} ${i.status}`);return i.body?(i.body.pipe(a),i.body.pipe(d),new Promise((t,r)=>{d.on("error",s=>{d.close(()=>{r(s)})}),i.body.on("error",s=>{d.close(()=>{r(s)})});let l=0,m=()=>{l++,l===2&&t(a.digest("hex"))};d.on("finish",m),a.on("finish",m)})):(await new Promise((t,r)=>{d.close(l=>{l?r(l):t()})}),a.digest("hex"))}async function H6(e,p,a){let d=a?.append?["--non-interactive","tee","-a",e]:["--non-interactive","tee",e],i=(0,K6.spawn)("sudo",d,{stdio:["pipe","ignore","inherit"]}),t=new Promise((r,l)=>{i.on("close",m=>{m===0?r():l(new Error("tee exited with "+m))})});try{await new Promise((r,l)=>{i.stdin.write(p,m=>{m?l(m):r()})}),await new Promise(r=>{i.stdin.end(r)})}catch(r){throw i.kill(),r}finally{await t}}async function G3(){if(F1.platform==="linux"){if(!await E1(["systemctl","cat","nix-daemon.service"],{ignoreStderr:!0}).then(()=>!0,()=>!1))return;(0,E.info)("Restarting Nix daemon..."),await E1(["systemctl","daemon-reload"]),await E1(["systemctl","restart","nix-daemon.service"])}else if(F1.platform==="darwin"){if(!await(0,J6.stat)("/Library/LaunchDaemons/org.nixos.nix-daemon.plist").then(()=>!0,()=>!1))return;(0,E.info)("Restarting Nix daemon..."),await E1(["launchctl","kickstart","-k","system/org.nixos.nix-daemon"])}else throw new Error("cannot restart Nix daemon on unknown platform "+F1.platform)}function O2(e){return e=e.trim(),e?e.split(/\s+/):[]}var W6=38380;(async()=>{try{(0,E.info)("Generating configuration...");let e=(0,E.getBooleanInput)("use_nixcached");if(e&&F1.platform!=="linux")throw new Error("nixcached not supported on "+F1.platform);let p=O2((0,E.getInput)("substituters",{required:!0}));if(e&&p.length!==1)throw new Error("Must have exactly 1 substituter for nixcached");let{config:a,tempDir:d,credsPath:i,nixcachedExe:t,nixcachedPipe:r}=await G6({useNixcached:e,substituters:e?[`http://localhost:${W6}`]:p,trustedPublicKeys:O2((0,E.getInput)("trusted_public_keys")),secretKeys:O2((0,E.getInput)("secret_keys")),awsAccessKeyId:(0,E.getInput)("aws_access_key_id"),awsSecretAccessKey:(0,E.getInput)("aws_secret_access_key")});if(d&&(e||E1(["chown","-R","root:root",d]),(0,E.saveState)(La,d)),t){let l=[];if(process.env.GOOGLE_APPLICATION_CREDENTIALS){let n=`GOOGLE_APPLICATION_CREDENTIALS=${process.env.GOOGLE_APPLICATION_CREDENTIALS}`;(0,E.debug)(`Using ${n} for nixcached`),l.push(`--setenv=${n}`)}if(i||process.env.AWS_SHARED_CREDENTIALS_FILE){let n=`AWS_SHARED_CREDENTIALS_FILE=${i||process.env.AWS_SHARED_CREDENTIALS_FILE}`;(0,E.debug)(`Using ${n} for nixcached`),l.push(`--setenv=${n}`)}(0,E.debug)("Starting nixcached serve...");let m="nixcached-serve.service",s=[m];if(await he(["systemd-run","--user",`--unit=${m}`,...l,t,"serve",`--port=${W6}`,"--",p[0]]),r){(0,E.debug)("Starting nixcached upload...");let n="nixcached-upload.service";s.push(n),await he(["systemd-run","--user",`--unit=${n}`,"--property=KillMode=mixed","--property=KillSignal=SIGHUP",...l,t,"upload","--keep-alive",`--input=${r}`,"--",p[0]])}(0,E.saveState)(Fa,s)}if((0,E.info)("Saving configuration..."),await E1(["mkdir","-p","/etc/nix"]),await H6("/etc/nix/nix.conf",a,{append:!0}),i&&!e){if(F1.platform!=="linux")throw new Error("Private substituters not supported on "+F1.platform);await E1(["mkdir","-p","/etc/systemd/system/nix-daemon.service.d"]);let l="/etc/systemd/system/nix-daemon.service.d/aws-credentials.conf";await H6(l,`[Service] Environment=AWS_SHARED_CREDENTIALS_FILE=`+i+` `),(0,E.saveState)(Ia,l)}await G3(),(0,E.info)("Done!")}catch(e){e instanceof Error?(0,E.setFailed)(e.message):(0,E.setFailed)(e+"")}})(); /** diff --git a/src/index.ts b/src/index.ts index 21b61c7..0e9806c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -147,8 +147,8 @@ const NIXCACHED_PORT = 38380; } = await generate({ useNixcached, substituters: useNixcached - ? substituters - : [`http://localhost:${NIXCACHED_PORT}`], + ? [`http://localhost:${NIXCACHED_PORT}`] + : substituters, trustedPublicKeys: spaceSepList(getInput('trusted_public_keys')), secretKeys: spaceSepList(getInput('secret_keys')), awsAccessKeyId: getInput('aws_access_key_id'),