From 8d29c548ba99f3c2709e011df045383b3a52237a Mon Sep 17 00:00:00 2001 From: janabhumi Date: Sun, 9 Oct 2022 14:56:08 +0300 Subject: [PATCH] refac: use nix apps instead of gnumake --- flake.lock | 5 +- flake.nix | 59 +++++++++++++------ .../default.nix | 0 .../hardware-configuration.nix | 0 machines/default.nix | 2 +- makefile | 11 ---- users/jan/home.nix | 5 -- 7 files changed, 46 insertions(+), 36 deletions(-) rename machines/{asus_gl553vd => asus-gl553vd}/default.nix (100%) rename machines/{asus_gl553vd => asus-gl553vd}/hardware-configuration.nix (100%) delete mode 100644 makefile diff --git a/flake.lock b/flake.lock index 7cdb1c4..542d911 100644 --- a/flake.lock +++ b/flake.lock @@ -306,7 +306,9 @@ }, "nil": { "inputs": { - "flake-utils": "flake-utils", + "flake-utils": [ + "flake-utils" + ], "nixpkgs": [ "nixpkgs" ], @@ -446,6 +448,7 @@ "root": { "inputs": { "dedsec-grub-theme": "dedsec-grub-theme", + "flake-utils": "flake-utils", "hardware": "hardware", "home-manager": "home-manager", "myneovim": "myneovim", diff --git a/flake.nix b/flake.nix index a5dea99..b44d30d 100644 --- a/flake.nix +++ b/flake.nix @@ -2,6 +2,8 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + hardware.url = "github:NixOS/nixos-hardware/master"; home-manager = { @@ -23,6 +25,7 @@ nil = { url = "github:oxalica/nil"; inputs.nixpkgs.follows = "nixpkgs"; + inputs.flake-utils.follows = "flake-utils"; }; # my neovim configuration @@ -38,11 +41,44 @@ }; }; - outputs = inputs @ { self, nixpkgs, hardware, ... }: - let - system = "x86_64-linux"; - in - { + outputs = inputs @ { self, flake-utils, nixpkgs, hardware, ... }: + flake-utils.lib.eachDefaultSystem + (system: + let + pkgs = import nixpkgs { inherit system; }; + inherit (pkgs) lib; + + nixos-rebuild = pkgs.nixos-rebuild.override { nix = pkgs.nixFlakes; }; + in + { + apps = lib.mapAttrs + (name: program: { type = "app"; program = toString program; }) + ( + (flake-utils.lib.flattenTree { + switch = lib.recurseIntoAttrs (lib.mapAttrs + (hostname: machine: pkgs.writeShellScript "switch-${hostname}" '' + ${nixos-rebuild}/bin/nixos-rebuild switch --flake .#${hostname} + '') + self.nixosConfigurations); + }) + // { + fix-systemd = pkgs.writeShellScript "fix-systemd" '' + systemctl --user reset-failed + ''; + } + ); + + devShells = { + default = pkgs.mkShell { + packages = with pkgs; + [ + stylua # lua formatter + ormolu # haskell formatter + ]; + }; + }; + }) + // { nixosConfigurations = nixpkgs.lib.mapAttrs (hostname: { system @@ -61,18 +97,5 @@ ++ extraModules; }) (import ./machines inputs); - - devShells.${system} = - let - pkgs = import nixpkgs { inherit system; }; - in - { - default = pkgs.mkShell { - packages = with pkgs; [ - stylua # lua formatter - ormolu # haskell formatter - ]; - }; - }; }; } diff --git a/machines/asus_gl553vd/default.nix b/machines/asus-gl553vd/default.nix similarity index 100% rename from machines/asus_gl553vd/default.nix rename to machines/asus-gl553vd/default.nix diff --git a/machines/asus_gl553vd/hardware-configuration.nix b/machines/asus-gl553vd/hardware-configuration.nix similarity index 100% rename from machines/asus_gl553vd/hardware-configuration.nix rename to machines/asus-gl553vd/hardware-configuration.nix diff --git a/machines/default.nix b/machines/default.nix index a8f6499..5185232 100644 --- a/machines/default.nix +++ b/machines/default.nix @@ -14,7 +14,7 @@ in ]; }; - asus_gl553vd = { + asus-gl553vd = { system = "x86_64-linux"; specialArgs = { diff --git a/makefile b/makefile deleted file mode 100644 index f2561c9..0000000 --- a/makefile +++ /dev/null @@ -1,11 +0,0 @@ -switchSys = nixos-rebuild switch --flake - -sys-home: - sudo ${switchSys} .#home - -sys-asus-gl553vd: - sudo ${switchSys} .#asus_gl553vd - -fix-systemd: - systemctl --user reset-failed - diff --git a/users/jan/home.nix b/users/jan/home.nix index 97ff0a7..cfdca59 100644 --- a/users/jan/home.nix +++ b/users/jan/home.nix @@ -6,11 +6,6 @@ in { imports = (import ./ui) ++ (import ./shell) ++ (import ./progs); - # Home Manager needs a bit of information about you and the - # paths it should manage. - home.username = secrets.userName; - home.homeDirectory = secrets.userDir; - home.keyboard = { model = "pc105"; layout = "us,ru";