4 ms·
Managing dotfiles with Make
- qudat 1y agoIt’s always fun to see what other people do for dotfile mgmt. I have a simple bash script that does something similar: https://erock-git-dotfiles.pgs.sh/tree/main/item/dotfiles.sh.html https://erock-git-dotfiles.pgs.sh/tree/main/item/dotfiles.sh...
- bbkane 1y agoThis is very clever, but I'd have to relearn Make's subtleties each time I tried to debug it or add a feature (count me in the "prefer to avoid it" crowd). I ended up writing a Go CLI to symlink my dotfiles. It's probably 10x more lines of code, but it uses a "plan, then execute" pattern, similar to Terraform that I find easier to test and clearer to use too. And it's a single binary so it's easy to install on Windows too.
- mcgrath_sh 1y agoI use a combination of stow and make to manage my dotfiles. I added a makefile well after using stow for a decade. The makefile is more for new system setup than day to day management. I might try out replacing stow with make based on this blog, more for fun than anything. I'm a bit reluctant to replace what has been working so well for a decade, but I'm very intrigued by this. Make has always interested me. It seems like it could be incredibly powerful in the right hands.
- doubled112 1y agoI've been using Chezmoi for a little while now. It simplifies what I want to do better than anything else I have tried.
- thayne 1y agoChezmoi is probably the best thing I've found. But I do have aome complaints about it. I don't love the filenames, and using symlinks often feels like a second class citizen. It also has the downside that you have to install and set up chezmoi first, and it isn't included in the debian or ubuntu repos.
- staticshock 1y agoI do this and like it: https://github.com/staticshock/dotfiles/blob/main/Makefile https://github.com/staticshock/dotfiles/blob/main/Makefile I also tend to put a Makefile into the root of any repo I work in (ignored via .git/info/exclude), so that shell commands relevant to my workflow can accumulate under that Makefile. I've been doing this for at least 10 years and love it. Most repos have some sort of a cli interface, but that doesn't mean that they're any good. Make is nice way to wrap all of them, and to standardize on at least the build/test/run commands across many disparate repos. Here's an example of one of those from a long-abandoned project: https://gist.github.com/staticshock/0e88a3232038d14a2817e105f9eaf85f https://gist.github.com/staticshock/0e88a3232038d14a2817e105...
- cortesoft 1y agoIs there a reason to not include your makefile in the git repo? Is it not useful to anyone else?
- belden 1y agoSpeaking for myself, reasons why I don’t immediately share my own tooling: Perhaps I want to hold it to my own standard for tooling, not the team’s. Perhaps I want to write it in a language that the team doesn’t really embrace. I might not think it’s worth anyone’s time to code review changes I make to my own tools. I might want to do something dumb like bake an API key into the tool. Maybe the project already has a similar tool, and I don’t want to explain why I am wrapping/ignoring it. In short: sometimes the cost to collaborate on idiosyncratic tools is just higher than I’m willing to pay.
- munksbeer 1y agoSadly, I do the same at times. I just want to hack together something that works for my use case. If I can share that with the wider team, that is superb. But I really don't enjoy my hacky utils being subject to tedious code review scrutiny they don't deserve. To be clear, I _do_ add utils that I think will be useful to the common repo, subject to review, and mostly they will be merged. But if it gets painful, I just retract the PR and keep it locally.
- monkaiju 1y agoBeen using yadm for a long time and i love it. super simple and has the "bootstrap" concept as an escape hatch for when i want to get weeeird
- haolez 1y agoWhat worked best for me is to turn my user's home dir into a Git repository. My .gitignore contains this: * And if I need to add something, I just "git add -f ...". Works surprisingly well. Combines well with git-secret for things like SSH keys, certificates and API keys.
- lucasoshiro 1y agoI wouldn't trust that... If you by mistake run `git clean -xfd` in your home, well, you know what happens
- fouc 1y agoHa, I'll probably never run that command but perhaps some git commands can be disabled if they're run in ~/
- Ferret7446 1y agoSame thing as running `rm -rf *` by mistake. Don't do that and keep backups.
- fouc 1y agoneat, TIL https://sobolevn.me/git-secret/ https://sobolevn.me/git-secret/
- dp-hackernews 1y agoOr git-crypt or SOPS
- kryptn 1y agomy dotfiles follow atlassian's tutorial where they do this, but put the git dir somewhere else and alias away the git command. It has worked pretty well for me. https://www.atlassian.com/git/tutorials/dotfiles https://www.atlassian.com/git/tutorials/dotfiles
- RichardLake 1y agoOnly downside to this are tools that default to only acting on stuff under version control. Whenever I use rg inside my home directory I'm caught out by this.
- dinkleberg 1y agoNothing beats nix + home manager. But it is fun to see how many different ways people go about solving this particular problem. All of them have their tradeoffs and annoyances.
- whacked_new 1y agoI advocate (and use) nix + home manager too but when you need a one-off change or test and realize you need to do the whole commit and switch thing, or when you are debugging and spelunk through the read only nix store, or when you set up a new (non-nix) computer and do the nix install, home-manager install, run the switch and get a deluge of errors... it's simultaneously awesome but "can I really recommend this to <colleague>?"
- AgentElement 1y agoWith nix + home manager, you can use `mkOutOfStoreSymlink` to make symlinks between the dotfile repo and the target destination in `.config`. I've found this to be the most ergonomic way to have nix-managed dotfiles. Because the out-of-store dotfile repo is symlinked, you can make little changes to your system without doing the whole commit and switch dance. For example, here's a snippet pulled from my dotfiles that does this for multiple dotfiles at once: home.file = builtins.mapAttrs (key: value: { # symlink ~/dotfiles/configs/{value} to ~/{key} source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/dotfiles/configs/${value}"; }) { ".zshrc" = "zsh/zshrc"; ".p10k.zsh" = "zsh/p10k.zsh"; ".config/sway/config" = "sway/config"; ".config/nvim/init.lua" = "nvim/init.lua"; };
- nothrabannosir 1y agoCaveat: This works for literal dotfiles in your repo but it doesn’t help you if you use nix declared config, e.g. programs.git
- whacked_new 1y ago
- adg33 1y agoI use Make with GNU Stow for dotfiles targeting different operating systems, with a Nix Flake for shell tools: https://github.com/ADGEfficiency/dotfiles/blob/main/Makefile https://github.com/ADGEfficiency/dotfiles/blob/main/Makefile It works fine - most of my time is still spent in configuring Neovim ^^
- wingmanjd 1y agoI found Andrew Burgess's method approachable and ended up cribbing from his dotfiles concept [1] and making my own repository [2]. His method uses bash instead of make to create the symlinks defined in the links.prop file in each subdir of the repo. I typically checkout the dotfiles repo to a personal project folder on every new OS build and then run the installer to get all my configs in place. - [1] https://shaky.sh/simple-dotfiles/ https://shaky.sh/simple-dotfiles/ - [2] https://gitlab.com/jgonyea/dotfiles https://gitlab.com/jgonyea/dotfiles
- obezyian 1y agoArticles like this one are more likely to drive people away from make(1) than teach them to appreciate it. This Makefile is anything but simple. It uses advanced features that are meant for complicated situations, just to create a few symlinks. The same symlinks, every time. And if you introduce a new dotfile to the repo, you have to update the Makefile too. It also makes no use of the main feature of make(1) - to track files for changes, and update them. For demonstration, here is the same functionality, in sh(1): files=$(find files -type f | sed s=^files/==) echo "$files" | sed s=[^/]*\$== | sort -u | { cd; xargs mkdir -p; } echo "$files" | xargs -I{} -n1 ln -sf $PWD/files/{} ~/{} Doesn't use advanced features, shorter, and you don't need to update the script for new dotfiles. And more "ubiquitous" than GNU make.
- lloeki 1y ago> This Makefile is anything but simple. This makefile does look simple to me, although it is not easy; but TFA never claimed it was supposed to be "easy". The shell you mentioned is not in any way "simpler" nor even "easier". The same thing can be done with bash substitutions and loops (all supported by zsh), and someone would argue that it'd be simpler by virtue of not suffering e.g gnu vs bsd vs posix sed nor needing xargs; also, pipefail and such. Also it doesn't do "the same thing": you have to be at a specific pwd and not in any subdir + you can't do a subset (e.g "make git") Note I'm not saying it's better or worse. I really like the article as it showcased a few advanced make features in a concrete and limited use case (symlinks). The result is simple to use and maintain.
- frou_dh 1y agoI do like Make so quite an interesting article, but the author seems overly impressed with their idea of using a literal ~ for the name of the subdirectory. That adds an unnecessary WTF factor to the code in my opinion :)
- camilomatajira 1y agoNice article, I love Make and your blog looks sharp. I would suggest to provide the beginner friendly version in which all the rules are hard coded, so that a beginner can profit and don't be freightened. And then, introduce the problem of needing to add rules by hand for each new dotfile, and then provide your solution using Make's builtins. I also suggest putting the complete final version of the Makefile at then end, so I can copy it. Regards,
- zokier 1y agoI don't understand what "managing" this accomplishes?
- balazs4 1y agoThanks for sharing! It is good to see that other ppl uses make for dotfiles. Here is mine: https://github.com/balazs4/dotfiles/blob/canary/makefile https://github.com/balazs4/dotfiles/blob/canary/makefile I am pretty happy about it nowadays; it works for me. Cheers