From c5246a1b46884655b64eacdc640cb4da2f6cc42e Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Tue, 1 Apr 2025 01:05:52 +0200 Subject: [PATCH] treewide: adopt flakes after using non-flake setup time has arrived to switch to flakes eeleco clearly won and flakes are the future --- default.nix | 32 +---- flake.lock | 190 +++++++++++++++++++++++++++ flake.nix | 32 +++++ inputs.nix | 84 ------------ lock.nix | 18 --- nix-os/core.nix | 2 + outputs.nix | 9 +- pkgs/overlays/version-info-fixup.nix | 2 +- pkgs/top-level/default.nix | 2 +- 9 files changed, 231 insertions(+), 140 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix delete mode 100644 inputs.nix delete mode 100644 lock.nix diff --git a/default.nix b/default.nix index d6c5e01..41c6ca2 100644 --- a/default.nix +++ b/default.nix @@ -1,31 +1 @@ -# if evaluating outside of the store, copy the current directory to the store and import it -# filtering out .gitignore files and .git directories -# if evaluating inside the store, import the outputs.nix file - -let - # Ideally this file should be selfcontained, but I like the utilities in nixpkgs lib - lib = (import "${(import ./inputs.nix {}).nixpkgs}/lib").extend (self: super: { - proot = import ./lib/gitignore-filter.nix { lib = self; }; - inherit (self.proot) parseGitignore runGitignoreFilter toGitignoreMatcher; - }); - - currentFilePath = (builtins.unsafeGetAttrPos "any" { any = "any"; }).file; - storePathLength = builtins.stringLength (builtins.toString builtins.storeDir); - evaluatingInStore = (builtins.substring 0 storePathLength currentFilePath) == builtins.storeDir; - - selfInStore = builtins.path { - path = ./.; - name = "source"; - filter = path: type: - let - selfPath = builtins.dirOf currentFilePath; - gitIgnoreFilters = lib.parseGitignore selfPath path; - result = type != "unknown" - && type != "symlink" - && builtins.baseNameOf path != ".git" - && lib.runGitignoreFilter gitIgnoreFilters path type; - in result; - }; -in -if !(evaluatingInStore) then { ... }@args: import selfInStore ({ selfPath = selfInStore; } // args ) -else { ... }@args: import ./outputs.nix ({ selfPath = selfInStore; } // args) +_: builtins.getFlake (builtins.toString ./.) diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..f6bc799 --- /dev/null +++ b/flake.lock @@ -0,0 +1,190 @@ +{ + "nodes": { + "cosmic-modules": { + "inputs": { + "flake-compat": "flake-compat", + "nixpkgs": "nixpkgs", + "nixpkgs-stable": "nixpkgs-stable", + "rust-overlay": "rust-overlay" + }, + "locked": { + "lastModified": 1743246566, + "narHash": "sha256-arEFUDLjADYIZ7T6PZX1yLOnfMoZ1ByebtmPuvV98+s=", + "owner": "lilyinstarlight", + "repo": "nixos-cosmic", + "rev": "c709db4b95e58f410978bb49c87cb74214d03e78", + "type": "github" + }, + "original": { + "owner": "lilyinstarlight", + "repo": "nixos-cosmic", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1717312683, + "narHash": "sha256-FrlieJH50AuvagamEvWMIE6D2OAnERuDboFDYAED/dE=", + "owner": "nix-community", + "repo": "flake-compat", + "rev": "38fd3954cf65ce6faf3d0d45cd26059e059f07ea", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1681202837, + "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "cfacdce06f30d2b68473a46042957675eebb3401", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixos-vscode-server": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1729422940, + "narHash": "sha256-DlvJv33ml5UTKgu4b0HauOfFIoDx6QXtbqUF3vWeRCY=", + "owner": "nix-community", + "repo": "nixos-vscode-server", + "rev": "8b6db451de46ecf9b4ab3d01ef76e59957ff549f", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixos-vscode-server", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1743095683, + "narHash": "sha256-gWd4urRoLRe8GLVC/3rYRae1h+xfQzt09xOfb0PaHSk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5e5402ecbcb27af32284d4a62553c019a3a49ea6", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1742937945, + "narHash": "sha256-lWc+79eZRyvHp/SqMhHTMzZVhpxkRvthsP1Qx6UCq0E=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "d02d88f8de5b882ccdde0465d8fa2db3aa1169f7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-24.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-unstable": { + "locked": { + "lastModified": 1743095683, + "narHash": "sha256-gWd4urRoLRe8GLVC/3rYRae1h+xfQzt09xOfb0PaHSk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5e5402ecbcb27af32284d4a62553c019a3a49ea6", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "ref": "nixos-unstable", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1742937945, + "narHash": "sha256-lWc+79eZRyvHp/SqMhHTMzZVhpxkRvthsP1Qx6UCq0E=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "d02d88f8de5b882ccdde0465d8fa2db3aa1169f7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "ref": "nixos-24.11", + "type": "github" + } + }, + "root": { + "inputs": { + "cosmic-modules": "cosmic-modules", + "nixos-vscode-server": "nixos-vscode-server", + "nixpkgs": "nixpkgs_2", + "nixpkgs-unstable": "nixpkgs-unstable" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "cosmic-modules", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1743215516, + "narHash": "sha256-52qbrkG65U1hyrQWltgHTgH4nm0SJL+9TWv2UDCEPNI=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "524463199fdee49338006b049bc376b965a2cfed", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..b183431 --- /dev/null +++ b/flake.nix @@ -0,0 +1,32 @@ +{ + inputs = { + nixos-vscode-server = { + type = "github"; + owner = "nix-community"; + repo = "nixos-vscode-server"; + inputs = { + nixpkgs.follows = "nixpkgs"; + }; + }; + nixpkgs = { + type = "github"; + owner = "NixOS"; + repo = "nixpkgs"; + ref = "nixos-24.11"; + }; + nixpkgs-unstable = { + type = "github"; + owner = "NixOS"; + repo = "nixpkgs"; + ref = "nixos-unstable"; + }; + cosmic-modules = { + type = "github"; + owner = "lilyinstarlight"; + repo = "nixos-cosmic"; + }; + }; + outputs = inputs: import ./outputs.nix { + inherit inputs; + }; +} diff --git a/inputs.nix b/inputs.nix deleted file mode 100644 index 1c6c039..0000000 --- a/inputs.nix +++ /dev/null @@ -1,84 +0,0 @@ -let self = { - lock ? import lockFile, - lockFile ? ./lock.nix, - pkgs ? throw "inputs called without pkgs", -}: - -{ - inherit lock; - nixos-vscode-server = rec { - url = "https://github.com/nix-community/nixos-vscode-server/archive/${lock.nixos-vscode-server.revision}.tar.gz"; - updateScript = pkgs.den-http-get-updater { - fileLocation = lockFile; - previousHash = lock.nixos-vscode-server.sha256; - previousVersion = lock.nixos-vscode-server.revision; - versionUrl = "https://api.github.com/repos/nix-community/nixos-vscode-server/commits"; - contentParser = "jq -rc '.[0].sha' <<< \"$newVersion\""; - prefetchUrlLocation = { - file = ./inputs.nix; - attrpath = "nixos-vscode-server.url"; - }; - }; - outPath = builtins.fetchTarball { - inherit url; - name = "nixos-vscode-server"; - sha256 = "${lock.nixos-vscode-server.sha256}"; - }; - }; - nixpkgs = rec { - url = "https://github.com/NixOS/nixpkgs/archive/${lock.nixpkgs.revision}.tar.gz"; - updateScript = pkgs.den-http-get-updater { - fileLocation = lockFile; - previousHash = lock.nixpkgs.sha256; - previousVersion = lock.nixpkgs.revision; - versionUrl = "https://channels.nixos.org/nixos-24.11/git-revision"; - prefetchUrlLocation = { - file = ./inputs.nix; - attrpath = "nixpkgs.url"; - }; - }; - outPath = builtins.fetchTarball { - inherit url; - name = "nixpkgs"; - sha256 = "${lock.nixpkgs.sha256}"; - }; - }; - nixpkgs-unstable = rec { - url = "https://github.com/NixOS/nixpkgs/archive/${lock.nixpkgs-unstable.revision}.tar.gz"; - updateScript = pkgs.den-http-get-updater { - fileLocation = lockFile; - previousHash = lock.nixpkgs-unstable.sha256; - previousVersion = lock.nixpkgs-unstable.revision; - versionUrl = "https://channels.nixos.org/nixos-unstable/git-revision"; - prefetchUrlLocation = { - file = ./inputs.nix; - attrpath = "nixpkgs-unstable.url"; - }; - }; - outPath = builtins.fetchTarball { - inherit url; - name = "nixpkgs-unstable"; - sha256 = "${lock.nixpkgs-unstable.sha256}"; - }; - }; - cosmic-modules = rec { - url = "https://github.com/lilyinstarlight/nixos-cosmic/archive/${lock.cosmic-modules.revision}.tar.gz"; - updateScript = pkgs.den-http-get-updater { - fileLocation = lockFile; - previousHash = lock.cosmic-modules.sha256; - previousVersion = lock.cosmic-modules.revision; - versionUrl = "https://api.github.com/repos/lilyinstarlight/nixos-cosmic/commits"; - contentParser = "jq -rc '.[0].sha' <<< \"$newVersion\""; - prefetchUrlLocation = { - file = ./inputs.nix; - attrpath = "cosmic-modules.url"; - }; - }; - outPath = builtins.fetchTarball { - inherit url; - name = "cosmic-modules"; - sha256 = "${lock.cosmic-modules.sha256}"; - }; - }; -}; -in self diff --git a/lock.nix b/lock.nix deleted file mode 100644 index a18318a..0000000 --- a/lock.nix +++ /dev/null @@ -1,18 +0,0 @@ -{ - nixos-vscode-server = { - revision = "8b6db451de46ecf9b4ab3d01ef76e59957ff549f"; - sha256 = "09j4kvsxw1d5dvnhbsgih0icbrxqv90nzf0b589rb5z6gnzwjnqf"; - }; - nixpkgs = { - revision = "d02d88f8de5b882ccdde0465d8fa2db3aa1169f7"; - sha256 = "0hdb0ajwfl7xn1hznik4kj35adiksc8k5apllz3jniwrszpkwrwm"; - }; - nixpkgs-unstable = { - revision = "5e5402ecbcb27af32284d4a62553c019a3a49ea6"; - sha256 = "0a8xv91nz7qkyxs3nhszxj3vb9s5v1xgyhmm32y1fbb8njx7hrw1"; - }; - cosmic-modules = { - revision = "c709db4b95e58f410978bb49c87cb74214d03e78"; - sha256 = "1szkgpsvm3yrdsg1rm0rr9yagcy8ynakvymlcw43c0736980bcba"; - }; -} diff --git a/nix-os/core.nix b/nix-os/core.nix index 34c6f41..d09e57b 100644 --- a/nix-os/core.nix +++ b/nix-os/core.nix @@ -23,6 +23,8 @@ channel.enable = false; settings.experimental-features = [ "no-url-literals" + "nix-command" + "flakes" ]; nixPath = [ "nixpkgs=${pkgs.selfExpr { useConfig = false; }}" diff --git a/outputs.nix b/outputs.nix index 76b8b85..e8fb8fa 100644 --- a/outputs.nix +++ b/outputs.nix @@ -1,12 +1,11 @@ { - inputsPath ? ./inputs.nix, - inputs ? import inputsPath {}, + inputs, selfPath ? ./. }: let -lib = (import "${inputs.nixpkgs}/lib").extend (import ./lib/overlays/version-info-fixup.nix { revision = inputs.lock.nixpkgs.revision; }); +lib = (import "${inputs.nixpkgs}/lib").extend (import ./lib/overlays/version-info-fixup.nix { revision = inputs.nixpkgs.rev; }); systems = [ "x86_64-linux" @@ -17,7 +16,7 @@ systems = [ forEachSystem = lib.genAttrs systems; self = { - inherit inputs inputsPath lib self; + inherit inputs lib self; outPath = selfPath; modifiedNixpkgs = import ./pkgs/top-level/impure.nix; modifiedNixpkgsPure = import ./pkgs/top-level/default.nix; @@ -31,7 +30,7 @@ self = { overlays = { cosmicPackages = import ./pkgs/overlays/cosmic-packages.nix { inherit inputs; }; selfExpr = import ./pkgs/overlays/selfExpr.nix { nixpkgsPath = inputs.nixpkgs; }; - unstableWithMeta = import ./pkgs/overlays/unstable-with-meta.nix { unstableSource = inputs.nixpkgs-unstable; revision = inputs.lock.nixpkgs-unstable.revision; }; + unstableWithMeta = import ./pkgs/overlays/unstable-with-meta.nix { unstableSource = inputs.nixpkgs-unstable; revision = inputs.nixpkgs-unstable.rev; }; versionInfoFixup = import ./pkgs/overlays/version-info-fixup.nix { inherit inputs; }; }; nixosConfigurations = let diff --git a/pkgs/overlays/version-info-fixup.nix b/pkgs/overlays/version-info-fixup.nix index b1f2ecc..b9ffa3a 100644 --- a/pkgs/overlays/version-info-fixup.nix +++ b/pkgs/overlays/version-info-fixup.nix @@ -1,7 +1,7 @@ { inputs ? import ../../inputs.nix {} }: self: super: { - lib = super.lib.extend (import ../../lib/overlays/version-info-fixup.nix { revision = inputs.lock.nixpkgs.revision; }); + lib = super.lib.extend (import ../../lib/overlays/version-info-fixup.nix { revision = inputs.nixpkgs.rev; }); } // super.lib.optionalAttrs (super ? unstable && super ? unstableRevision) { unstable = super.unstable // { diff --git a/pkgs/top-level/default.nix b/pkgs/top-level/default.nix index 34637da..2ee6687 100644 --- a/pkgs/top-level/default.nix +++ b/pkgs/top-level/default.nix @@ -14,7 +14,7 @@ let overlays = (args.overlays or []) ++ [ # ../.. should be nix store path that represents self in outputs.nix that is gc-rooted by this point ( import ../overlays/selfExpr.nix { nixpkgsPath = "${builtins.toString ../..}/pkgs/top-level/impure.nix"; } ) - ( import ../overlays/unstable-with-meta.nix { unstableSource = inputs.nixpkgs-unstable; revision = inputs.lock.nixpkgs-unstable.revision; } ) + ( import ../overlays/unstable-with-meta.nix { unstableSource = inputs.nixpkgs-unstable; revision = inputs.nixpkgs-unstable.rev; } ) ( import ../overlays/unstable-latest.nix ) ( import ../overlays/version-info-fixup.nix { inherit inputs; } ) ( import ./by-name-overlay.nix ../by-name )