Commit b436b6bb4eb6

Vincent Demeester <vincent@sbr.pm>
2022-04-15 16:58:22
Initiate `flake` migration…
… taking inspiration from different configurations. Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent a23dd26
docs/moving-home-to-nix-flakes.org
@@ -0,0 +1,30 @@
+#+TITLE: Moving =home= to nix flakes
+#+FILETAGS: #home nix dotfiles configuration
+
+This document is a /live/ document on moving this =monorepo= to using nix flakes. It will go
+through why as well as trying to dig around what was done for it.
+
+* Why flakes
+
+#+begin_quote
+Nix is a package manager that lets you have a more deterministic view of your software
+dependencies and build processes. One if its biggest weaknesses out of the box is that
+there are very few conventions on how projects using Nix should work together. It's like
+having a build system but also having to configure systems to run software yourself. This
+could mean copying a NixOS module out of the project's git repo, writing your own or
+more. In contrast to this, Nix flakes define a set of conventions for how software can be
+build, run, integrated and deployed without having to rely on external tools such as Niv
+or Lorri to help you do basic tasks in a timely manner.
+– from [[https://christine.website/blog/nix-flakes-1-2022-02-21]]
+#+end_quote
+
+Nix flakes seems to be more and more stable and usable, and thus, as I needed to
+re-install one of my laptop powered by NixOS, I felt I would migrate the repository
+towards nix flakes.
+
+The idea is to make this repository a "flake-enabled" repository while still working with
+the current setup I have (=niv=, =morph=, …).
+
+* Digging into the flake
+
+#+include: "../flake.nix"
nix/lib/default.nix
@@ -0,0 +1,10 @@
+inputs:
+
+# personal lib
+let
+  inherit (inputs.nixpkgs) lib;
+
+  home = import ./home.nix inputs;
+  system = import ./system.nix inputs;
+in
+lib // home // system
nix/lib/home.nix
@@ -0,0 +1,20 @@
+inputs:
+
+let
+  inherit (inputs) self;
+  inherit (inputs.home-manager.lib) homeManagerConfiguration;
+
+  extraSpecialArgs = { inherit inputs; };
+
+  defArgs = rec {
+    configuration = { };
+    system = "x86_64-linux";
+    inherit extraSpecialArgs;
+  };
+
+  mkHome = args: homeManagerConfiguration (defArgs // args // {
+    homeDirectory = "/home/${args.username}";
+    pkgs = inputs.self.pkgs.${args.system or defArgs.system};
+  });
+in
+{ inherit mkHome extraSpecialArgs; }
nix/lib/system.nix
@@ -0,0 +1,14 @@
+inputs:
+
+let
+  inherit (inputs.nixpkgs) lib;
+in
+rec {
+  supportedSystems = [ "aarch64-linux" "x86_64-linux" ];
+
+  genSystems = lib.genAttrs supportedSystems;
+
+  nixpkgsFor = genSystems (system: overlays: import inputs.nixpkgs {
+    inherit system overlays;
+  });
+}
nix/modules/default.nix
@@ -0,0 +1,2 @@
+{ pkgs, ... }:
+{ }
systems/hosts/default.nix
@@ -0,0 +1,33 @@
+inputs:
+
+let
+  inherit (inputs) self;
+
+  sharedModules = [
+    { _module.args = { inherit inputs; }; }
+    #../modules/minimal.nix
+    #../modules/security.nix
+    inputs.home-manager.nixosModule
+    {
+      home-manager = {
+        inherit (inputs.self.lib) extraSpecialArgs;
+        useGlobalPkgs = true;
+      };
+    }
+  ];
+
+  inherit (self.lib) nixosSystem makeOverridable;
+  # inherit (import "${self}/home/profiles" inputs) homeImports;
+in
+{
+  # naruhodo
+  naruhodo = nixosSystem {
+    modules = [
+    ] ++ sharedModules;
+    system = "x86_64-linux";
+  };
+  # shikoku
+  # aomi
+  # wakasu
+  # sakhalin
+}
systems/hosts/deploy.nix
@@ -0,0 +1,16 @@
+inputs:
+
+{
+  nodes = with inputs.deploy-rs-lib.x86_64-linux; {
+    aomi = { };
+    sakhalin = { };
+    shikoku = {
+      hostname = "shikoku.home";
+      profiles.system = {
+        user = "root";
+        path = activate.nixos inputs.self.nixosConfigurations.shikoku;
+      };
+    };
+    wakasu = { };
+  };
+}
users/profiles.nix
@@ -0,0 +1,39 @@
+inputs:
+
+let
+  inherit (inputs) self;
+  inherit (self.lib) mkHome extraSpecialArgs;
+
+  sharedModules = [
+    # ../.
+    # ../files
+    # ../shell
+    # ../games.nix
+    # ../media.nix
+  ];
+
+  homeImports = {
+    "vincent@naruhodo" = sharedModules ++ [ ../wayland ./mihai-io ../editors/emacs ];
+    # "vincent@aomi" = sharedModules ++ [ ../wayland ./mihai-tosh ];
+    "vincent@okinawa" = sharedModules ++ [ ../wayland ./mihai-tosh ];
+    server = [ ../cli.nix ];
+  };
+in
+{
+  inherit homeImports extraSpecialArgs;
+
+  homeConfigurations = {
+    "vincent@naruhodo" = {
+      username = "vincent";
+      extraModules = homeImports."vincent@naruhodo";
+    };
+    "vincent@okinawa" = {
+      username = "vincent";
+      extraModules = homeImports."vincent@naruhodo";
+    };
+    "server" = {
+      username = "vincent";
+      extraModules = homeImports.server;
+    };
+  };
+}
flake.lock
@@ -0,0 +1,294 @@
+{
+  "nodes": {
+    "deploy-rs": {
+      "inputs": {
+        "flake-compat": "flake-compat",
+        "nixpkgs": [
+          "nixpkgs"
+        ],
+        "utils": [
+          "flake-utils"
+        ]
+      },
+      "locked": {
+        "lastModified": 1648475189,
+        "narHash": "sha256-gAGAS6IagwoUr1B0ohE3iR6sZ8hP4LSqzYLC8Mq3WGU=",
+        "owner": "serokell",
+        "repo": "deploy-rs",
+        "rev": "83e0c78291cd08cb827ba0d553ad9158ae5a95c3",
+        "type": "github"
+      },
+      "original": {
+        "owner": "serokell",
+        "repo": "deploy-rs",
+        "type": "github"
+      }
+    },
+    "devshell": {
+      "inputs": {
+        "flake-utils": "flake-utils",
+        "nixpkgs": "nixpkgs"
+      },
+      "locked": {
+        "lastModified": 1649691969,
+        "narHash": "sha256-nY1aUWIyh3TcGVo3sn+3vyCh+tOiEZL4JtMX3aOZSeY=",
+        "owner": "numtide",
+        "repo": "devshell",
+        "rev": "e22633b05fec2fe196888c593d4d9b3f4f648a25",
+        "type": "github"
+      },
+      "original": {
+        "owner": "numtide",
+        "repo": "devshell",
+        "type": "github"
+      }
+    },
+    "emacs-overlay": {
+      "locked": {
+        "lastModified": 1649819967,
+        "narHash": "sha256-JWQndTHQmR1k1h4iHoo0ns815QRibzzxoCigTlsHEWQ=",
+        "owner": "nix-community",
+        "repo": "emacs-overlay",
+        "rev": "3f368b1be2df5a23a6d944eced1e9612a903feb6",
+        "type": "github"
+      },
+      "original": {
+        "owner": "nix-community",
+        "repo": "emacs-overlay",
+        "type": "github"
+      }
+    },
+    "flake-compat": {
+      "flake": false,
+      "locked": {
+        "lastModified": 1648199409,
+        "narHash": "sha256-JwPKdC2PoVBkG6E+eWw3j6BMR6sL3COpYWfif7RVb8Y=",
+        "owner": "edolstra",
+        "repo": "flake-compat",
+        "rev": "64a525ee38886ab9028e6f61790de0832aa3ef03",
+        "type": "github"
+      },
+      "original": {
+        "owner": "edolstra",
+        "repo": "flake-compat",
+        "type": "github"
+      }
+    },
+    "flake-compat_2": {
+      "flake": false,
+      "locked": {
+        "lastModified": 1648199409,
+        "narHash": "sha256-JwPKdC2PoVBkG6E+eWw3j6BMR6sL3COpYWfif7RVb8Y=",
+        "owner": "edolstra",
+        "repo": "flake-compat",
+        "rev": "64a525ee38886ab9028e6f61790de0832aa3ef03",
+        "type": "github"
+      },
+      "original": {
+        "owner": "edolstra",
+        "repo": "flake-compat",
+        "type": "github"
+      }
+    },
+    "flake-utils": {
+      "locked": {
+        "lastModified": 1642700792,
+        "narHash": "sha256-XqHrk7hFb+zBvRg6Ghl+AZDq03ov6OshJLiSWOoX5es=",
+        "owner": "numtide",
+        "repo": "flake-utils",
+        "rev": "846b2ae0fc4cc943637d3d1def4454213e203cba",
+        "type": "github"
+      },
+      "original": {
+        "owner": "numtide",
+        "repo": "flake-utils",
+        "type": "github"
+      }
+    },
+    "flake-utils_2": {
+      "locked": {
+        "lastModified": 1649676176,
+        "narHash": "sha256-OWKJratjt2RW151VUlJPRALb7OU2S5s+f0vLj4o1bHM=",
+        "owner": "numtide",
+        "repo": "flake-utils",
+        "rev": "a4b154ebbdc88c8498a5c7b01589addc9e9cb678",
+        "type": "github"
+      },
+      "original": {
+        "owner": "numtide",
+        "repo": "flake-utils",
+        "type": "github"
+      }
+    },
+    "home-manager": {
+      "inputs": {
+        "nixpkgs": [
+          "nixpkgs"
+        ]
+      },
+      "locked": {
+        "lastModified": 1649642044,
+        "narHash": "sha256-V9ZjTJcbDPgWG+H3rIC6XuPHZAPK1VupBbSsuDbptkQ=",
+        "owner": "nix-community",
+        "repo": "home-manager",
+        "rev": "e39a9d0103e3b2e42059c986a8c633824b96c193",
+        "type": "github"
+      },
+      "original": {
+        "owner": "nix-community",
+        "repo": "home-manager",
+        "type": "github"
+      }
+    },
+    "home-manager-stable": {
+      "inputs": {
+        "nixpkgs": [
+          "nixos-21_11"
+        ]
+      },
+      "locked": {
+        "lastModified": 1649887911,
+        "narHash": "sha256-Af0Ppb1RZ7HWuxUvF0/O7h3cy8tqU2eKFyVwyA1ZD+w=",
+        "owner": "nix-community",
+        "repo": "home-manager",
+        "rev": "7244c6715cb8f741f3b3e1220a9279e97b2ed8f5",
+        "type": "github"
+      },
+      "original": {
+        "owner": "nix-community",
+        "ref": "release-21.11",
+        "repo": "home-manager",
+        "type": "github"
+      }
+    },
+    "impermanence": {
+      "locked": {
+        "lastModified": 1646131459,
+        "narHash": "sha256-GPmgxvUFvQ1GmsGfWHy9+rcxWrczeDhS9XnAIPHi9XQ=",
+        "owner": "nix-community",
+        "repo": "impermanence",
+        "rev": "2f39baeb7d039fda5fc8225111bb79474138e6f4",
+        "type": "github"
+      },
+      "original": {
+        "owner": "nix-community",
+        "repo": "impermanence",
+        "type": "github"
+      }
+    },
+    "nixos-21_11": {
+      "locked": {
+        "lastModified": 1649619156,
+        "narHash": "sha256-p0q4zpuKMwrzGF+5ZU7Thnpac5TinhDI9jr2mBxhV4w=",
+        "owner": "NixOS",
+        "repo": "nixpkgs",
+        "rev": "e7d63bd0d50df412f5a1d8acfa3caae75522e347",
+        "type": "github"
+      },
+      "original": {
+        "owner": "NixOS",
+        "ref": "nixos-21.11",
+        "repo": "nixpkgs",
+        "type": "github"
+      }
+    },
+    "nixos-unstable": {
+      "locked": {
+        "lastModified": 1649673231,
+        "narHash": "sha256-1T3AFscfS7s9pkFA+UIDrHH3/RLVjRdYs5ImuLYpOlE=",
+        "owner": "NixOS",
+        "repo": "nixpkgs",
+        "rev": "33772708c6d0e33f697426ba386aa0149cbcbecb",
+        "type": "github"
+      },
+      "original": {
+        "owner": "NixOS",
+        "ref": "nixos-unstable",
+        "repo": "nixpkgs",
+        "type": "github"
+      }
+    },
+    "nixpkgs": {
+      "locked": {
+        "lastModified": 1643381941,
+        "narHash": "sha256-pHTwvnN4tTsEKkWlXQ8JMY423epos8wUOhthpwJjtpc=",
+        "owner": "NixOS",
+        "repo": "nixpkgs",
+        "rev": "5efc8ca954272c4376ac929f4c5ffefcc20551d5",
+        "type": "github"
+      },
+      "original": {
+        "owner": "NixOS",
+        "ref": "nixpkgs-unstable",
+        "repo": "nixpkgs",
+        "type": "github"
+      }
+    },
+    "nixpkgs-unstable": {
+      "locked": {
+        "lastModified": 1648219316,
+        "narHash": "sha256-Ctij+dOi0ZZIfX5eMhgwugfvB+WZSrvVNAyAuANOsnQ=",
+        "owner": "NixOS",
+        "repo": "nixpkgs",
+        "rev": "30d3d79b7d3607d56546dd2a6b49e156ba0ec634",
+        "type": "github"
+      },
+      "original": {
+        "owner": "NixOS",
+        "ref": "nixpkgs-unstable",
+        "repo": "nixpkgs",
+        "type": "github"
+      }
+    },
+    "nixpkgs_2": {
+      "locked": {
+        "lastModified": 1649809588,
+        "narHash": "sha256-f6sgDj9A8FXTVyA2zkxA66YX+j6BftxE9VHTeIMhEKE=",
+        "owner": "NixOS",
+        "repo": "nixpkgs",
+        "rev": "ff9efb0724de5ae0f9db9df2debefced7eb1571d",
+        "type": "github"
+      },
+      "original": {
+        "owner": "NixOS",
+        "ref": "nixos-unstable",
+        "repo": "nixpkgs",
+        "type": "github"
+      }
+    },
+    "nur": {
+      "locked": {
+        "lastModified": 1649835308,
+        "narHash": "sha256-YCQuEXmakGFQihFPHl3yhls3Ou3pILQDTeEf+CJhtB0=",
+        "owner": "nix-community",
+        "repo": "NUR",
+        "rev": "28556f4175d82d3b5fa6b3c0df439617bf511ce4",
+        "type": "github"
+      },
+      "original": {
+        "owner": "nix-community",
+        "repo": "NUR",
+        "type": "github"
+      }
+    },
+    "root": {
+      "inputs": {
+        "deploy-rs": "deploy-rs",
+        "devshell": "devshell",
+        "emacs-overlay": "emacs-overlay",
+        "flake-compat": "flake-compat_2",
+        "flake-utils": "flake-utils_2",
+        "home-manager": "home-manager",
+        "home-manager-stable": "home-manager-stable",
+        "impermanence": "impermanence",
+        "nixos-21_11": "nixos-21_11",
+        "nixos-unstable": "nixos-unstable",
+        "nixpkgs": "nixpkgs_2",
+        "nixpkgs-unstable": "nixpkgs-unstable",
+        "nur": "nur"
+      }
+    }
+  },
+  "root": "root",
+  "version": 7
+}
flake.nix
@@ -0,0 +1,92 @@
+{
+  description = "System Config";
+
+  inputs = {
+    # Flake for compatibility with non-flake commands
+    flake-compat = { type = "github"; owner = "edolstra"; repo = "flake-compat"; flake = false; };
+    flake-utils = { type = "github"; owner = "numtide"; repo = "flake-utils"; };
+    devshell = { type = "github"; owner = "numtide"; repo = "devshell"; };
+
+    # Flake Dependencies
+    home-manager = { type = "github"; owner = "nix-community"; repo = "home-manager"; inputs.nixpkgs.follows = "nixpkgs"; };
+    home-manager-stable = { type = "github"; owner = "nix-community"; repo = "home-manager"; ref = "release-21.11"; inputs.nixpkgs.follows = "nixos-21_11"; };
+    impermanence = { type = "github"; owner = "nix-community"; repo = "impermanence"; };
+    nur.url = "github:nix-community/NUR";
+    emacs-overlay.url = "github:nix-community/emacs-overlay";
+    deploy-rs = {
+      type = "github";
+      owner = "serokell";
+      repo = "deploy-rs";
+      inputs.utils.follows = "flake-utils";
+      inputs.nixpkgs.follows = "nixpkgs";
+    };
+
+    # Channels
+    # FIXME: is it needed or should I just alias nixos-unstable instead
+    nixpkgs = { type = "github"; owner = "NixOS"; repo = "nixpkgs"; ref = "nixos-unstable"; };
+    nixos-21_11 = { type = "github"; owner = "NixOS"; repo = "nixpkgs"; ref = "nixos-21.11"; };
+    nixos-unstable = { type = "github"; owner = "NixOS"; repo = "nixpkgs"; ref = "nixos-unstable"; };
+    nixpkgs-unstable = { type = "github"; owner = "NixOS"; repo = "nixpkgs"; ref = "nixpkgs-unstable"; };
+  };
+
+  outputs = { self, nixpkgs, nixos-21_11, ... }@inputs:
+    let
+      lib = import ./nix/lib inputs;
+      inherit (lib) genSystems;
+
+      overlays.default = import ./nix/packages;
+
+      pkgs = genSystems
+        (system:
+          import nixpkgs {
+            inherit system;
+            overlays = [
+              inputs.devshell.overlay
+              inputs.emacs-overlay.overlay
+              overlays.default
+            ];
+
+            config.allowUnfree = true;
+          });
+      stablePkgs = genSystems
+        (system:
+          import nixos-21_11 {
+            inherit system;
+            overlays = [
+              inputs.devshell.overlay
+              inputs.emacs-overlay.overlay
+              overlays.default
+            ];
+
+            config.allowUnfree = true;
+          });
+    in
+    {
+      inherit lib overlays pkgs;
+
+      # Standalone home-manager config
+      inherit (import ./home/profiles inputs) homeConfigurations;
+
+      deploy = import ./hosts/deploy.nix inputs;
+
+      # NixOS configuration with home-manager
+      nixosConfigurations = import ./systems/hosts inputs;
+
+      # devShells = genSystems (system: {
+      #   default = pkgs.${system}.devshell.mkShell {
+      #     packages = with pkgs.${system}; [
+      #       git
+      #       nixpkgs-fmt
+      #       inputs.deploy-rs.defaultPackage.${system}
+      #       # repl
+      #     ];
+      #     name = "dots";
+      #   };
+      # });
+
+      packages = lib.genAttrs [ "x86_64-linux" ] (system: {
+        inherit (pkgs.${system})
+          ;
+      });
+    };
+}
README.org
@@ -75,15 +75,19 @@
 * References
 
 Repositories
+- [[https://github.com/jordanisaacs/dotfiles][https://github.com/jordanisaacs/dotfiles]] — [[file:/net/sakhalin.home/export/gaia/src/configs/jordanisaacs.dotfiles/][src]]
+- [[https://git.sr.ht/~akirak/nix-config][https://git.sr.ht/~akirak/nix-config]] — [[file:/net/sakhalin.home/export/gaia/src/configs/akirak.nix-config/][src]]
+  + [[https://github.com/akirak/nix-desktop][https://github.com/akirak/nix-desktop]]
+- [[https://github.com/davidtwco/veritas]] — [[file:/net/sakhalin.home/export/gaia/src/configs/davidtwco.veritas/][src]]
+- [[https://github.com/buckley310/nixos-config][https://github.com/buckley310/nixos-config]] — [[file:/net/sakhalin.home/export/gaia/src/configs/buckley310.nixos-config/][src]]
+- [[https://github.com/eadwu/nixos-configuration][https://github.com/eadwu/nixos-configuration]] — [[file:/net/sakhalin.home/export/gaia/src/configs/eadwu.nixos-configuration/][src]]
+- [[https://github.com/berbiche/dotfiles][https://github.com/berbiche/dotfiles]] — [[file:/net/sakhalin.home/export/gaia/src/configs/berbiche.dotfiles/][src]]
+- https://github.com/hlissner/dotfiles/ — [[file:/net/sakhalin.home/export/gaia/src/configs/hlissner.dotfiles/][src]]
 - [[https://github.com/lovesegfault/nix-config][https://github.com/lovesegfault/nix-config]]
 - [[https://github.com/utdemir/dotfiles]]
-- [[https://github.com/davidtwco/veritas]]
 - [[https://github.com/bqv/nixrc][https://github.com/bqv/nixrc]]
-- [[https://github.com/berbiche/dotfiles][https://github.com/berbiche/dotfiles]]
-- https://github.com/hlissner/dotfiles/
 - [[https://github.com/leotaku/nixos-config]]
 - [[https://github.com/rasendubi/dotfiles]]
-- [[https://github.com/akirak/nix-desktop][https://github.com/akirak/nix-desktop]]
 - [[https://git.tazj.in/about/]]
 - [[https://github.com/danieldk/nix-home]]
 - https://github.com/terlar/nix-config