nix

configuration files that power my machines
Log | Files | Refs | README | LICENSE

default.nix (2092B)


      1 {
      2   config,
      3   lib,
      4   inputs,
      5   ...
      6 }: let
      7   sources = import ./npins;
      8 
      9   date = inputs.self.lastModifiedDate or "19700101000000";
     10   year = lib.substring 0 4 date;
     11   monthNum = lib.substring 4 2 date;
     12   month = lib.elemAt [
     13     "january"
     14     "february"
     15     "march"
     16     "april"
     17     "may"
     18     "june"
     19     "july"
     20     "august"
     21     "september"
     22     "october"
     23     "november"
     24     "december"
     25   ] (lib.toInt (lib.removePrefix "0" monthNum) - 1);
     26 
     27   tmplArgs = {
     28     inherit year month;
     29     homeDir = config.home.homeDirectory;
     30   };
     31 
     32   mkMapping = path: prefix: let
     33     scan = dir: rel:
     34       lib.concatLists (lib.mapAttrsToList (name: type: let
     35         newRel =
     36           if rel == ""
     37           then name
     38           else "${rel}/${name}";
     39         newPath = dir + "/${name}";
     40       in
     41         if type == "directory"
     42         then scan newPath newRel
     43         else [
     44           {
     45             name = newRel;
     46             path = newPath;
     47           }
     48         ])
     49       (builtins.readDir dir));
     50   in
     51     builtins.listToAttrs (map (file: let
     52       isNix = lib.hasSuffix ".nix" file.name;
     53       target = prefix + (lib.removeSuffix ".nix" file.name);
     54     in
     55       lib.nameValuePair target (
     56         if isNix
     57         then {
     58           text = import file.path tmplArgs;
     59           force = true;
     60         }
     61         else {
     62           source = file.path;
     63           force = true;
     64         }
     65       )) (scan path ""));
     66 in {
     67   imports = [./plass.nix];
     68 
     69   config = {
     70     home.file =
     71       (mkMapping ./home ".")
     72       // (lib.mapAttrs (_: v: v // {executable = true;}) (mkMapping ./bin "bin/"))
     73       // {
     74         "bin/xpanes" = {
     75           source = "${sources.tmux-xpanes}/bin/xpanes";
     76           executable = true;
     77         };
     78       };
     79 
     80     xdg.configFile =
     81       (mkMapping ./config "")
     82       // {
     83         "zsh/plugins/zsh-autopair".source = sources.zsh-autopair;
     84         "zsh/plugins/zsh-histdb".source = sources.zsh-histdb;
     85         "zsh/plugins/zsh-autosuggestions".source = sources.zsh-autosuggestions;
     86         "zsh/plugins/zsh-completions".source = sources.zsh-completions;
     87       };
     88 
     89     home.sessionPath = ["$HOME/bin"];
     90   };
     91 }