--- tags: - programming - nix --- While working on a NixOS module I made a realisation on the difference between functional and imperative programming. I was trying to configure `systemd.tmpfiles.rules` to create directories for git repositories. After looking a bit how to iterate; i tried the following: ```nix let paths = ["abs_paths" ...] in { map(p: systemd.tmpfiles.rules = ["d {$p} ..."];); } ``` This is very much originating from the imperative mindset; we loop over a list and then do stuff like setting variables and calling other functions. However in functional programming we do not! This is the correct version in functional programming: ```nix let paths = [ "abs_paths" ... ]; in { systemd.tmpfiles.rules = map(p: "d ${p} ..") paths; } ``` Functions are pure, we can't assign stuff inside of their bodies because that would make them impure. Instead we can just return a value; in this case an array and *then* assign it.