{"action":"created","issue":{"url":"https://api.github.com/repos/NixOS/nixpkgs/issues/18526","repository_url":"https://api.github.com/repos/NixOS/nixpkgs","labels_url":"https://api.github.com/repos/NixOS/nixpkgs/issues/18526/labels{/name}","comments_url":"https://api.github.com/repos/NixOS/nixpkgs/issues/18526/comments","events_url":"https://api.github.com/repos/NixOS/nixpkgs/issues/18526/events","html_url":"https://github.com/NixOS/nixpkgs/pull/18526","id":176299447,"number":18526,"title":"Use mkEnableOption throughout Nixos where appropriate","user":{"login":"siddharthist","id":4294323,"avatar_url":"https://avatars.githubusercontent.com/u/4294323?v=3","gravatar_id":"","url":"https://api.github.com/users/siddharthist","html_url":"https://github.com/siddharthist","followers_url":"https://api.github.com/users/siddharthist/followers","following_url":"https://api.github.com/users/siddharthist/following{/other_user}","gists_url":"https://api.github.com/users/siddharthist/gists{/gist_id}","starred_url":"https://api.github.com/users/siddharthist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/siddharthist/subscriptions","organizations_url":"https://api.github.com/users/siddharthist/orgs","repos_url":"https://api.github.com/users/siddharthist/repos","events_url":"https://api.github.com/users/siddharthist/events{/privacy}","received_events_url":"https://api.github.com/users/siddharthist/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2016-09-12T05:53:00Z","updated_at":"2016-09-19T10:25:58Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/NixOS/nixpkgs/pulls/18526","html_url":"https://github.com/NixOS/nixpkgs/pull/18526","diff_url":"https://github.com/NixOS/nixpkgs/pull/18526.diff","patch_url":"https://github.com/NixOS/nixpkgs/pull/18526.patch"},"body":"###### Motivation for this change\r\nFrom #18524:\r\n\r\n> Many, many services use the following snippet:\r\n> ```nix\r\n>       enable = mkOption {\r\n>         default = false;\r\n>         type = types.bool;\r\n>         description = ''\r\n>           Whether to enable Mopidy, a music player daemon.\r\n>         '';\r\n>       };\r\n> ```\r\n> That's why `mkEnableOption` was created! \r\n> ```nix\r\n>   mkEnableOption = name: mkOption {\r\n>     default = false;\r\n>     example = true;\r\n>     description = \"Whether to enable ${name}.\";\r\n>     type = lib.types.bool;\r\n>   };\r\n> ```\r\n\r\nI wrote this script:\r\n```bash\r\n#!/usr/bin/env nix-shell\r\n#! nix-shell -i bash -p ag\r\n\r\ngit checkout master nixos/modules/\r\ncd \"nixos/modules\"\r\n\r\n# Loop through files with \"enable = mkOption\"\r\nfor file in $(IFS=\\n ag -l \"enable = mkOption\"); do\r\n  # This line will exit 0 if the default for \"enable\" is false.\r\n  if perl -0777 -e 'exit 1 if (<STDIN> =~ m/.+?enable\\s+=\\s+mkOption\\s+{(.|\\n)+?default\\s+=\\s+true;(.|\\n)+?};/)' < \"$file\"; then\r\n    # This line will replace\r\n    # enable = mkEnableOption \"Foobar, the baz\";\r\n    # with\r\n    # enable = mkEnableOption \"Foobar, the baz\";\r\n    perl -0777 -p -i -e 's/(.+?)enable\\s+?=\\s+?mkOption\\s+?\\{.+?enable ([^\\n]+?)\\..+?};/\\1enable = mkEnableOption \"\\2\";/igs' \"$file\"\r\n  fi\r\ndone\r\n\r\ncd ../../\r\n# Loop through the modified files and confirm the diffs\r\nfor file in $(git status --porcelain | awk 'match($1, \"M\"){print $2}'); do\r\n  echo \"----------------------------------------------------\"\r\n  echo \"Does the diff look ok for $file?\"\r\n  echo \"----------------------------------------------------\"\r\n  git --no-pager diff master \"$file\"\r\n  read -r -p \"[y/N]: \" response\r\n  case $response in\r\n    [yY][eE][sS]|[yY])\r\n      git add \"$file\"\r\n      tmp=${file%.nix}\r\n      name=${tmp##*/}\r\n      git commit -m \"$name module: use mkEnableOption\"\r\n      ;;\r\n    *)\r\n      git checkout master \"$file\"\r\n      ;;\r\n  esac\r\ndone\r\n```\r\nI was conservative, and only accepted diffs where the description was close to exactly the same. I've also broken it up into a commit per file, which will allow for easier reverting (without redoing all this work), should a problem arise. \r\n\r\nNext steps would be to review the diffs where the script broke/did not correctly fill in the description, and manually change those to use `mkEnableOption`.  \r\n\r\n###### Things done\r\n\r\n- [ ] Tested using sandboxing\r\n  ([nix.useSandbox](http://nixos.org/nixos/manual/options.html#opt-nix.useSandbox) on NixOS,\r\n    or option `build-use-sandbox` in [`nix.conf`](http://nixos.org/nix/manual/#sec-conf-file)\r\n    on non-NixOS)\r\n- Built on platform(s)\r\n   - [ ] NixOS\r\n   - [ ] OS X\r\n   - [ ] Linux\r\n- [ ] Tested compilation of all pkgs that depend on this change using `nix-shell -p nox --run \"nox-review wip\"`\r\n- [ ] Tested execution of all binary files (usually in `./result/bin/`)\r\n- [x] Fits [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/.github/CONTRIBUTING.md).\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/NixOS/nixpkgs/issues/comments/247958569","html_url":"https://github.com/NixOS/nixpkgs/pull/18526#issuecomment-247958569","issue_url":"https://api.github.com/repos/NixOS/nixpkgs/issues/18526","id":247958569,"user":{"login":"rasendubi","id":1366419,"avatar_url":"https://avatars.githubusercontent.com/u/1366419?v=3","gravatar_id":"","url":"https://api.github.com/users/rasendubi","html_url":"https://github.com/rasendubi","followers_url":"https://api.github.com/users/rasendubi/followers","following_url":"https://api.github.com/users/rasendubi/following{/other_user}","gists_url":"https://api.github.com/users/rasendubi/gists{/gist_id}","starred_url":"https://api.github.com/users/rasendubi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rasendubi/subscriptions","organizations_url":"https://api.github.com/users/rasendubi/orgs","repos_url":"https://api.github.com/users/rasendubi/repos","events_url":"https://api.github.com/users/rasendubi/events{/privacy}","received_events_url":"https://api.github.com/users/rasendubi/received_events","type":"User","site_admin":false},"created_at":"2016-09-19T10:25:58Z","updated_at":"2016-09-19T10:25:58Z","body":"After a week, feedback is mostly negative. I propose to close this."}}
{"actor":{"display_login":"rasendubi"}}