On 5 March 2017 at 01:21, Bjørn Forsman <[email protected]> wrote:
> Hi Bas, > > On 5 March 2017 at 00:49, Bas van Dijk <[email protected]> wrote: > >> Hi Bjørn, >> >> At LumiGuide I use the following systemd service to setup hydra: >> >> # Create a hydra admin user named "xxxx" and copy the GitHub private SSH >> # key to hydra's home directory so that it can connect to GitHub to clone >> # our repo's. >> systemd.services.lumi-hydra-setup = { >> wantedBy = [ "multi-user.target" ]; >> requires = [ "hydra-init.service" "postgresql.service" ]; >> after = [ "hydra-init.service" "postgresql.service" ]; >> environment = config.systemd.services.hydra-init.environment; >> path = [ config.services.hydra.package ]; >> script = >> let hydraHome = config.users.users.hydra.home; >> hydraQueueRunnerHome = config.users.users.hydra-queue-runner.home; >> in '' >> hydra-create-user xxxx \ >> --full-name 'XXXX' \ >> --email-address '[email protected]' \ >> --password '${cfg.xxxxPassword}' \ >> --role admin >> >> mkdir -p "${hydraHome}/.ssh" >> chmod 700 "${hydraHome}/.ssh" >> cp "*xxxx*" "${hydraHome}/.ssh/id_rsa" >> chown -R hydra:hydra "${hydraHome}/.ssh" >> chmod 600 "${hydraHome}/.ssh/id_rsa" >> mkdir -p "${hydraQueueRunnerHome}/.ssh" >> chmod 700 "${hydraQueueRunnerHome}/.ssh" >> cp "*xxxx*" "${hydraQueueRunnerHome}/.ssh/id_rsa" >> chown -R hydra-queue-runner:hydra "${hydraQueueRunnerHome}/.ssh" >> chmod 600 "${hydraQueueRunnerHome}/.ssh/id_rsa" >> ''; >> serviceConfig = { >> Type = "oneshot"; >> RemainAfterExit = true; >> }; >> }; Note that I set the environment to be the hydra-init environment. >> With a bit of luck that's the solution for your problem. >> > > Thanks for the tip and example code. Yes, it was a missing environment > variable! After looking at the environment for the hydra-init service > > $ nixos-option systemd.services.hydra-init.environment > Value: > { HYDRA_CONFIG = "/var/lib/hydra/hydra.conf"; [...snipped...] > > and trying various combinations of those environment variables, I found > that I only needed HYDRA_CONFIG to make it work. > > $ sudo -u hydra -E HYDRA_CONFIG="/var/lib/hydra/hydra.conf" > hydra-create-user alice --full-name 'Alice Q. User' --email-address ' > [email protected]' --password alice --role admin > creating new user `alice' > Since the nixpkgs hydra module defines all HYDRA_* environment variables to be global environment variables (set in NixOS environment.variables option), I guess what blocked me the first time was that sudo restricts the environment. I guess the the better/easier way would be "sudo -E hydra-create-user ..." (unless using a systemd service that is). $ sudo -E hydra-create-user bfo --full-name 'Bjørn Forsman' --password bfo --role admin updating existing user `bfo' Best regards, Bjørn Forsman
_______________________________________________ nix-dev mailing list [email protected] http://lists.science.uu.nl/mailman/listinfo/nix-dev
