{"action":"created","issue":{"url":"https://api.github.com/repos/NixOS/nixpkgs/issues/7370","labels_url":"https://api.github.com/repos/NixOS/nixpkgs/issues/7370/labels{/name}","comments_url":"https://api.github.com/repos/NixOS/nixpkgs/issues/7370/comments","events_url":"https://api.github.com/repos/NixOS/nixpkgs/issues/7370/events","html_url":"https://github.com/NixOS/nixpkgs/pull/7370","id":68229538,"number":7370,"title":"Configure NixOS from EC2 user-data [don't merge]","user":{"login":"copumpkin","id":2623,"avatar_url":"https://avatars.githubusercontent.com/u/2623?v=3","gravatar_id":"","url":"https://api.github.com/users/copumpkin","html_url":"https://github.com/copumpkin","followers_url":"https://api.github.com/users/copumpkin/followers","following_url":"https://api.github.com/users/copumpkin/following{/other_user}","gists_url":"https://api.github.com/users/copumpkin/gists{/gist_id}","starred_url":"https://api.github.com/users/copumpkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/copumpkin/subscriptions","organizations_url":"https://api.github.com/users/copumpkin/orgs","repos_url":"https://api.github.com/users/copumpkin/repos","events_url":"https://api.github.com/users/copumpkin/events{/privacy}","received_events_url":"https://api.github.com/users/copumpkin/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/NixOS/nixpkgs/labels/feedback-requested","name":"feedback-requested","color":"f7c6c7"},{"url":"https://api.github.com/repos/NixOS/nixpkgs/labels/in%20progress","name":"in progress","color":"ededed"}],"state":"open","locked":false,"assignee":{"login":"copumpkin","id":2623,"avatar_url":"https://avatars.githubusercontent.com/u/2623?v=3","gravatar_id":"","url":"https://api.github.com/users/copumpkin","html_url":"https://github.com/copumpkin","followers_url":"https://api.github.com/users/copumpkin/followers","following_url":"https://api.github.com/users/copumpkin/following{/other_user}","gists_url":"https://api.github.com/users/copumpkin/gists{/gist_id}","starred_url":"https://api.github.com/users/copumpkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/copumpkin/subscriptions","organizations_url":"https://api.github.com/users/copumpkin/orgs","repos_url":"https://api.github.com/users/copumpkin/repos","events_url":"https://api.github.com/users/copumpkin/events{/privacy}","received_events_url":"https://api.github.com/users/copumpkin/received_events","type":"User","site_admin":false},"milestone":null,"comments":21,"created_at":"2015-04-14T00:51:24Z","updated_at":"2015-04-29T06:27:13Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/NixOS/nixpkgs/pulls/7370","html_url":"https://github.com/NixOS/nixpkgs/pull/7370","diff_url":"https://github.com/NixOS/nixpkgs/pull/7370.diff","patch_url":"https://github.com/NixOS/nixpkgs/pull/7370.patch"},"body":"[See #6662 for more discussion of how I got here and why I'm doing it this way]\r\n\r\nThis is my initial attempt at getting a working configure-from-user-data NixOS image working. The basic idea is to create an \"unstable\" NixOS image: its `/etc/nixos/configuration.nix` doesn't actually specify the way the machine is configured, but rather assumes that an `/etc/nixos/amazon-init.nix` exists, which is not bundled inside the image. Instead of bundling `amazon-init.nix`, the image bundles a `postBootCommands` script that downloads the EC2 user-data and writes it into `/etc/nixos/amazon-init.nix`.\r\n\r\nThe \"unstable\" NixOS image thus only configures itself from user-data on first boot, since when it calls `nixos-rebuild switch` on your personalized configuration, the custom `postBootCommands` will go away.\r\n\r\nUser-data should look something like:\r\n\r\n```nix\r\n### http://nixos.org/channels/nixos-unstable nixos\r\n\r\n{\r\n  # Insert your config here, and you'll probably not want me to log into your box so\r\n  # change the user below, or don't put one there at all!\r\n\r\n  security.sudo.wheelNeedsPassword = false;\r\n\r\n  users.extraUsers.copumpkin = \r\n    { createHome      = true;\r\n      home            = \"/home/copumpkin\";\r\n      description     = \"Dan P\";\r\n      extraGroups     = [ \"wheel\" ];\r\n      useDefaultShell = true;\r\n      openssh.authorizedKeys.keys = [\r\n        \"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCkoril5uKjJohHvqz9Ys9R2rBH95MUb4Rxo5kcuRvEIwMranQ7xP5eU7rZqfv7elE1DLfMs19via+btUX3w8o4juYxzXjafnH6Mck5hYdvxNnErW6gsp0vGDQ0ruRCQx3UmOuC5Ld/wXY7iMQqOlxeLZF2dVCKP1+BSs37wLC7scXYu0U+wODprVpAsZIOwLP85w/uCNlC8wbvNDWG+Hx+XD/ml2ezQiNBRnh7Qo3QKgpUvVBO0d9z84g92D2H9IA+pEpJiWFcYKGEowKSVQVFCi5LoWRiz8XLKL+JeBt5mmmqjmJua6o8lXV7+nba//KCIkG+IWS4nwKQlpzZXc4H\"\r\n      ];\r\n    };\r\n}\r\n```\r\n\r\nOne thing to note is the `###` section at the top, which specifies the channels (I just strip off the `###` and direct into `~/.nix-channels`)\r\n\r\nIf you trust me and want to try it out, I'm hosting a public AMI (until I get sick of paying for storage) of the above with ID `ami-1c477874`.\r\n\r\nQuestions for anyone still reading:\r\n* Is this the best way to do it? The `postBootCommands` with periodic timed check feels kind of hacky, but I also can't use a systemd service and activation scripts didn't work either.\r\n* Is this the best format for user-data? I like it because it's simple, specifies the full machine (with channels, although I'm not necessarily sold on the `###` convention), and is very clearly just nixos configuration. Unfortunately it's not compatible with the existing format nixops uses for its temporary host keys, but I'd rather make it use a clean nix configuration file than force this into that format and have to deal with escaping and other ugliness. I haven't used NixOps much so perhaps it'll be too painful to transition it, but if possible I'd like the user-data format to be clean.\r\n\r\nNote that it's still a WIP, so I'll obviously take out the useless `echo` calls and such before merging :smile: \r\n\r\ncc @edolstra @shlevy @rbvermaa "},"comment":{"url":"https://api.github.com/repos/NixOS/nixpkgs/issues/comments/97321213","html_url":"https://github.com/NixOS/nixpkgs/pull/7370#issuecomment-97321213","issue_url":"https://api.github.com/repos/NixOS/nixpkgs/issues/7370","id":97321213,"user":{"login":"cstrahan","id":143982,"avatar_url":"https://avatars.githubusercontent.com/u/143982?v=3","gravatar_id":"","url":"https://api.github.com/users/cstrahan","html_url":"https://github.com/cstrahan","followers_url":"https://api.github.com/users/cstrahan/followers","following_url":"https://api.github.com/users/cstrahan/following{/other_user}","gists_url":"https://api.github.com/users/cstrahan/gists{/gist_id}","starred_url":"https://api.github.com/users/cstrahan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cstrahan/subscriptions","organizations_url":"https://api.github.com/users/cstrahan/orgs","repos_url":"https://api.github.com/users/cstrahan/repos","events_url":"https://api.github.com/users/cstrahan/events{/privacy}","received_events_url":"https://api.github.com/users/cstrahan/received_events","type":"User","site_admin":false},"created_at":"2015-04-29T06:27:13Z","updated_at":"2015-04-29T06:27:13Z","body":"@copumpkin How do you build an AMI?"}}